%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/internet/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/internet/__pycache__/testing.cpython-312.pyc

�

Ϫ�f~t��f�dZddlmZddlmZddlmZmZddlm	Z	m
Z
mZmZddl
mZmZddlmZddlmZmZdd	lmZmZmZmZdd
lmZmZddlmZmZmZddl m!Z!dd
l"m#Z#ddl$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0ddl1m2Z2ddl3m4Z4m5Z5m6Z6ddl7m8Z8ddl9m:Z:ddl;m<Z<gd�Z=ed�Z>Gd�dej~�Z@Gd�de8j��ZBGd�d�ZCee0e&e)�Gd�d��ZDGd�deD�ZEGd �d!e�ZFee'�Gd"�d#��ZGee%�Gd$�d%��ZHee*e.e-e/e,e+�Gd&�d'��ZIeeI�D]ZJeeJeI��
Gd(�d)eIe2�ZKee.e-e/e,�Gd*�d+��ZLGd,�d-�ZMd.�ZNee4�Gd/�d0ee5��ZOy1)2zJ
Assorted functionality which is commonly useful when writing unit tests.
�)�annotations)�BytesIO)�AF_INET�AF_INET6)�Callable�Iterator�Sequence�overload)�
implementedBy�implementer)�verifyClass)�	ParamSpec�Self)�address�error�protocol�task)�_dataMustBeBytes�
isIPv6Address)�IPv4Address�IPv6Address�UNIXAddress)�Deferred)�UnsupportedAddressFamily)�
IConnector�	IConsumer�IListeningPort�	IProtocol�
IPushProducer�IReactorCore�
IReactorFDSet�IReactorSocket�IReactorSSL�IReactorTCP�IReactorUNIX�
ITransport)�Clock)�ILogObserver�LogEvent�LogPublisher)�basic)�failure)�TestCase)�AccumulatingProtocol�LineSendingProtocol�FakeDatagramTransport�StringTransport� StringTransportWithDisconnection�StringIOWithoutClosing�_FakeConnector�	_FakePort�
MemoryReactor�MemoryReactorClock�RaisingMemoryReactor�NonStreamingProducer�waitUntilAllDisconnected�EventLoggingObserver�_Pc�:�eZdZdZdxZZdZdZdZdZ	d�Z
d�Zd�Zy)r.ad
    L{AccumulatingProtocol} is an L{IProtocol} implementation which collects
    the data delivered to it and can fire a Deferred when it is connected or
    disconnected.

    @ivar made: A flag indicating whether C{connectionMade} has been called.
    @ivar data: Bytes giving all the data passed to C{dataReceived}.
    @ivar closed: A flag indicated whether C{connectionLost} has been called.
    @ivar closedReason: The value of the I{reason} parameter passed to
        C{connectionLost}.
    @ivar closedDeferred: If set to a L{Deferred}, this will be fired when
        C{connectionLost} is called.
    rN�c���d|_|j�P|jj�9|jj}d|j_|j|�yyy�N�)�made�factory�protocolConnectionMade�callback��self�ds  �:/usr/lib/python3/dist-packages/twisted/internet/testing.py�connectionMadez#AccumulatingProtocol.connectionMadeXsR����	��<�<�#����(K�(K�(W����3�3�A�26�D�L�L�/�
