%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f�.����dZddlZddlmZddlmZmZmZmZddl	m
Z
ddlmZddl
mZddlmZGd	�d
�Zee
�Gd�d��Zeej&ej(�Gd
�d��Zd�Zd�Zefd�Zd�Zd�Zeej&ej(�Gd�d��ZGd�dej8�ZGd�dej<�Zdd�Z dd�Z!y)zF
Testing support for protocols -- loopback between client and server.
�N)�implementer)�defer�
interfaces�main�protocol)�IAddress)�
deferLater)�policies)�failurec�4�eZdZdZdZdZd�Zd�Zd�ZeZ	d�Z
y)�_LoopbackQueuez�
    Trivial wrapper around a list to give it an interface like a queue, which
    the addition of also sending notifications by way of a Deferred whenever
    the list has something added to it.
    NFc��g|_y�N)�_queue��selfs �</usr/lib/python3/dist-packages/twisted/protocols/loopback.py�__init__z_LoopbackQueue.__init__"s	�����c��|jj|�|j�&|jdc}|_|jd�yyr)r�append�_notificationDeferred�callback)r�v�ds   r�putz_LoopbackQueue.put%sF�������1���%�%�1�,0�,F�,F��)�A�t�)�
�J�J�t��2rc�,�t|j�Sr)�boolrrs r�__nonzero__z_LoopbackQueue.__nonzero__+s���D�K�K� � rc�8�|jjd�S�Nr)r�poprs r�getz_LoopbackQueue.get0s���{�{���q�!�!r)�__name__�
__module__�__qualname__�__doc__r�
disconnectrrr�__bool__r#�rrr
r
s/���!���J���!��H�"rr
c��eZdZy)�_LoopbackAddressN)r$r%r&r*rrr,r,4s��rr,c�P�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy)
�_LoopbackTransportFNc��||_yr)�q)rr0s  rrz_LoopbackTransport.__init__?s	����rc�p�t|t�std��|jj	|�y)Nz"Can only write bytes to ITransport)�
isinstance�bytes�	TypeErrorr0r�r�datas  r�writez_LoopbackTransport.writeBs(���$��&��@�A�A����
�
�4�rc�X�|jjdj|��y�Nr)r0r�join�r�iovecs  r�
writeSequencez _LoopbackTransport.writeSequenceGs�����
�
�3�8�8�E�?�#rc�\�d|j_|jjd�y)NT)r0r(rrs r�loseConnectionz!_LoopbackTransport.loseConnectionJs�� ��������
�
�4�rc�$�|j�y)zB
        Abort the connection. Same as L{loseConnection}.
        N)r?rs r�abortConnectionz"_LoopbackTransport.abortConnectionNs��	
���rc��t�Sr�r,rs r�getPeerz_LoopbackTransport.getPeerT����!�!rc��t�SrrCrs r�getHostz_LoopbackTransport.getHostWrErc�\�|j�J�||_||_|j�yr)�producer�streamingProducer�
_pollProducer�rrI�	streamings   r�registerProducerz#_LoopbackTransport.registerProducer[s-���}�}�$�$�$� ��
�!*������rc�.�|j�J�d|_yr�rIrs r�unregisterProducerz%_LoopbackTransport.unregisterProduceras���}�}�(�(�(���
rc�l�|j�(|js|jj�yyyr)rIrJ�resumeProducingrs rrKz _LoopbackTransport._pollProduceres-���=�=�$�T�-C�-C��M�M�)�)�+�.D�$r)r$r%r&�
disconnectingrIrr7r=r?rArDrGrNrQrKr*rrr.r.9s>���M��H���
$���"�"���,rr.c�X�|r(|j�}|�y|j|�|r�'yy)z�
    L{identityPumpPolicy} is a policy which delivers each chunk of data written
    to the given queue as-is to the target.

    This isn't a particularly realistic policy.

    @see: L{loopbackAsync}
    N)r#�dataReceived)�queue�targetr3s   r�identityPumpPolicyrYjs-����	�	����=�����E�"�	rc��g}|r'|j�}|�n|j|�|r�'|r!|jdj|��yy)z�
    L{collapsingPumpPolicy} is a policy which collapses all outstanding chunks
    into a single string and delivers it to the target.

    @see: L{loopbackAsync}
    Nr)r#rrVr:)rWrXr3�chunks    r�collapsingPumpPolicyr\zsP��
�E�
��	�	����=��
���U��	�

����C�H�H�U�O�,�
rc��t�}t�}|jt|��|jt|��t|||||�S)a
    Establish a connection between C{server} and C{client} then transfer data
    between them until the connection is closed. This is often useful for
    testing a protocol.

    @param server: The protocol instance representing the server-side of this
        connection.

    @param client: The protocol instance representing the client-side of this
        connection.

    @param pumpPolicy: When either C{server} or C{client} writes to its
        transport, the string passed in is added to a queue of data for the
        other protocol.  Eventually, C{pumpPolicy} will be called with one such
        queue and the corresponding protocol object.  The pump policy callable
        is responsible for emptying the queue and passing the strings it
        contains to the given protocol's C{dataReceived} method.  The signature
        of C{pumpPolicy} is C{(queue, protocol)}.  C{queue} is an object with a
        C{get} method which will return the next string written to the
        transport, or L{None} if the transport has been disconnected, and which
        evaluates to C{True} if and only if there are more items to be
        retrieved via C{get}.

    @return: A L{Deferred} which fires when the connection has been closed and
        both sides have received notification of this.
    )r
�makeConnectionr.�_loopbackAsyncBody)�server�client�
pumpPolicy�serverToClient�clientToServers     r�
loopbackAsyncre�sT��6$�%�N�#�%�N�
���,�^�<�=�
���,�^�<�=������
��rc�$���fd�}	dx}x}}||||�}||||�}|s@|s>tj�}	|	|_|	|_|	jt||||��|	S|j
r
d}||||�n|j
rd}||||�|ry|j
tjtj��|j
tjtj��tjd�S��
)ak
    Transfer bytes from the output queue of each protocol to the input of the other.

    @param server: The protocol instance representing the server-side of this
    connection.

    @param serverToClient: The L{_LoopbackQueue} holding the server's output.

    @param client: The protocol instance representing the client-side of this
    connection.

    @param clientToServer: The L{_LoopbackQueue} holding the client's output.

    @param pumpPolicy: See L{loopbackAsync}.

    @return: A L{Deferred} which fires when the connection has been closed and
        both sides have received notification of this.
    c�b��d}|r�||�d}|r|s|jj�|S)NFT)�	transportrK)�sourcer0rX�sentrbs    �r�pumpz _loopbackAsyncBody.<locals>.pump�s8�������q�&�!��D���
���*�*�,��rFTN)r�Deferredr�addCallback�_loopbackAsyncContinuer(�connectionLostr�Failurer�CONNECTION_DONE�succeed)
r`rcrardrbrkr(�
clientSent�
serverSentrs
    `     rr_r_�s���(
��/4�4�
�4�Z�*��&�.�&�9�
��&�.�&�9�
��*���� �A�34�N�0�34�N�0�
�M�M�&������

��H��$�$��J�����0�
�
&�
&��J�����0���!�!�'�/�/�$�2F�2F�"G�H��!�!�'�/�/�$�2F�2F�"G�H��=�=��&�&�Irc
�V�d|_d|_ddlm}t|dt|||||�S)Nr��reactor)r�twisted.internetrwr	r_)�ignoredr`rcrardrbrws       rrnrn�s>��
,0�N�(�+/�N�(�)���	�������	�	rc�Z�eZdZdZdZdZdZdd�Zd�Zd�Z	d�Z
d�Zd	�Zd
�Z
d�Zd�Zd
�Zy)�
LoopbackRelayrrNc� �||_||_yr)rX�logFile)rrXr}s   rrzLoopbackRelay.__init__s�������rc��|j|z|_|jr(|jjdt|�z�yy)Nzloopback writing %s
)�bufferr}r7�reprr5s  rr7zLoopbackRelay.writes:���k�k�D�(����<�<��L�L���6��d��C�D�rc�D�|jdj|��yr9)r7r:r;s  rr=zLoopbackRelay.writeSequence"s���
�
�3�8�8�E�?�#rc��|jdk(ry|jr|jj�|jrk|jr1|jjdt
|j�z�|j}d|_|jj|�|jdk(rDd|_|jjtjtj��yy)N���zloopback receiving %s
r�)�
shouldLoserIrSrr}r7r�rXrVrorrprrq)rrs  r�clearBufferzLoopbackRelay.clearBuffer%s����?�?�b� ���=�=��M�M�)�)�+��;�;��|�|����"�"�#<�t�D�K�K�?P�#P�Q��[�[�F��D�K��K�K�$�$�V�,��?�?�a�� �D�O��K�K�&�&�w���t�7K�7K�'L�M� rc�2�|jdk7rd|_yy)Nr�r�)r�rs rr?zLoopbackRelay.loseConnection5s���?�?�b� ��D�O�!rc��y�N�loopbackr*rs rrGzLoopbackRelay.getHost9���rc��yr�r*rs rrDzLoopbackRelay.getPeer<r�rc��||_yrrPrLs   rrNzLoopbackRelay.registerProducer?s	�� ��
rc��d|_yrrPrs rrQz LoopbackRelay.unregisterProducerBs	����
rc�J�d|jjj�d�S)Nz	Loopback(�))rX�	__class__r$rs r�	logPrefixzLoopbackRelay.logPrefixEs"���4�;�;�0�0�9�9�<�A�>�>rr)r$r%r&rr�rTrIrr7r=r�r?rGrDrNrQr�r*rrr{r{sJ��
�F��J��M��H��E�
$�N�  ���!��?rr{c��eZdZd�Zd�Zd�Zy)�LoopbackClientFactoryc�R�d|_tj�|_||_yr!)�disconnectedrrl�deferredr)rrs  rrzLoopbackClientFactory.__init__Js��������(��
� ��
rc��|jSr)r)r�addrs  r�
buildProtocolz#LoopbackClientFactory.buildProtocolOs���}�}�rc�H�d|_|jjd�y)Nr�)r�r�r)r�	connector�reasons   r�clientConnectionLostz*LoopbackClientFactory.clientConnectionLostRs������
�
���t�$rN)r$r%r&rr�r�r*rrr�r�Is��!�
�%rr�c��eZdZd�Zd�Zy)�_FireOnClosec�x�tjj|||�tj�|_yr)r
�ProtocolWrapperrrrlr�)rr�factorys   rrz_FireOnClose.__init__Xs(��� � �)�)�$��'�B����(��
rc�z�tjj||�|jj	d�yr)r
r�ror�r)rr�s  rroz_FireOnClose.connectionLost\s*��� � �/�/��f�=��
�
���t�$rN)r$r%r&rror*rrr�r�Ws��)�%rr�c���	�ddlm}tjt	j
��}t
||��	||_�	fd�|_|j||d���t|�}||_|jd�j�j|�|j}|j�	fd��|j�fd��|S)zBRun session between server and client protocol instances over TCP.rrvc����Srr*�r��
serverWrappers �r�<lambda>zloopbackTCP.<locals>.<lambda>h����=�rz	127.0.0.1)�	interfacec����jSr�r���xr�s �rr�zloopbackTCP.<locals>.<lambda>n�
���M�2�2�rc�$���j�Sr��
stopListening�r��
serverPorts �rr�zloopbackTCP.<locals>.<lambda>o����J�4�4�6�r)rxrwr
�WrappingFactoryr�Factoryr��noisyr��	listenTCPr��
connectTCPrG�portr�rm)
r`rar�r�rw�f�clientFrr�r�s
        @@r�loopbackTCPr�as����(�� � ��!1�!1�!3�4�A� ��F�+�M��A�G�0�A�O��"�"�4��k�"�B�J�#�F�+�G��G�M����{�J�$6�$6�$8�$=�$=�w�G����A��M�M�2�3��M�M�6�7��Hrc���	�tj�}ddlm}t	j
t
j��}t||��	||_	�	fd�|_
|j||��t|�}||_	|j||�|j}|j�	fd��|j�fd��|S)zJRun session between server and client protocol instances over UNIX socket.rrvc����Srr*r�s �rr�zloopbackUNIX.<locals>.<lambda>{r�rc����jSrr�r�s �rr�zloopbackUNIX.<locals>.<lambda>�r�rc�$���j�Srr�r�s �rr�zloopbackUNIX.<locals>.<lambda>�r�r)�tempfile�mktemprxrwr
r�rr�r�r�r��
listenUNIXr��connectUNIXr�rm)
r`rar��pathrwr�r�rr�r�s
        @@r�loopbackUNIXr�ss�����?�?��D�(�� � ��!1�!1�!3�4�A� ��F�+�M��A�G�0�A�O��#�#�D�!�,�J�#�F�+�G��G�M�����g�&����A��M�M�2�3��M�M�6�7��Hr)rT)T)"r'r��zope.interfacerrxrrrr�twisted.internet.interfacesr�twisted.internet.taskr	�twisted.protocolsr
�twisted.pythonrr
r,�
ITransport�	IConsumerr.rYr\rer_rnr{�
ClientFactoryr�r�r�r�r�r*rr�<module>r�s���
��&�>�>�0�,�'�"�"�"�8
�X��	�	��	�
�Z�
"�
"�J�$8�$8�9�-,�-,�:�-,�`
#� -�".@�#�LD'�N�4
�Z�
"�
"�J�$8�$8�9�3?�3?�:�3?�l%�H�2�2�%�%�8�+�+�%�
�$
r

Zerion Mini Shell 1.0