%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__/test_unix.cpython-312.pyc

�

Ϫ�f5����dZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
ddlmZddlmZddlmZddlmZmZdd	lmZGd
�dej0�Zee
j4ed�d�Gd
�dej6��ZGd�dej:�ZGd�dej>�Z ee
jBed�d�Gd�dej6��Z"y)zK
Tests for implementations of L{IReactorUNIX} and L{IReactorUNIXDatagram}.
�N)�skipIf)�address�defer�error�
interfaces�protocol�reactor�utils)�lockfile)�
networkString)�FilePath)�MyClientFactory�MyServerFactory)�unittestc��eZdZd�Zd�Zy)�FailedConnectionClientFactoryc��||_y�N)�onFail)�selfrs  �8/usr/lib/python3/dist-packages/twisted/test/test_unix.py�__init__z&FailedConnectionClientFactory.__init__s	�����c�:�|jj|�yr)r�errback)r�	connector�reasons   r�clientConnectionFailedz4FailedConnectionClientFactory.clientConnectionFaileds�������F�#rN)�__name__�
__module__�__qualname__rr�rrrrs���$rr�1This reactor does not support UNIX domain socketsc�p�eZdZdZej
ed�sdZd�Zd�Z	d�Z
d�Zd�Zd	�Z
d
�Zd�Zd�Zy)
�UnixSocketTestsz
    Test unix sockets.
    Nr#c������j�}�j��t��tj�x}�_tj|��}�j|j�tjtjtj�}�j|j�|j��|j|����fd�}|j|�|S)z�
        The address passed to the server factory's C{buildProtocol} method and
        the address returned by the connected protocol's transport's C{getPeer}
        method match the address the client socket is bound to.
        c���tj��}�j�j|g��j|jj�|�yr)r�UNIXAddress�assertEqual�
peerAddresses�	transport�getPeer)�proto�expected�peernamer�
serverFactorys  ���r�
cbConnMadez1UnixSocketTests.test_peerBind.<locals>.cbConnMade;sH����*�*�8�4�H����]�8�8�8�*�E����U�_�_�4�4�6��Ar)�mktemprr�Deferred�protocolConnectionMader	�
listenUNIX�
addCleanup�
stopListening�socket�AF_UNIX�SOCK_STREAM�close�bind�connect�addCallback)r�filename�connMade�unixPort�
unixSocketr1r/r0s`     @@r�
test_peerBindzUnixSocketTests.test_peerBind*s�����;�;�=���;�;�=��'�)�
�:?�.�.�:J�J��=�7��%�%�h�
�>������.�.�/��]�]�6�>�>�6�3E�3E�F�
����
�(�(�)�����!����8�$�	B�
	���Z�(��rc������j��t�}tj�}||_tj�|�}�j|j�t��tj�}|�_tj���tj||g�}���fd�}|j|�|S)z�
        L{IReactorUNIX.connectUNIX} can be used to connect a client to a server
        started with L{IReactorUNIX.listenUNIX}.
        c����|\}}�j�jtj��g�|jj�|jj�yr)r)r*rr(r+�loseConnection)�args�serverProtocol�clientProtocol�
clientFactoryr?rs   ���r�allConnectedz1UnixSocketTests.test_dumber.<locals>.allConnectedTs\���-1�*�N�N�
����+�+�g�.A�.A�(�.K�-L�
�
�$�$�3�3�5��$�$�3�3�5r)
r2rrr3r4r	r5r6r7r�connectUNIX�
gatherResultsr>)	rr0�serverConnMaderA�clientConnMade�drKrJr?s	`      @@r�test_dumberzUnixSocketTests.test_dumberCs����
�;�;�=��'�)�
����)��/=�
�,��%�%�h�
�>������.�.�/�'�)�
����)��/=�
�,����H�m�4������ @�A��		6�	
�
�
�l�#��rc�����	��j��t�}tj�}||_tj�|d���	�jtj�dz��t��tj�}|�_tj��d��tj||g�}����	fd�}|j|���fd�}|j|�|S)z�
        A lockfile is created and locked when L{IReactorUNIX.listenUNIX} is
        called and released when the Deferred returned by the L{IListeningPort}
        provider's C{stopListening} method is called back.
        T��wantPID�.lock���checkPIDc���|\}}�j�jtj��g�|jj�|jj��j