�J�J�t��)X�#r>c�.�|xj|z
c_y�N)�data�rGrMs  rI�dataReceivedz!AccumulatingProtocol.dataReceived_s���	�	�T��	r>c��d|_||_|j�&|jdc}|_|jd�yyr@)�closed�closedReason�closedDeferredrE)rG�reasonrHs   rI�connectionLostz#AccumulatingProtocol.connectionLostbsC�����"������*�%)�%8�%8�$�"�A�t�"�
�J�J�t��+r>)
�__name__�
__module__�__qualname__�__doc__rBrQrRrSrMrCrJrOrU�r>rIr.r.@s6�����D�6��L��N��D��G���r>r.c�*�eZdZdZdd�Zd�Zd�Zd�Zy)r/Fc�4�|dd|_g|_||_yrL)�lines�response�start)rGr]r_s   rI�__init__zLineSendingProtocol.__init__ms���1�X��
���
���
r>c�b�|jr#|jD]}|j|��yyrL)r_r]�sendLine�rG�lines  rIrJz"LineSendingProtocol.connectionMaders-���:�:��
�
�
$���
�
�d�#�
$�r>c��|js)|jD]}|j|��g|_|jj	|�yrL)r_r]rbr^�appendrcs  rI�lineReceivedz LineSendingProtocol.lineReceivedwsA���z�z��
�
�
$���
�
�d�#�
$��D�J��
�
���T�"r>c��d|_y�NT)�lostConn)rGrTs  rIrUz"LineSendingProtocol.connectionLost~s	����
r>N)T)rVrWrXrjr`rJrgrUrZr>rIr/r/js���H��
$�
#�r>r/c�*�eZdZe�Zd�Zefd�Zy)r0c��g|_yrL)�written�rGs rIr`zFakeDatagramTransport.__init__�s	����r>c�>�|jj||f�yrL)rmrf)rG�packet�addrs   rI�writezFakeDatagramTransport.write�s�������V�T�N�+r>N)rVrWrX�object�noAddrr`rrrZr>rIr0r0�s��
�X�F��"(�,r>r0c��eZdZdZdZdZdZdZdZdZ	dZ
dd�Zd�Zd�Z
d�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zy)r1a�
    A transport implementation which buffers data in memory and keeps track of
    its other state without providing any behavior.

    L{StringTransport} has a number of attributes which are not part of any of
    the interfaces it claims to implement.  These attributes are provided for
    testing purposes.  Implementation code should not use any of these
    attributes; they are not provided by other transports.

    @ivar disconnecting: A C{bool} which is C{False} until L{loseConnection} is
        called, then C{True}.

    @ivar disconnected: A C{bool} which is C{False} until L{abortConnection} is
        called, then C{True}.

    @ivar producer: If a producer is currently registered, C{producer} is a
        reference to it.  Otherwise, L{None}.

    @ivar streaming: If a producer is currently registered, C{streaming} refers
        to the value of the second parameter passed to C{registerProducer}.

    @ivar hostAddr: L{None} or an object which will be returned as the host
        address of this transport.  If L{None}, a nasty tuple will be returned
        instead.

    @ivar peerAddr: L{None} or an object which will be returned as the peer
        address of this transport.  If L{None}, a nasty tuple will be returned
        instead.

    @ivar producerState: The state of this L{StringTransport} in its capacity
        as an L{IPushProducer}.  One of C{'producing'}, C{'paused'}, or
        C{'stopped'}.

    @ivar io: A L{io.BytesIO} which holds the data which has been written to
        this transport since the last call to L{clear}.  Use L{value} instead
        of accessing this directly.

    @ivar _lenient: By default L{StringTransport} enforces that
        L{resumeProducing} is not called after the connection is lost. This is
        to ensure that any code that does call L{resumeProducing} after the
        connection is lost is not blindly expecting L{resumeProducing} to have
        any impact.

        However, if your test case is calling L{resumeProducing} after
        connection close on purpose, and you know it won't block expecting
        further data to show up, this flag may safely be set to L{True}.

        Defaults to L{False}.
    @type lenient: L{bool}
    FN�	producingc�d�|j�|�||_|�||_d|_||_yri)�clear�hostAddr�peerAddr�	connected�_lenient)rG�hostAddress�peerAddress�lenients    rIr`zStringTransport.__init__�s3���
�
���"�'�D�M��"�'�D�M������
r>c�"�t�|_y)z�
        Discard all data written to this transport so far.

        This is not a transport method.  It is intended for tests.  Do not use
        it in implementation code.
        N)r�iorns rIrxzStringTransport.clear�s
���)��r>c�6�|jj�S)aN
        Retrieve all data which has been buffered by this transport.

        This is not a transport method.  It is intended for tests.  Do not use
        it in implementation code.

        @return: A C{bytes} giving all data written to this transport since the
            last call to L{clear}.
        @rtype: C{bytes}
        )r��getvaluerns rI�valuezStringTransport.value�s���w�w���!�!r>c�P�t|�|jj|�yrL)rr�rrrNs  rIrrzStringTransport.write�s��������
�
�d�r>c�X�|jjdj|��y)Nr>)r�rr�joinrNs  rI�
writeSequencezStringTransport.writeSequence�s�����
�
�c�h�h�t�n�%r>c��d|_y)z~
        Close the connection. Does nothing besides toggle the C{disconnecting}
        instance variable to C{True}.
        TN)�
disconnectingrns rI�loseConnectionzStringTransport.loseConnection�s��
"��r>c�2�d|_|j�y)z�
        Abort the connection. Same as C{loseConnection}, but also toggles the
        C{aborted} instance variable to C{True}.
        TN)�disconnectedr�rns rI�abortConnectionzStringTransport.abortConnection�s��
!������r>c�`�|j�tjddd�S|jS)N�TCPz192.168.1.1i1�)rzrrrns rI�getPeerzStringTransport.getPeers+���=�=� ��&�&�u�m�U�C�C��}�}�r>c�`�|j�tjddd�S|jS)Nr�z10.0.0.1i90)ryrrrns rI�getHostzStringTransport.getHosts+���=�=� ��&�&�u�j�%�@�@��}�}�r>c�N�|j�td��||_||_y)NzCannot register two producers��producer�RuntimeError�	streaming)rGr�r�s   rI�registerProducerz StringTransport.registerProducer
s&���=�=�$��>�?�?� ��
�"��r>c�N�|j�td��d|_d|_y)Nz5Cannot unregister a producer unless one is registeredr�rns rI�unregisterProducerz"StringTransport.unregisterProducers&���=�=� ��V�W�W���
���r>c�~�|jr|jstd��|jdk(rtd��y)Nz,Cannot resume producing after loseConnection�stoppedz Cannot resume a stopped producer)r�r|r��
producerStaterns rI�_checkStatezStringTransport._checkStates<�����d�m�m��M�N�N�����*��A�B�B�+r>c�2�|j�d|_y)N�paused�r�r�rns rI�pauseProducingzStringTransport.pauseProducing s������%��r>c��d|_y)Nr�)r�rns rI�
stopProducingzStringTransport.stopProducing$s
��&��r>c�2�|j�d|_y)Nrvr�rns rI�resumeProducingzStringTransport.resumeProducing's������(��r>)NNF)rVrWrXrYr�r�r�r�ryrzr�r`rxr�rrr�r�r�r�r�r�r�r�r�r�r�rZr>rIr1r1�sy��1�f�M��L��H��I��H��H��M� ��"��&�"���
�#��C�&�'�)r>r1c�"�eZdZUdZded<d�Zy)r2zt
    A L{StringTransport} which on disconnection will trigger the connection
    lost on the attached protocol.
    rrc��|jrId|_|jjtjtjd���yy)NFzBye.)r{rrUr,�Failurer�ConnectionDonerns rIr�z/StringTransportWithDisconnection.loseConnection4s;���>�>�"�D�N��M�M�(�(�����9M�9M�f�9U�)V�W�r>N)rVrWrXrY�__annotations__r�rZr>rIr2r2,s���
��Xr>r2c��eZdZdZd�Zy)r3z)
    A BytesIO that can't be closed.
    c��y)z
        Do nothing.
        NrZrns rI�closezStringIOWithoutClosing.close?��r>N)rVrWrXrYr�rZr>rIr3r3:s���r>r3c�(�eZdZdZd�Zd�Zd�Zd�Zy)r5z�
    A fake L{IListeningPort} to be used in tests.

    @ivar _hostAddress: The L{IAddress} this L{IListeningPort} is pretending
        to be listening on.
    c��||_y)zz
        @param hostAddress: An L{IAddress} this L{IListeningPort} should
            pretend to be listening on.
        N��_hostAddress)rGr}s  rIr`z_FakePort.__init__Ns��
(��r>c��y)zQ
        Fake L{IListeningPort.startListening} that doesn't do anything.
        NrZrns rI�startListeningz_FakePort.startListeningUr�r>c��y)zP
        Fake L{IListeningPort.stopListening} that doesn't do anything.
        NrZrns rI�
stopListeningz_FakePort.stopListeningZr�r>c��|jS)zN
        Fake L{IListeningPort.getHost} that returns our L{IAddress}.
        r�rns rIr�z_FakePort.getHost_s��� � � r>N)rVrWrXrYr`r�r�r�rZr>rIr5r5Es���(��
�
!r>r5c�6�eZdZdZdZdZd�Zd�Zd�Zd�Z	d�Z
y)	r4a'
    A fake L{IConnector} that allows us to inspect if it has been told to stop
    connecting.

    @ivar stoppedConnecting: has this connector's
        L{_FakeConnector.stopConnecting} method been invoked yet?

    @ivar _address: An L{IAddress} provider that represents our destination.
    Fc��||_y)zs
        @param address: An L{IAddress} provider that represents this
            connector's destination.
        N��_address)rGrs  rIr`z_FakeConnector.__init__us��
 ��
r>c��d|_y)zw
        Implement L{IConnector.stopConnecting} and set
        L{_FakeConnector.stoppedConnecting} to C{True}
        TN)�stoppedConnectingrns rI�stopConnectingz_FakeConnector.stopConnecting|s��
"&��r>c��d|_y)z@
        Implement L{IConnector.disconnect} as a no-op.
        TN)�
_disconnectedrns rI�
disconnectz_FakeConnector.disconnect�s��"��r>c��y)z=
        Implement L{IConnector.connect} as a no-op.
        NrZrns rI�connectz_FakeConnector.connect�r�r>c��|jS)zp
        Implement L{IConnector.getDestination} to return the C{address} passed
        to C{__init__}.
        r�rns rI�getDestinationz_FakeConnector.getDestination�s��
�}�}�r>N)rVrWrXrYr�r�r`r�r�r�r�rZr>rIr4r4fs-����M��� �&�"��
r>r4c���eZdZdZd�Zd�Zdd�Zd�Zd�Zd�Z	dd�Z
d	�Z												d d
�Zd�Z
								d!d�Zd
