%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�I���dZddlZ	ddlmZddlmZmZddl	m
Z
mZddlm
Z
mZddlmZddlmZmZdd	lmZdd
lmZGd�d�Zeej2�Gd
�d��Zeej6ej8�Gd�d��Zd�Zd�ZGd�d�Z 			dd�Z!eedddfd�Z"d�Z#Gd�d�Z$dd�Z%y#e$rY��wxYw)z0
Utilities and helpers for simulating a network
�N)�Error)�directlyProvides�implementer)�error�
interfaces)�TCP4ClientEndpoint�TCP4ServerEndpoint)�ConnectionRefusedError)�Factory�Protocol)�MemoryReactorClock)�Failurec�$�eZdZd�Zdefd�Zd�Zy)�TLSNegotiationc�<�||_||_d|_||_y)NF)�obj�connectState�sent�readyToSend)�selfrrs   �4/usr/lib/python3/dist-packages/twisted/test/iosim.py�__init__zTLSNegotiation.__init__s �����(�����	�'����returnc�"�d|j�d�S)NzTLSNegotiation(�))r�rs r�__repr__zTLSNegotiation.__repr__!s�� �����A�.�.rc��|jj|j�s t�|_|j	�yy�N)r�iosimVerify�NativeOpenSSLError�disconnectReason�loseConnection)r�other�tpts   r�pretendToVerifyzTLSNegotiation.pretendToVerify$s6���x�x�#�#�E�I�I�.�#5�#7�C� ���� �/rN)�__name__�
__module__�__qualname__r�strrr'�rrrrs��(�/�#�/�!rrc��eZdZdZy)�FakeAddressz]
    The default address type for the host and peer of L{FakeTransport}
    connections.
    N)r(r)r*�__doc__r,rrr.r.-s��rr.c� �eZdZdZeej�fd��ZdZdZ	dZ
ejd�Z
dZdZdZd d�Zdefd�Zd	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"d!d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d�Z*y)"�
FakeTransportz�
    A wrapper around a file-like object to make it behave as a Transport.

    This doesn't actually stream the file to the attached protocol,
    and is thus useful mainly as a utility for debugging protocols.
    c�*�tt|��Sr )�int�next)�counters r�<lambda>zFakeTransport.<lambda>>s���T�'�]�AS�rrzConnection doneNc��||_||_g|_|j�|_|�
t�}||_|�
t�}||_y)a�
        @param protocol: This transport will deliver bytes to this protocol.
        @type protocol: L{IProtocol} provider

        @param isServer: C{True} if this is the accepting side of the
            connection, C{False} if it is the connecting side.
        @type isServer: L{bool}

        @param hostAddress: The value to return from C{getHost}.  L{None}
            results in a new L{FakeAddress} being created to use as the value.
        @type hostAddress: L{IAddress} provider or L{None}

        @param peerAddress: The value to return from C{getPeer}.  L{None}
            results in a new L{FakeAddress} being created to use as the value.
        @type peerAddress: L{IAddress} provider or L{None}
        N)�protocol�isServer�stream�_nextserial�serialr.�hostAddress�peerAddress)rr8r9r=r>s     rrzFakeTransport.__init__GsS��"!��
� ��
�����&�&�(�����%�-�K�&�����%�-�K�&��rrc��dj|jxrdxsd|j|jjj
�S)NzFakeTransport<{},{},{}>�S�C)�formatr9r<r8�	__class__r(rs rrzFakeTransport.__repr__cs@��(�/�/��M�M�!�c�(�S��K�K��M�M�#�#�,�,�
�	
rc��|jry|j�|jj|�y|jj|�yr )�
disconnecting�tls�tlsbuf�appendr:)r�datas  r�writezFakeTransport.writejs<�������8�8���K�K���t�$��K�K���t�$rc�l�|jr(|js|jj�yyyr ��producer�streamingProducer�resumeProducingrs r�_checkProducerzFakeTransport._checkProducerts*���=�=��!7�!7��M�M�)�)�+�"8�=rc�F�||_||_|s|j�yy)z.
        From abstract.FileDescriptor
        NrL)rrM�	streamings   r�registerProducerzFakeTransport.registerProducerzs'��!��
�!*�����$�$�&�rc��d|_yr )rMrs r�unregisterProducerz FakeTransport.unregisterProducer�s	����
rc�D�|j�|j�yr )rUr$rs r�
stopConsumingzFakeTransport.stopConsuming�s�����!����rc�D�|jdj|��y)Nr)rJ�join)r�iovecs  r�
writeSequencezFakeTransport.writeSequence�s���
�
�3�8�8�E�?�#rc��d|_y�NT�rErs rr$zFakeTransport.loseConnection�s
��!��rc��d|_y)zp
        For the time being, this is the same as loseConnection; no buffered
        data will be lost.
        TNr^rs r�abortConnectionzFakeTransport.abortConnection�s��
"��rc��|j�t�}n|j}|jj	t|��yr )rFr"r#r8�connectionLostr)r�errs  r�reportDisconnectzFakeTransport.reportDisconnect�s7���8�8��%�&�C��'�'�C��
�
�$�$�W�S�\�2rc��y)zM
        Identify this transport/event source to the logging system.
        �iosimr,rs r�	logPrefixzFakeTransport.logPrefix�s��rc��|jSr )r>rs r�getPeerzFakeTransport.getPeer�������rc��|jSr )r=rs r�getHostzFakeTransport.getHost�rjrc��yr r,rs rrOzFakeTransport.resumeProducing����rc��yr r,rs r�pauseProducingzFakeTransport.pauseProducing�rnrc�$�|j�yr )r$rs r�
stopProducingzFakeTransport.stopProducing�s�����rc�R�|j|z}t||�|_g|_yr )r9rrFrG)r�contextFactory�beNormalrs    r�startTLSzFakeTransport.startTLS�s'���}�}�x�/��!�.�,�?�����rc���|j}|rg|_dj|�S|j�4|jjrd|j_|jSyy)z�
        Get the pending writes from this transport, clearing them from the
        pending buffer.

        @return: the bytes written with C{transport.write}
        @rtype: L{bytes}
        rNT)r:rYrFrr)rr@s  r�getOutBufferzFakeTransport.getOutBuffer�sV��
�K�K����D�K��8�8�A�;��
�X�X�
!��x�x�#�#� $����
��x�x���rc��t|t�r�|j�J�|jjrc|jj	||�d|_|j
dc}|_|j
|�t|tj�yd|j_
y|jj|�yr])
�
isinstancerrFrr'rGr[rr�
ISSLTransportrr8�dataReceived)r�buf�bs   r�bufferReceivedzFakeTransport.bufferReceived�s����c�>�*��8�8�'�'�'��x�x�}�}����(�(��d�3����"&���d���4�;��"�"�1�%� ��z�'?�'?�@�(,����$��M�M�&�&�s�+rc��yr r,rs r�getTcpKeepAlivezFakeTransport.getTcpKeepAlive�rnrc��yr r,rs r�
getTcpNoDelayzFakeTransport.getTcpNoDelay�rnrc��yr r,rs r�loseWriteConnectionz!FakeTransport.loseWriteConnection�rnrc��yr r,�r�enableds  r�setTcpKeepAlivezFakeTransport.setTcpKeepAlive�rnrc��yr r,r�s  r�
setTcpNoDelayzFakeTransport.setTcpNoDelay�rnr)NN)T)+r(r)r*r/�staticmethod�	itertools�countr;�closedrE�disconnectedr�ConnectionDoner#rMrNrFrr+rrJrPrSrUrWr[r$r`rdrgrirlrOrprrrvrxrr�r�r�r�r�r,rrr1r15s�����o�i�o�o�.?�S�T�K�
�F��M��L�+�u�+�+�,=�>���H���
�C�'�8
�#�
�%�,�'���$�"�"�3�� � �
�
����,,�&
�
�
�
�
rr1c��t|d��S)z�
    Create and return a new in-memory transport hooked up to the given protocol.

    @param clientProtocol: The client protocol to use.
    @type clientProtocol: L{IProtocol} provider

    @return: The transport.
    @rtype: L{FakeTransport}
    F�r9�r1)�clientProtocols r�makeFakeClientr��s����%�8�8rc��t|d��S)z�
    Create and return a new in-memory transport hooked up to the given protocol.

    @param serverProtocol: The server protocol to use.
    @type serverProtocol: L{IProtocol} provider

    @return: The transport.
    @rtype: L{FakeTransport}
    Tr�r�)�serverProtocols r�makeFakeServerr�
s����$�7�7rc�(�eZdZdZdd�Zdd�Zdd�Zy)�IOPumpz�
    Utility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    Nc�p�||_||_||_||_||_|�
t�}||_yr )�client�server�clientIO�serverIO�debugr
�clock)rr�r�r�r�r�r�s       rrzIOPump.__init__s9�������� ��
� ��
���
��=�&�(�E���
rc�b�d}td�D]}|j||�rd}�|SJd��)zk
        Pump until there is no more input or output.

        Returns whether any data was moved.
        Fi�TzToo long)�range�pump)rr��advanceClock�result�_s     r�flushzIOPump.flush(sE�����t��	!�A��y�y���-�����
�	!�
!�j� �1rc�\�|r|jjd�|js|rtd�|jj�}|jj�}|jj�|jj�|js|r=td�|rtdt|�z�|rtdt|�z�|r|jj|�|r|jj|�|s|ry|jjrl|jjsV|js|rtd�d|j_d|j_
|jj�y|jjrl|jjsV|js|rtd�d|j_d|j_
|jj�yy	)
z�
        Move data back and forth, while also triggering any currently pending
        scheduled calls (i.e. C{callLater(0, f)}).

        Returns whether any data was moved.
        rz