�Sr)r)r*rr(r+rFr7)rGrH�clientProtorJr?rrAs   ����r�
_portStuffz0UnixSocketTests.test_pidFile.<locals>._portStuffysk���*.�'�N�K�
����+�+�g�.A�.A�(�.K�-L�
�
�!�!�0�0�2��$�$�3�3�5��)�)�+�+rc�V���jtj�dz�d�y)NrU�locked)�assertFalser�isLocked)�ignoredr?rs ��r�_checkz,UnixSocketTests.test_pidFile.<locals>._check�s#������X�.�.�x�'�/A�B�H�Mr)r2rrr3r4r	r5�
assertTruerr_rrLrMr>)
rr0rNrOrPr[rarJr?rAs
`      @@@r�test_pidFilezUnixSocketTests.test_pidFilebs�����;�;�=��'�)�
����)��/=�
�,��%�%�h�
�t�L������)�)�(�W�*<�=�>�
(�)�
����)��/=�
�,����H�m�a�@������ @�A��	,�	
�
�
�j�!�	N�	
�
�
�f���rc����|j��t��tj��d��}|j	t
jtj��d����fd�}|j�j|�S)z�
        L{IReactorUNIX.listenUNIX} raises L{error.CannotListenError} if passed
        the name of a file on which a server is already listening.
        TrSc�T��tj��d��}|j�S�NTrS)r	r5r7)�ignrAr?r0s  ��r�stoppedListeningz<UnixSocketTests.test_socketLocking.<locals>.stoppedListening�s&����)�)�(�M�4�P�H��)�)�+�+r)	r2rr	r5�assertRaisesr�CannotListenErrorr7r>)rrArhr?r0s   @@r�test_socketLockingz"UnixSocketTests.test_socketLocking�s|���
�;�;�=��'�)�
��%�%�h�
�t�L������#�#�������	�	
�	,��%�%�'�3�3�4D�E�Erc��|j�|_td|j�d��}dttj
j
tj��j�ji}ttj�j�j}tj|dd|f|��}|j|�|S)NzBfrom twisted.internet import protocol, reactor
reactor.listenUNIX(z), protocol.ServerFactory(),wantPID=True)
s
PYTHONPATHs-us-c)�env)r2r?rr
�os�pathsep�join�sys�path�asBytesMode�
executabler
�getProcessValuer>)r�callback�sourcerm�pyExerPs      r�_uncleanSocketTestz"UnixSocketTests._uncleanSocketTest�s������
��
���}�}�
�
���h�r�z�z���s�x�x�'@�A�M�M�O�T�T�U������(�4�4�6�;�;���!�!�%�%���)?�S�I��	�
�
�h���rc�0���fd�}�j|�S)a"
        If passed C{True} for the C{wantPID} parameter, a server can be started
        listening with L{IReactorUNIX.listenUNIX} when passed the name of a
        file on which a previous server which has not exited cleanly has been
        listening using the C{wantPID} option.
        c�x��tj�jt�d��}|j	�Srf)r	r5r?rr7)rg�prs  �r�ranStupidChildzGUnixSocketTests.test_uncleanServerSocketLocking.<locals>.ranStupidChild�s+����"�"�4�=�=�/�2C�T�R�A��?�?�$�$r�ry�rr}s` r�test_uncleanServerSocketLockingz/UnixSocketTests.test_uncleanServerSocketLocking�s���	%�
�&�&�~�6�6rc�0���fd�}�j|�S)z�
        If passed C{True} for the C{checkPID} parameter, a client connection
        attempt made with L{IReactorUNIX.connectUNIX} fails with
        L{error.BadFileError}.
        c����tj�}t|�}tj�j