�Zd�Zd"d�Zd#d�Zd$d�Zd#d�Z	d$d�Zd%d�Zd&d�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)'r6a:
    A fake reactor to be used in tests.  This reactor doesn't actually do
    much that's useful yet.  It accepts TCP connection setup attempts, but
    they will never succeed.

    @ivar hasInstalled: Keeps track of whether this reactor has been installed.
    @type hasInstalled: L{bool}

    @ivar running: Keeps track of whether this reactor is running.
    @type running: L{bool}

    @ivar hasStopped: Keeps track of whether this reactor has been stopped.
    @type hasStopped: L{bool}

    @ivar hasCrashed: Keeps track of whether this reactor has crashed.
    @type hasCrashed: L{bool}

    @ivar whenRunningHooks: Keeps track of hooks registered with
        C{callWhenRunning}.
    @type whenRunningHooks: L{list}

    @ivar triggers: Keeps track of hooks registered with
        C{addSystemEventTrigger}.
    @type triggers: L{dict}

    @ivar tcpClients: Keeps track of connection attempts (ie, calls to
        C{connectTCP}).
    @type tcpClients: L{list}

    @ivar tcpServers: Keeps track of server listen attempts (ie, calls to
        C{listenTCP}).
    @type tcpServers: L{list}

    @ivar sslClients: Keeps track of connection attempts (ie, calls to
        C{connectSSL}).
    @type sslClients: L{list}

    @ivar sslServers: Keeps track of server listen attempts (ie, calls to
        C{listenSSL}).
    @type sslServers: L{list}

    @ivar unixClients: Keeps track of connection attempts (ie, calls to
        C{connectUNIX}).
    @type unixClients: L{list}

    @ivar unixServers: Keeps track of server listen attempts (ie, calls to
        C{listenUNIX}).
    @type unixServers: L{list}

    @ivar adoptedPorts: Keeps track of server listen attempts (ie, calls to
        C{adoptStreamPort}).

    @ivar adoptedStreamConnections: Keeps track of stream-oriented
        connections added using C{adoptStreamConnection}.
    c� �d|_d|_d|_d|_d|_g|_i|_g|_g|_g|_	g|_
g|_g|_g|_
g|_g|_t!�|_t!�|_y)z0
        Initialize the tracking lists.
        FTN)�hasInstalled�running�hasRun�
hasStopped�
hasCrashed�whenRunningHooks�triggers�
tcpClients�
tcpServers�
sslClients�
sslServers�unixClients�unixServers�adoptedPorts�adoptedStreamConnections�
connectors�set�readers�writersrns rIr`zMemoryReactor.__init__�s���"��������������� "�����
����������������������(*��%�����u����u��r>c��d|_y)zO
        Fake install callable to emulate reactor module installation.
        TN)r�rns rI�installzMemoryReactor.install�s��!��r>c��t���zA
        Not implemented; raises L{NotImplementedError}.
        ��NotImplementedError)rG�name�timeouts   rI�resolvezMemoryReactor.resolve��
��"�#�#r>c��|jdusJ�d|_d|_|jD]\}}}||i|���|j�y)a
        Fake L{IReactorCore.run}.
        Sets C{self.running} to L{True}, runs all of the hooks passed to
        C{self.callWhenRunning}, then calls C{self.stop} to simulate a request
        to stop the reactor.
        Sets C{self.hasRun} to L{True}.
        FTN)r�r�r��stop)rG�f�args�kwargss    rI�runzMemoryReactor.run�sW���|�|�u�$�$�$�������#�4�4�	�O�A�t�V�
�t��v��	�	
�	�	�r>c� �d|_d|_y)z�
        Fake L{IReactorCore.run}.
        Sets C{self.running} to L{False}.
        Sets C{self.hasStopped} to L{True}.
        FTN)r�r�rns rIr�zMemoryReactor.stops�������r>c� �d|_d|_y)z�
        Fake L{IReactorCore.crash}.
        Sets C{self.running} to L{None}, because that feels crashy.
        Sets C{self.hasCrashed} to L{True}.
        NT)r�r�rns rI�crashzMemoryReactor.crashs�������r>c��t��r�r�)rG�delays  rI�iteratezMemoryReactor.iterater�r>c��t��r�r�)rG�	eventTypes  rI�fireSystemEventzMemoryReactor.fireSystemEvent#r�r>c��|jj|i�}|j|g�}|j|||f�y)z�
        Fake L{IReactorCore.run}.
        Keep track of trigger by appending it to
        self.triggers[phase][eventType].
        N)r��
setdefaultrf)rG�phaser��callabler��kw�
phaseTriggers�eventTypeTriggerss        rI�addSystemEventTriggerz#MemoryReactor.addSystemEventTrigger)sB���
�
�0�0���;�
�)�4�4�Y��C��� � �(�D�"�!5�6r>c��t��r�r�)rG�	triggerIDs  rI�removeSystemEventTriggerz&MemoryReactor.removeSystemEventTrigger:r�r>c�@�|jj|||f�y)z�
        Fake L{IReactorCore.callWhenRunning}.
        Keeps a list of invocations to make in C{self.whenRunningHooks}.
        N)r�rf)rGr�r�r�s    rI�callWhenRunningzMemoryReactor.callWhenRunning@s��	
���$�$�h��b�%9�:r>c���|tk(rtddd�}n!|tk(rtddd�}n
t	��|j
j
|||f�t|�S)zv
        Fake L{IReactorSocket.adoptStreamPort}, that logs the call and returns
        an L{IListeningPort}.
        r��0.0.0.0���::�rrrrrr�rfr5)rG�fileno�
addressFamilyrCrqs     rI�adoptStreamPortzMemoryReactor.adoptStreamPortIs^��
�G�#��u�i��6�D�
�h�
&��u�d�D�1�D�*�,�,���� � �&�-��!A�B����r>c�@�|jj|||f�y)z�
        Record the given stream connection in C{adoptedStreamConnections}.

        @see:
            L{twisted.internet.interfaces.IReactorSocket.adoptStreamConnection}
        N)r�rf�rG�fileDescriptorr	rCs    rI�adoptStreamConnectionz#MemoryReactor.adoptStreamConnectionXs��	
�%�%�,�,�n�m�W�-U�Vr>c���|tk(rtddd�}n!|tk(rtddd�}n
t	��|j
j
||||f�t|�S)z�
        Fake L{IReactorSocket.adoptDatagramPort}, that logs the call and
        returns a fake L{IListeningPort}.

        @see: L{twisted.internet.interfaces.IReactorSocket.adoptDatagramPort}
        �UDPrrrr)rGrr	r�
maxPacketSizerqs      rI�adoptDatagramPortzMemoryReactor.adoptDatagramPortas`���G�#��u�i��6�D�
�h�
&��u�d�D�1�D�*�,�,���� � �&�-��=�!Q�R����r>c��|jj||||f�t|�rtd||�}t|�St	dd|�}t|�S)zm
        Fake L{IReactorTCP.listenTCP}, that logs the call and
        returns an L{IListeningPort}.
        r�r)r�rfrrrr5)rG�portrC�backlog�	interfacers      rI�	listenTCPzMemoryReactor.listenTCPrs]��
	
������g�w�	�B�C���#�!�%��D�9�G���!�!�"�%��D�9�G���!�!r>Nc��|jj|||||f�t|�rtt	d||��}nttd||��}|j
|�|jj|�|S)zj
        Fake L{IReactorTCP.connectTCP}, that logs the call and
        returns an L{IConnector}.
        r�)r�rfrr4rr�startedConnectingr�)rG�hostrrCr��bindAddress�conns       rI�
connectTCPzMemoryReactor.connectTCP~st��
	
������d�G�W�k�J�K����!�+�e�T�4�"@�A�D�!�+�e�T�4�"@�A�D��!�!�$�'������t�$��r>c�n�|jj|||||f�ttdd|��S)zm
        Fake L{IReactorSSL.listenSSL}, that logs the call and
        returns an L{IListeningPort}.
        r�r)r�rfr5r�rGrrC�contextFactoryrrs      rI�	listenSSLzMemoryReactor.listenSSL�s5��
	