-- GLUG --�.zC: zS: Tz* Cz* SF)
r��advancer��printr�rxr�rP�reprrrEr�rd)rr�r��sData�cDatas     rr�zIOPump.pump8s�����J�J���q�!��:�:���,���
�
�*�*�,���
�
�*�*�,���
�
�$�$�&��
�
�$�$�&��:�:���#�J���e�d�5�k�)�*���e�d�5�k�)�*���M�M�(�(��/���M�M�(�(��/��E���=�=�&�&�t�}�}�/I�/I��z�z�U��e��)-�D�M�M�&�*.�D�M�M�'��M�M�*�*�,���=�=�&�&�t�}�}�/I�/I��z�z�U��e��)-�D�M�M�&�*.�D�M�M�'��M�M�*�*�,��rr )FT)r(r)r*r/rr�r�r,rrr�r�s����� *rr�FTc��|j|�|j|�t||||||��}|r|j�|S)a�
    Create a new L{IOPump} connecting two protocols.

    @param serverProtocol: The protocol to use on the accepting side of the
        connection.
    @type serverProtocol: L{IProtocol} provider

    @param serverTransport: The transport to associate with C{serverProtocol}.
    @type serverTransport: L{FakeTransport}

    @param clientProtocol: The protocol to use on the initiating side of the
        connection.
    @type clientProtocol: L{IProtocol} provider

    @param clientTransport: The transport to associate with C{clientProtocol}.
    @type clientTransport: L{FakeTransport}

    @param debug: A flag indicating whether to log information about what the
        L{IOPump} is doing.
    @type debug: L{bool}

    @param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
        returning to put the protocols into their post-handshake or
        post-server-greeting state?
    @type greet: L{bool}

    @param clock: An optional L{Clock}. Pumping the resulting L{IOPump} will
        also increase clock time by a small increment.

    @return: An L{IOPump} which connects C{serverProtocol} and
        C{clientProtocol} and delivers bytes between them when it is pumped.
    @rtype: L{IOPump}
    �r�)�makeConnectionr�r�)r��serverTransportr��clientTransportr��greetr�r�s        r�connectr�esP��T�!�!�/�2��!�!�/�2������
��
�D�
��
�
���Krc�h�|�}|�}||�}	||�}
||t||
||	|||��fS)a�
    Connect a given server and client class to each other.

    @param ServerClass: a callable that produces the server-side protocol.
    @type ServerClass: 0-argument callable returning L{IProtocol} provider.

    @param ClientClass: like C{ServerClass} but for the other side of the
        connection.
    @type ClientClass: 0-argument callable returning L{IProtocol} provider.

    @param clientTransportFactory: a callable that produces the transport which
        will be attached to the protocol returned from C{ClientClass}.
    @type clientTransportFactory: callable taking (L{IProtocol}) and returning
        L{FakeTransport}

    @param serverTransportFactory: a callable that produces the transport which
        will be attached to the protocol returned from C{ServerClass}.
    @type serverTransportFactory: callable taking (L{IProtocol}) and returning
        L{FakeTransport}

    @param debug: Should this dump an escaped version of all traffic on this
        connection to stdout for inspection?
    @type debug: L{bool}

    @param greet: Should the L{IOPump} be L{flushed <IOPump.flush>} once before
        returning to put the protocols into their post-handshake or
        post-server-greeting state?
    @type greet: L{bool}

    @param clock: An optional L{Clock}. Pumping the resulting L{IOPump} will
        also increase clock time by a small increment.

    @return: the client protocol, the server protocol, and an L{IOPump} which,
        when its C{pump} and C{flush} methods are called, will move data
        between the created client and server protocol instances.
    @rtype: 3-L{tuple} of L{IProtocol}, L{IProtocol}, L{IOPump}
    r�)r�)�ServerClass�ClientClass�clientTransportFactory�serverTransportFactoryr�r�r��c�s�cio�sios           r�connectedServerAndClientr��sE��\	�
�A��
�A�
 ��
#�C�
 ��
#�C��a���C��C���U�C�C�Crc�4�|\}}}}}|\}}}	}
||k(r||fSy)a'
    Should the client and server described by the arguments be connected to
    each other, i.e. do their port numbers match?

    @param clientInfo: the args for connectTCP
    @type clientInfo: L{tuple}

    @param serverInfo: the args for listenTCP
    @type serverInfo: L{tuple}

    @return: If they do match, return factories for the client and server that
        should connect; otherwise return L{None}, indicating they shouldn't be
        connected.
    @rtype: L{None} or 2-L{tuple} of (L{ClientFactory},
        L{IProtocolFactory})
    Nr,)�
clientInfo�
serverInfo�
clientHost�
clientPort�
clientFactory�
clientTimeout�clientBindAddress�
serverPort�
serverFactory�
serverBacklog�serverInterfaces           r�_factoriesShouldConnectr��s?��.	�
������BL�?�Z��
���Z���m�+�+�rc�>�eZdZdZd�Zdd�Zee��fd�Zy)�ConnectionCompleterz�
    A L{ConnectionCompleter} can cause synthetic TCP connections established by
    L{MemoryReactor.connectTCP} and L{MemoryReactor.listenTCP} to succeed or
    fail.
    c��||_y)z�
        Create a L{ConnectionCompleter} from a L{MemoryReactor}.

        @param memoryReactor: The reactor to attach to.
        @type memoryReactor: L{MemoryReactor}
        N)�_reactor)r�
memoryReactors  rrzConnectionCompleter.__init__�s��&��
rc	��|j}t|j�D]�\}}|jD]�}t	||�}|s�|jj|�|jj|�|\}}|jd�}	|jd�}
t|
�}t|	�}t|
||	||�ccS��y)a�
        Complete a single TCP connection established on this
        L{ConnectionCompleter}'s L{MemoryReactor}.

        @param debug: A flag; whether to dump output from the established
            connection to stdout.
        @type debug: L{bool}

        @return: a pump for the connection, or L{None} if no connection could
            be established.
        @rtype: L{IOPump} or L{None}
        N)r��	enumerate�
tcpClients�
tcpServersr��remove�
connectors�pop�
buildProtocolr�r�r�)
rr�r��	clientIdxr�r��	factoriesr�r�r�r�r�r�s
             r�succeedOncezConnectionCompleter.succeedOnces����
�
�
�%.�}�/G�/G�%H�	�!�I�z�+�6�6�
�
�3�J�
�K�	��!�,�,�3�3�J�?�!�,�,�0�0��;�3<�0�M�=�%2�%@�%@��%F�N�%2�%@�%@��%F�N�&4�^�&D�O�&4�^�&D�O�"�&�'�&�'����
�	rc��|jjjd�dj|jjjd�|�y)z�
        Fail a single TCP connection established on this
        L{ConnectionCompleter}'s L{MemoryReactor}.

        @param reason: the reason to provide that the connection failed.
        @type reason: L{Failure}
        r�N)r�r�r��clientConnectionFailedr�)r�reasons  r�failOncezConnectionCompleter.failOnce$sF��	
�
�
� � �$�$�Q�'��*�A�A��M�M�$�$�(�(��+�V�	
rN�F)	r(r)r*r/rr�rr
r�r,rrr�r��s%���&��B&�&<�&>�?�

rr�c��t�}t|dd�}t|d�}|jt	j
t��|t|�fS)a�
    Create an endpoint that can be fired on demand.

    @param debug: A flag; whether to dump output from the established
        connection to stdout.
    @type debug: L{bool}

    @return: A client endpoint, and an object that will cause one of the
        L{Deferred}s returned by that client endpoint.
    @rtype: 2-L{tuple} of (L{IStreamClientEndpoint}, L{ConnectionCompleter})
    z0.0.0.0i�)r
rr	�listenr�forProtocolrr�)r��reactor�clientEndpoint�serverEndpoints    r�connectableEndpointr�1sP��!�"�G�'���D�A�N�'���6�N����'�-�-�h�7�8��.�w�7�7�7r)FTNr�)&r/r��OpenSSL.SSLrr"�ImportError�zope.interfacerr�twisted.internetrr�twisted.internet.endpointsrr	�twisted.internet.errorr
�twisted.internet.protocolrr�twisted.internet.testingr
�twisted.python.failurerr�IAddressr.�
ITransport�
ITLSTransportr1r�r�r�r�r�r�r�r�r,rr�<module>r�s���
��	�7�9�.�M�9�7�7�*�!�!�&
�Z�
 �
 �!���"��
�Z�
"�
"�J�$<�$<�=�D
�D
�>�D
�N
9�
8�K�K�f�
�
�7�z*�)�
�
�
�2D�j�>;
�;
�|8��I�	��	�s�C�C
�C


Zerion Mini Shell 1.0