|d���j
|tj�S)NTrW)	rr3rr	rLr?�
assertFailurer�BadFileError)rgrP�frs   �rr}zCUnixSocketTests.test_connectToUncleanServer.<locals>.ranStupidChild�sH������ �A�-�a�0�A�����
�
�q�4�@��%�%�a��);�);�<�<rr~rs` r�test_connectToUncleanServerz+UnixSocketTests.test_connectToUncleanServer�s���	=��&�&�~�6�6rc�D�����j�}tj||��d��d|�d�}�jt	��|��jt��|�t
j�j�}���fd�}|j|�|S)z~
        Test the C{__str__} and C{__repr__} implementations of a UNIX port when
        used with the given factory.
        �<� on �>c�~��d��d�}�jt��|��jt��|�y�Nr�z (not listening)>�r)�repr�str)rg�unconnectedString�factoryNamerrAs  ���rrhz3UnixSocketTests._reprTest.<locals>.stoppedListening�s=���"#�K�=�0A� B�����T�(�^�->�?����S��]�,=�>r)
r2r	r5r)r�r�r�
maybeDeferredr7r>)rr0r�r?�connectedStringrPrhrAs` `    @r�	_reprTestzUnixSocketTests._reprTest�s����
�;�;�=���%�%�h�
�>���k�]�$�x�l�!�<������h���9�����X���8����� 6� 6�7��	?�
	
�
�
�&�'��rc�p�Gd�d�}|j|t�|j|�d�S)a!
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIX.listenUNIX} contains the name of the new-style factory
        class being used and the filename on which the port is listening or
        indicates that the port is not listening.
        c��eZdZd�Zd�Zy)�EUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactoryc��yrr"�rs r�doStartzMUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactory.doStart����rc��yrr"r�s r�doStopzLUnixSocketTests.test_reprWithNewStyleFactory.<locals>.NewStyleFactory.doStop�r�rN)rr r!r�r�r"rr�NewStyleFactoryr�����
�
rr�z&twisted.test.test_unix.NewStyleFactory��assertIsInstance�typer�)rr�s  r�test_reprWithNewStyleFactoryz,UnixSocketTests.test_reprWithNewStyleFactory�s8��	�	�	
���o�t�4��~�~���G�
�	
r)rr r!�__doc__r�IReactorUNIXr	�skiprCrQrcrkryr�r�r�r�r"rrr%r%sO��
�#�:�"�"�7�D�1�B���2�>*�XF�.�"
7�
7��,
rr%c�0�eZdZdxZZdZd�Zd�Zd�Zd�Z	y)�ClientProtoFNc�h�tj�|_tj�|_yr)rr3�deferredStarted�deferredGotBackr�s rrzClientProto.__init__� ��$�~�~�/���$�~�~�/��rc��d|_y�NT��stoppedr�s r�stopProtocolzClientProto.stopProtocol	�	����rc�H�d|_|jjd�yr���startedr�rvr�s r�
startProtocolzClientProto.startProtocol���������%�%�d�+rc�H�||_|jjd�yr)�gotbackr�rv)r�datas  r�datagramReceivedzClientProto.datagramReceivedr�r)
rr r!r�r�r�rr�r�r�r"rrr�r�s%����G�g��G�0��,�,rr�c�4�eZdZdxZZdxZZd�Zd�Zd�Z	d�Z
y)�ServerProtoFNc�h�tj�|_tj�|_yr)rr3r��deferredGotWhatr�s rrzServerProto.__init__r�rc��d|_yr�r�r�s rr�zServerProto.stopProtocolr�rc�H�d|_|jjd�yr�r�r�s rr�zServerProto.startProtocol r�rc��||_|jjd|�||_|jjd�y)N�hi back)�gotfromr+�write�gotwhatr�rv)rr��addrs   rr�zServerProto.datagramReceived$s8����������Z��.�������%�%�d�+r)rr r!r�r�r�r�rr�r�r�r"rrr�r�s*����G�g���G�g�0��,�,rr�z3This reactor does not support UNIX datagram socketsc�(�eZdZdZd�Zd�Zd�Zd�Zy)�DatagramUnixSocketTestsz%
    Test datagram UNIX sockets.
    c������	��j���j�}t��	t��tj|�	�}�j|j�tj|����}�j|j�tj�	j�jg�}��	fd�}����	fd�}|j|�|j|�|S)zf
        Test that a datagram can be sent to and received by a server and vice
        versa.
        )�bindAddressc����jjd�tj�j�j
g�S)N�hi)r+r�rrMr�r�)r`�cp�sps ��rr�z4DatagramUnixSocketTests.test_exchange.<locals>.writeDs7����L�L���u�%��&�&��(:�(:�B�<N�<N�'O�P�Prc����jd�j��j��j��jd�j�y)Nr�r�)r)r�r�r�)r`�
clientaddrr�rr�s ����r�_cbTestExchangez>DatagramUnixSocketTests.test_exchange.<locals>._cbTestExchangeHs?������U�B�J�J�/����Z����4����Z����4r)r2r�r�r	�listenUNIXDatagramr6r7�connectUNIXDatagramrrMr�r>)
r�
serveraddr�s�crPr�r�r�r�r�s
`      @@@r�
test_exchangez%DatagramUnixSocketTests.test_exchange4s����
�[�[�]�
��[�[�]�
�
�]��
�]���&�&�z�2�6��������(��'�'�
�B�J�O��������(�����!3�!3�R�5G�5G� H�I��	Q�	5�
	
�
�
�e��	�
�
�o�&��rc��|j�}t�}tj||�}|j	t
jtj||�|j�tj|�y)z�
        L{IReactorUNIXDatagram.listenUNIXDatagram} raises
        L{error.CannotListenError} if the unix socket specified is already in
        use.
        N)
r2r�r	r�rirrjr7rn�unlink)rr�r|r�s    r�test_cannotListenz)DatagramUnixSocketTests.test_cannotListenQs^���{�{�}���M���&�&�t�Q�/�����%�1�1�7�3M�3M�t�UV�W�	����
�	�	�$�rc�D�����j�}tj||��d��d|�d�}�jt	��|��jt��|�t
j�j�}���fd�}|j|�|S)z�
        Test the C{__str__} and C{__repr__} implementations of a UNIX datagram
        port when used with the given protocol.
        r�r�r�c�~��d��d�}�jt��|��jt��|�yr�r�)rgr��protocolNamerrAs  ���rrhz;DatagramUnixSocketTests._reprTest.<locals>.stoppedListeningns=���"#�L�>�1B� C�����T�(�^�->�?����S��]�,=�>r)
r2r	r�r)r�r�rr�r7r>)r�serverProtor�r?r��stopDeferredrhrAs` `    @rr�z!DatagramUnixSocketTests._reprTest`s����
�;�;�=���-�-�h��D���l�^�4��|�1�=������h���9�����X���8��*�*�8�+A�+A�B��	?�
	� � �!1�2��rc�p�Gd�d�}|j|t�|j|�d�S)a2
        The two string representations of the L{IListeningPort} returned by
        L{IReactorUNIXDatagram.listenUNIXDatagram} contains the name of the
        new-style protocol class being used and the filename on which the port
        is listening or indicates that the port is not listening.
        c��eZdZd�Zd�Zy)�ODatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocolc��yrr")rr+s  r�makeConnectionz^DatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocol.makeConnectionr�rc��yrr"r�s rr�zVDatagramUnixSocketTests.test_reprWithNewStyleProtocol.<locals>.NewStyleProtocol.doStop�r�rN)rr r!r�r�r"rr�NewStyleProtocolr�~r�rr�z'twisted.test.test_unix.NewStyleProtocolr�)rr�s  r�test_reprWithNewStyleProtocolz5DatagramUnixSocketTests.test_reprWithNewStyleProtocolvs9��	�	�	
���.��5��~�~��� I�
�	
rN)rr r!r�r�r�r�r�r"rrr�r�+s��
��:��,
rr�)#r�rnr8rqrr�twisted.internetrrrrrr	r
�twisted.pythonr�twisted.python.compatr�twisted.python.filepathr
�twisted.test.test_tcprr�
twisted.trial�
ClientFactoryrr��TestCaser%�ConnectedDatagramProtocolr��DatagramProtocolr��IReactorUNIXDatagramr�r"rr�<module>r�s����

�
�
��X�X�X�#�/�,�B�"�$�H�$:�$:�$���
�����.�.�7��\
�h�'�'�\
�	�\
�~,�(�4�4�,�(,�(�+�+�,�,�'�
�'�'���6�6�9��[
�h�/�/�[
�	�[
r

Zerion Mini Shell 1.0