������g�~�w�	�R�S���U�I�t�<�=�=r>c���|jj||||||f�ttd||��}|j	|�|j
j|�|S)zj
        Fake L{IReactorSSL.connectSSL}, that logs the call and returns an
        L{IConnector}.
        r�)r�rfr4rrr�)rGrrrCr r�rrs        rI�
connectSSLzMemoryReactor.connectSSL�s`��	
�����
�4��.�'�;�G�	
��k�%��t�<�=���!�!�$�'������t�$��r>c�j�|jj|||||f�tt|��S)zo
        Fake L{IReactorUNIX.listenUNIX}, that logs the call and returns an
        L{IListeningPort}.
        )r�rfr5r�rGrrCr�mode�wantPIDs      rI�
listenUNIXzMemoryReactor.listenUNIX�s3��
	
������'�7�D�'� J�K���W�-�.�.r>c���|jj||||f�tt|��}|j	|�|j
j|�|S)zl
        Fake L{IReactorUNIX.connectUNIX}, that logs the call and returns an
        L{IConnector}.
        )r�rfr4rrr�)rGrrCr��checkPIDrs      rI�connectUNIXzMemoryReactor.connectUNIX�sU��
	
������'�7�H� E�F��k�'�2�3���!�!�$�'������t�$��r>c�:�|jj|�y)zW
        Fake L{IReactorFDSet.addReader} which adds the reader to a local set.
        N)r��add�rG�readers  rI�	addReaderzMemoryReactor.addReader����	
������ r>c�:�|jj|�y)zg
        Fake L{IReactorFDSet.removeReader} which removes the reader from a
        local set.
        N)r��discardr.s  rI�removeReaderzMemoryReactor.removeReader����
	
�����V�$r>c�:�|jj|�y)zW
        Fake L{IReactorFDSet.addWriter} which adds the writer to a local set.
        N)r�r-�rG�writers  rI�	addWriterzMemoryReactor.addWriter�r1r>c�:�|jj|�y)zg
        Fake L{IReactorFDSet.removeWriter} which removes the writer from a
        local set.
        N)r�r3r7s  rI�removeWriterzMemoryReactor.removeWriter�r5r>c�,�t|j�S)zn
        Fake L{IReactorFDSet.getReaders} which returns a list of readers from
        the local set.
        )�listr�rns rI�
getReaderszMemoryReactor.getReaders����
�D�L�L�!�!r>c�,�t|j�S)zn
        Fake L{IReactorFDSet.getWriters} which returns a list of writers from
        the local set.
        )r=r�rns rI�
getWriterszMemoryReactor.getWriters�r?r>c�l�|jj�|jj�y)zt
        Fake L{IReactorFDSet.removeAll} which removed all readers and writers
        from the local sets.
        N)r�rxr�rns rI�	removeAllzMemoryReactor.removeAll�s$��
	
�����������r>)�
)r)r��strr�rEr��Callable[_P, object]r��_P.argsr��	_P.kwargs�return�None)r�rFr�rGr�rHrIrJ)i ��2���N�rLi�r�rOr)rVrWrXrYr`r�r�r�r�r�r�r�r�rrr
rrrrr!r#r(r+r0r4r9r;r>rArCrZr>rIr6r6�s���6�p�6!�$��$��$�$�7��7��7�'�	7�
�7��
7�
�7�"$�;�,�;�5<�;�DM�;�	
�;�
�W��"
"��>�LP�
�/�	�!�%�!�%�"�"�r>r6c��eZdZd�Zy)r7c�X�tj|�tj|�yrL)r6r`r'rns rIr`zMemoryReactorClock.__init__�s�����t�$�
���t�r>N)rVrWrXr`rZr>rIr7r7�s��r>r7c�\�eZdZdZd
d�Zd�Zdd�Zdd�Zdd�Z	dd�Z	dd	�Z
dd
�Zd�Zd�Z
y)r8z�
    A fake reactor to be used in tests.  It accepts TCP connection setup
    attempts, but they will fail.

    @ivar _listenException: An instance of an L{Exception}
    @ivar _connectException: An instance of an L{Exception}
    Nc� �||_||_y)z�
        @param listenException: An instance of an L{Exception} to raise
            when any C{listen} method is called.

        @param connectException: An instance of an L{Exception} to raise
            when any C{connect} method is called.
        N)�_listenException�_connectException)rG�listenException�connectExceptions   rIr`zRaisingMemoryReactor.__init__�s��!0���!1��r>c��|j�)zb
        Fake L{IReactorSocket.adoptStreamPort}, that raises
        L{_listenException}.
        �rV)rGrr	rCs    rIr
z$RaisingMemoryReactor.adoptStreamPorts��
�#�#�#r>c��|j�)zQ
        Fake L{IReactorTCP.listenTCP}, that raises L{_listenException}.
        r[)rGrrCrrs     rIrzRaisingMemoryReactor.listenTCP
����#�#�#r>c��|j�)zS
        Fake L{IReactorTCP.connectTCP}, that raises L{_connectException}.
        �rW)rGrrrCr�rs      rIrzRaisingMemoryReactor.connectTCP����$�$�$r>c��|j�)zQ
        Fake L{IReactorSSL.listenSSL}, that raises L{_listenException}.
        r[rs      rIr!zRaisingMemoryReactor.listenSSLr]r>c��|j�)zS
        Fake L{IReactorSSL.connectSSL}, that raises L{_connectException}.
        r_)rGrrrCr r�rs       rIr#zRaisingMemoryReactor.connectSSLs���$�$�$r>c��|j�)zS
        Fake L{IReactorUNIX.listenUNIX}, that raises L{_listenException}.
        r[r%s      rIr(zRaisingMemoryReactor.listenUNIX'r]r>c��|j�)zU
        Fake L{IReactorUNIX.connectUNIX}, that raises L{_connectException}.
        r_)rGrrCr�r*s     rIr+z RaisingMemoryReactor.connectUNIX-r`r>c��|j�)ze
        Fake L{IReactorSocket.adoptDatagramPort}, that raises
        L{_connectException}.
        r_)rGr
r	rrs     rIrz&RaisingMemoryReactor.adoptDatagramPort3���
�$�$�$r>c��|j�)zi
        Fake L{IReactorSocket.adoptStreamConnection}, that raises
        L{_connectException}.
        r_rs    rIrz*RaisingMemoryReactor.adoptStreamConnection:rfr>)NNrKrNrPrQ)rVrWrXrYr`r
rrr!r#r(r+rrrZr>rIr8r8�s@���	2�$�$�%�$�LP�%�$�%�%�%r>r8c�6�eZdZdZdZdZd�Zd�Zd�Zd�Z	d�Z
y	)
r9z5
    A pull producer which writes 10 times only.
    rFc�0�||_t�|_yrL)�consumerr�result)rGrjs  rIr`zNonStreamingProducer.__init__Js�� ��
��j��r>c�@�|j�|jdk\rtd��|jjd|jfz�|xjdz
c_|jdk(r+|jj	�|j�yy)z/
        Write the counter value once.
        NrDz"BUG: resume after unregister/stop.s%drA)rj�counterr�rrr��_donerns rIr�z$NonStreamingProducer.resumeProducingNsz���=�=� �D�L�L�B�$6��C�D�D��M�M�������� 7�8��L�L�A��L��|�|�r�!��
�
�0�0�2��
�
��"r>c��td��)z�
        An implementation of C{IPushProducer.pauseProducing}. This should never
        be called on a pull producer, so this just raises an error.
        z"BUG: pause should never be called.)r�rns rIr�z#NonStreamingProducer.pauseProducing[s��
�?�@�@r>c�P�d|_|j}|`|jd�y)zQ
        Fire a L{Deferred} so that users can wait for this to complete.
        N)rjrkrErFs  rIrnzNonStreamingProducer._donebs%����
��K�K���K�	�
�
�4�r>c�2�d|_|j�y)z&
        Stop all production.
        TN)r�rnrns rIr�z"NonStreamingProducer.stopProducingks������
�
�r>N)rVrWrXrYrmr�r`r�r�rnr�rZr>rIr9r9Bs-����G��G�!��A��r>r9c�t���d���fd�}tj|��|�_�jdd��S)a�
    Take a list of disconnecting protocols, callback a L{Deferred} when they're
    all done.

    This is a hack to make some older tests less flaky, as
    L{ITransport.loseConnection} is not atomic on all reactors (for example,
    the CoreFoundation, which sometimes takes a reactor turn for CFSocket to
    realise). New tests should either not use real sockets in testing, or take
    the advice in
    I{https://jml.io/pages/how-to-disconnect-in-twisted-really.html} to heart.

    @param reactor: The reactor to schedule the checks on.
    @type reactor: L{IReactorTime}

    @param protocols: The protocols to wait for disconnecting.
    @type protocols: A L{list} of L{IProtocol}s.
    Nc�~��d�D�cgc]}|jj��c}vr�j�yycc}wri)�	transportr{r�)�x�lc�	protocolss ��rI�_checkz(waitUntilAllDisconnected.<locals>._check�s2����y�A�!����-�-�A�A��G�G�I�B��As�:g{�G�z�?T)�now)r�LoopingCall�clockr_)�reactorrwrxrvs ` @rIr:r:ss;���$
�B��
�	�	�&�	!�B��B�H�
�8�8�D�d�8�#�#r>c�n�eZdZdZdd�Zdd�Zed
d��Zedd��Zdd�Zdd�Zdd�Z	e
dd	��Zy
)r;a�
    L{ILogObserver} That stores its events in a list for later inspection.
    This class is similar to L{LimitedHistoryLogObserver} save that the
    internal buffer is public and intended for external inspection.  The
    observer implements the sequence protocol to ease iteration of the events.

    @ivar _events: The events captured by this observer
    @type _events: L{list}
    c��g|_yrL��_eventsrns rIr`zEventLoggingObserver.__init__�s	��')��r>c�,�t|j�SrL)�lenr�rns rI�__len__zEventLoggingObserver.__len__�s���4�<�<� � r>c��yrLrZ�rG�indexs  rI�__getitem__z EventLoggingObserver.__getitem__����r>c��yrLrZr�s  rIr�z EventLoggingObserver.__getitem__�r�r>c� �|j|SrLrr�s  rIr�z EventLoggingObserver.__getitem__�s���|�|�E�"�"r>c�,�t|j�SrL)�iterr�rns rI�__iter__zEventLoggingObserver.__iter__�s���D�L�L�!�!r>c�:�|jj|�y)z'
        @see: L{ILogObserver}
        N)r�rf)rG�events  rI�__call__zEventLoggingObserver.__call__�s��	
�����E�"r>c�d���|���j��|j��fd���S)a-
        Create an L{EventLoggingObserver} instance that observes the provided
        publisher and will be cleaned up with addCleanup().

        @param testInstance: Test instance in which this logger is used.
        @type testInstance: L{twisted.trial.unittest.TestCase}

        @param publisher: Log publisher to observe.
        @type publisher: twisted.logger.LogPublisher

        @return: An EventLoggingObserver configured to observe the provided
            publisher.
        @rtype: L{twisted.test.proto_helpers.EventLoggingObserver}
        c�&���j��SrL)�removeObserver)�obs�	publishers��rI�<lambda>z8EventLoggingObserver.createWithCleanup.<locals>.<lambda>�s���	�(@�(@��(E�r>)�addObserver�
addCleanup)�cls�testInstancer�r�s  `@rI�createWithCleanupz&EventLoggingObserver.createWithCleanup�s.��� �e�����c�"���� E�F��
r>N)rIrJ)rI�int)r�r�rIr))r��slicerIzSequence[LogEvent])r�zint | slicerIzLogEvent | Sequence[LogEvent])rIzIterator[LogEvent])r�r)rIrJ)r�r-r�r*rIr)rVrWrXrYr`r�r
r�r�r��classmethodr�rZr>rIr;r;�s\���*�!���������#�"�#����r>r;N)PrY�
__future__rr�r�socketrr�typingrrr	r
�zope.interfacerr�zope.interface.verifyr
rr�twisted.internetrrrr�twisted.internet.abstractrr�twisted.internet.addressrrr�twisted.internet.deferr�twisted.internet.errorr�twisted.internet.interfacesrrrrrr r!r"r#r$r%r&�twisted.internet.taskr'�twisted.loggerr(r)r*�twisted.protocolsr+�twisted.pythonr,�twisted.trial.unittestr-�__all__r<�Protocolr.�LineReceiverr/r0r1r2r3r5r4r6�ifacer7r8r9r:r;rZr>rI�<module>r�s���
�#��$�9�9�5�-�"�;�;�E�J�J�+�;�
�
�
�
�(�?�?�#�"�+���"�t�_��'�8�,�,�'�T�%�,�,��0,�,�
�Z��M�2�\)�\)�3�\)�~X��X��W��
�^��!�!��!�@
�Z��,�,��,�^
��+�{�L�.�-��K�K��K�\
�=�
)�&�E���}�%�&�����
�[�+�|�^�D�M%�M%�E�M%�`.�.�b$�:
�\��8�8�H�-�8��8r>

Zerion Mini Shell 1.0