%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f.k�� �dZddlZddlmZddlmZmZmZmZm	Z	m
Z
ddlmZm
Z
mZddlmZddlmZGd�d	�ZGd
�deej(�ZGd�d
eej,�ZGd�de�ZGd�de�ZGd�dej(�Zeej8e	d�d�Gd�de��Zeej8e	d�d�Gd�de��Zeej>e	d�d�Gd�de��Z y)zG
Tests for implementations of L{IReactorUDP} and L{IReactorMulticast}.
�N)�skipIf)�defer�error�
interfaces�protocol�reactor�udp)�Deferred�
gatherResults�
maybeDeferred)�runtime)�TestCasec�*�eZdZdZdZdZd�Zd�Zd�Zy)�MixinrNc��g|_y�N)�packets��selfs �7/usr/lib/python3/dist-packages/twisted/test/test_udp.py�__init__zMixin.__init__s	�����c�v�d|_|j�&|jdc}|_|jd�yy�N�)�started�startedDeferred�callback�r�ds  r�
startProtocolzMixin.startProtocols;��������+�&*�&:�&:�D�#�A�t�#�
�J�J�t��,rc��d|_yr)�stoppedrs r�stopProtocolzMixin.stopProtocol"s	����r)	�__name__�
__module__�__qualname__rr#rrr!r$�rrrrs ���G��G��O���rrc��eZdZdZdZd�Zy)�ServerNrc��|jj||f�|j�&|jdc}|_|jd�yyr�r�append�packetReceivedr)r�data�addrr s    r�datagramReceivedzServer.datagramReceived*sJ�������T�4�L�)����*�%)�%8�%8�$�"�A�t�"�
�J�J�t��+r)r%r&r'r.�refusedr1r(rrr*r*&s���N��G�rr*c�&�eZdZdZdZd�Zd�Zd�Zy)�ClientNrc��|jj|�|j�&|jdc}|_|jd�yyrr,)rr/r s   rr1zClient.datagramReceived5sF�������D�!����*�%)�%8�%8�$�"�A�t�"�
�J�J�t��+rc�t�|j�%|jdc}|_|j|�||_yr)r�errback�failure)rr8r s   r�connectionFailedzClient.connectionFailed;s6�����+�&*�&:�&:�D�#�A�t�#�
�I�I�g����rc��|j�8|jdc}|_|jtjd��d|_y�N�yupr�rr7r�ConnectionRefusedErrorr2rs  r�connectionRefusedzClient.connectionRefusedA�A�����+�&*�&:�&:�D�#�A�t�#�
�I�I�e�2�2�5�9�:���r)r%r&r'r.r2r1r9r?r(rrr4r41s���N��G���rr4c��eZdZd�Zy)�
GoodClientc��|j�8|jdc}|_|jtjd��d|_yr;r=rs  rr?zGoodClient.connectionRefusedIr@rN)r%r&r'r?r(rrrBrBHs��rrBc��eZdZdZy)�BadClientErrorzf
    Raised by BadClient at the end of every datagramReceived call to try and
    screw stuff up.
    N)r%r&r'�__doc__r(rrrErEPs��rrEc� �eZdZdZdZd�Zd�Zy)�	BadClientz�
    A DatagramProtocol which always raises an exception from datagramReceived.
    Used to test error handling behavior in the reactor for that method.
    Nc��||_y)ze
        Set the Deferred which will be called back when datagramReceived is
        called.
        N)r rs  r�setDeferredzBadClient.setDeferred_s��
��rc�z�|j�%|jdc}|_|j|�td��)NzApplication code is very buggy!)r rrE)r�bytesr0r s    rr1zBadClient.datagramReceivedfs5���6�6������I�A�t�v�
�J�J�u���>�?�?r)r%r&r'rFr rJr1r(rrrHrHWs���
	
�A��@rrH�!This reactor does not support UDPc��eZdZd�Zd�Zd�Zd�Zd�Zee	jjd�dk(d�d	��Zd
�Z
d�Zd�Zd
�Zy)�UDPTestsc����t�}tj�x}|_t	j
d|d�����fd�}|j
|�S)zu
        The C{type} of the host address of a listening L{DatagramProtocol}'s
        transport is C{"UDP"}.
        r�	127.0.0.1��	interfacec�|���j�}�j|jd��j�S)N�UDP)�getHost�assertEqual�type�
stopListening)�ignoredr0�prs  ��r�	cbStartedz+UDPTests.test_oldAddress.<locals>.cbStartedxs/����9�9�;�D����T�Y�Y��.��?�?�$�$r�r*rr
rr�	listenUDP�addCallback)r�serverr r\r[s`   @r�test_oldAddresszUDPTests.test_oldAddressosJ���
���%*�^�^�%5�5��F�"����a��;�?��	%�
�}�}�Y�'�'rc������t��tj�x}�_t	j
d�d������fd�}��fd�}|j
|�j
|�S)z�
        The L{DatagramProtocol}'s C{startProtocol} and C{stopProtocol}
        methods are called when its transports starts and stops listening,
        respectively.
        rrQrRc����j�jd��j�jd��j�S)Nrr)rWrr#rY)rZ�port1rr`s ���rr\z*UDPTests.test_startStop.<locals>.cbStarted�s:������V�^�^�Q�/����V�^�^�Q�/��&�&�(�(rc�>���j�jd�yr)rWr#)rZrr`s ��r�	cbStoppedz*UDPTests.test_startStop.<locals>.cbStopped�s������V�^�^�Q�/rr])rr r\rfrdr`s`   @@r�test_startStopzUDPTests.test_startStopsZ������%*�^�^�%5�5��F�"��!�!�!�V�{�C��	)�
	0��}�}�Y�'�3�3�I�>�>rc����t��tj�x}�_t	j
d�d��}d����fd�}|j
�|�S)zr
        Re-listening with the same L{DatagramProtocol} re-invokes the
        C{startProtocol} callback.
        rrQrRc�"�|j�Sr�rY�rZ�ports  rr\z'UDPTests.test_rebind.<locals>.cbStarted�s���%�%�'�'rc���tj�x}�_tjd�d��}|j�|�S�NrrQrR)rr
rrr^r_)rZr r[r\r`s   ��rrfz'UDPTests.test_rebind.<locals>.cbStopped�s<���).���)9�9�A��&��!�!�!�V�{�C�A��=�=��A�.�.rr])rr r[rfr\r`s    @@r�test_rebindzUDPTests.test_rebind�sQ���
���%*�^�^�%5�5��F�"����a��;�?��	(�	/�
�}�}�Y��*�*rc������t��tj�x}�_t	j
d�d������fd�}|j
|��fd�}|j
|�|S)z�
        A L{CannotListenError} exception is raised when attempting to bind a
        second protocol instance to an already bound port
        rrQrRc����j�j��jj��t�}�j	t
jtj�j�j|d��y)NrQrR)
rWrV�	transportr*�assertRaisesr�CannotListenErrorrr^rl)rZ�server2rlrr`s  ���rr\z*UDPTests.test_bindError.<locals>.cbStarted�si������T�\�\�^�V�-=�-=�-E�-E�-G�H��h�G�����'�'��!�!�����#�#��%�
�
rc�$���j�Srrjrks �r�
cbFinishedz+UDPTests.test_bindError.<locals>.cbFinished�s����%�%�'�'rr])rr r\rwrlr`s`   @@r�test_bindErrorzUDPTests.test_bindError�s_���
���%*�^�^�%5�5��F�"�� � ��F�k�B��		�	
�
�
�i� �	(�	
�
�
�j�!��rc�����	�
�t��
tj�x}�
_t	j
d�
d���	t
��tj�x��_���fd�}|j|�}��
fd�}|j|����
fd�}|j|��	�fd�}|j|�|S)z�
        Datagrams can be sent with the transport's C{write} method and
        received via the C{datagramReceived} callback method.
        rrQrRc�B��tjd�d���_�Srn)rr^�port2)rZ�client�
clientStartedrs ���r�cbServerStartedz2UDPTests.test_sendPackets.<locals>.cbServerStarted�s��� �*�*�1�f��L�D�J� � rc������jjd�jj�j��jj�}�jj�}t	j
�x}�_�jjd|j|jf�ddd|j|jffg�����fd��t	j�d�|gd��S)	NrQ�hello)�a)�bN�cc����rVtj�x}�_|j���jj
�j
d��|Sy�Nr)rr
r.r_rr�write�pop)rZ�nextClientWrite�cbClientSendr|�clientWritesr`s  ����rr�zHUDPTests.test_sendPackets.<locals>.cbClientStarted.<locals>.cbClientSend�sT����>C�n�n�>N�N�O�f�&;�#�/�/��=�*�F�$�$�*�*�L�,<�,<�Q�,?�@�*�*�	 rT��fireOnOneErrback)
rr�connectrVrlrr
r.r��host�DeferredList)rZ�cAddr�sAddr�
serverSendr�r�r|r`s    @@��r�cbClientStartedz2UDPTests.test_sendPackets.<locals>.cbClientStarted�s�������$�$�[�&�2B�2B�2J�2J�2L�2Q�2Q�R��$�$�,�,�.�E��$�$�,�,�.�E�16���1A�A�J��.����"�"�8�e�j�j�%�*�*�-E�F�#�\�D�5�:�:�u�z�z�:R�3S�T�L�
+��%�%��d�#�Z�0�4��
rc�R���jj�}�jj�}�j�jd|j|j
ffg�|j|j
f}�j�jd|fd|fd|fg�y)Nr�r�r�r�)rrrVrWrr�rl)rZr�r��
clientAddrr|rr`s    ���r�cbSendsFinishedz2UDPTests.test_sendPackets.<locals>.cbSendsFinished�s�����$�$�,�,�.�E��$�$�,�,�.�E����V�^�^�x�%�*�*�e�j�j�9Q�.R�-S�T��*�*�e�j�j�1�J��������
�#�d�J�%7�$�
�9K�L�
rc���tjtj�j�tj�jj�gd��S�NTr�)rr�rrYr{)rZrdrs ��rrwz-UDPTests.test_sendPackets.<locals>.cbFinished�sL����%�%��'�'��(;�(;�<��'�'��
�
�(@�(@�A��"&��
r)r*rr
rrr^rBr_)r�
serverStartedr~r r�r�rwr|r}rdr`s`      @@@@r�test_sendPacketszUDPTests.test_sendPackets�s����
���16���1A�A�
��.��!�!�!�V�{�C�����16���1A�A�
��.�	!�
�%�%�o�6��	�0	
�
�
�o�&�	�	
�
�
�o�&�	�	
�
�
�j�!��r�INFRASTRUCTURE�AZUREPIPELINESz"Hangs on Pipelines due to firewallc������	�t��tj�x}�_t	j
d�d���t
��	tj�x}�	_t	j
d�	d���tj||gd��}���	fd�}|j|���fd�}|j|�|S)z�
        A L{ConnectionRefusedError} exception is raised when a connection
        attempt is actively refused by the other end.

        Note: This test assumes no one is listening on port 80 UDP.
        rrQrRTr�c�P��tj�x}�_�jj	dd�td�D]A}�jj
d|fz��jj
d|fzd��C�j|tj�S)NrQ�P�
�%d�rQr�)
rr
rrrr��ranger��
assertFailurerr>)rZr?�ir|rr`s   ���rr\z2UDPTests.test_connectionRefused.<locals>.cbStarteds����9>���9I�I��� 6����$�$�[�"�5��2�Y�
H��� � �&�&�u��t�|�4�� � �&�&�u��t�|�5F�G�
H��%�%�&7��9U�9U�V�Vrc���tjtj�j�tj�j�gd��Sr��rr�rrY)rZrlr{s ��rrwz3UDPTests.test_connectionRefused.<locals>.cbFinished'sH����%�%��'�'��(:�(:�;��'�'��(;�(;�<��"&��
r)	rBrr
rrr^r*r�r_)
rr}r�r r\rwr|rlr{r`s
`     @@@@r�test_connectionRefusedzUDPTests.test_connectionRefuseds�������16���1A�A�
��.�� � ��F�k�B�����16���1A�A�
��.��!�!�!�V�{�C�����
�}�=�PT�U��	W�	
�
�
�i� �	�	
�
�
�j�!��rc�4��	�
���
�t��	tj�x}�	_t	j
d�	d���
d�
t
��tj�x}�_tj�x}�_t	j
d�d���tj||gd��}�	���
fd�}|j|�tj||gd��}���
fd�}|j|��
�fd	�}|j|�|S)
as
        When a server fails to successfully read a packet the server should
        still be able to process future packets.
        The IOCP reactor had a historical problem where a failure to read caused
        the reactor to ignore any future reads. This test should prevent a regression.

        Note: This test assumes no one is listening on port 80 UDP.
        rrQrRsSending test packet to serverTr�c����jjdd��jj�d�jf�y)Ns$write to port no one is listening tor�rQ)rrr��_realPortNumber)rZr|r`�
serverPort�test_data_to_sends ����r�cbClientAndServerStartedzAUDPTests.test_serverReadFailure.<locals>.cbClientAndServerStartedJsE���
���"�"�7�9J�
�
���"�"�!�K��1K�1K�#L�
rc�J���j�jdd��yr��rWr)rZrr`r�s ���r�verify_server_got_dataz?UDPTests.test_serverReadFailure.<locals>.verify_server_got_data]s"������V�^�^�A�.�q�1�3D�Erc���tjtj�j�tj�j�gd��Sr�r�)rZ�
clientPortr�s ��r�cleanupz0UDPTests.test_serverReadFailure.<locals>.cleanupbsH����%�%��'�'�
�(@�(@�A��'�'�
�(@�(@�A��"&��
r)
rBrr
rrr^r*r.r�r_)rr}r��
serverGotData�server_client_started_dr��
all_data_sentr�r�r|r�r`r�r�s`        @@@@@r�test_serverReadFailurezUDPTests.test_serverReadFailure3s�������16���1A�A�
��.��&�&�q�&�K�H�
�<�����16���1A�A�
��.�05���0@�@�
��-��&�&�q�&�K�H�
�"'�"4�"4�
�M�*�T�#
��	�	 �+�+�,D�E��*�*�
$�m�4�t�
�
�	F�	�!�!�"8�9�	�	�!�!�'�*��rc�b�t�}tjd|d��}|jtj
|jjdd�|jjdd�|jt|jjdd�|j�S)a 
        A call to the transport's connect method fails with an
        L{InvalidAddressError} when a non-IP address is passed as the host
        value.

        A call to a transport's connect method fails with a L{RuntimeError}
        when the transport is already connected.
        rrQrR�	localhostr�)
rBrr^rsr�InvalidAddressErrorrrr��RuntimeErrorrY)rr|rls   r�test_badConnectzUDPTests.test_badConnectos������� � ��F�k�B������%�%�v�'7�'7�'?�'?��b�	
�	��� � ��b�1����,��(8�(8�(@�(@�+�r�R��!�!�#�#rc�J��������	�tj���fd�}�j|�t��t	j
d�d����fd�}�j
|��j��ttd���g�	�������	fd�����S)zr
        When datagramReceived raises an exception it is logged but the port
        is not disconnected.
        c����jt�}�jt|�ddt|�fz�y)z�
            Flush the exceptions which the reactor should have logged and make
            sure they're actually there.
            �z'Incorrectly found %d errors, expected 2N)�flushLoggedErrorsrErW�len)�ign�errsrs  �r�cbCompletedz8UDPTests.test_datagramReceivedError.<locals>.cbCompleted�s:���
�)�)�.�9�D�����D�	�1�G�3�t�9�,�V�
rrrQrRc�h���tj�j�j�fd��S)z�
            Disconnect the port we started and pass on whatever was given to us
            in case it was a Failure.
            c����Srr()r��results �r�<lambda>zHUDPTests.test_datagramReceivedError.<locals>.cbCleanup.<locals>.<lambda>�s���v�r)rrrY�addBoth)r�rls`�r�	cbCleanupz6UDPTests.test_datagramReceivedError.<locals>.cbCleanup�s(���
�&�&�t�'9�'9�:�B�B�CU�V�Vr�<c�^����s	�
jd��
j�jdd�d�jd�fz}t
j�}�j|��jj|�j�jf���	��fd�}�	fd�}|j||�|j�j�tjd|jt!j"d	���y#t$r�j�Y��wxYw)
a6
            Send one packet to the listening BadClient.  Set up a 0.1 second
            timeout to do re-transmits in case the packet is dropped.  When two
            packets have been received by the BadClient, stop sending and let
            the finalDeferred's callbacks do some assertions.
            zNot enough packets receivedNzUDP Protocol lost its transportr�rc����j��j|�t��dk(r"tjd�j
d�y��y)z�
                A packet arrived.  Cancel the timeout for it, record it, and
                maybe finish the test.
                r�rN)�cancelr-r�r�	callLaterr)�packet�
finalDeferred�makeAttempt�succeededAttempts�timeoutCalls ����r�cbPacketReceivedzRUDPTests.test_datagramReceivedError.<locals>.makeAttempt.<locals>.cbPacketReceived�sL���
�"�"�$�!�(�(��0��(�)�Q�.�
�%�%�a��)?�)?��F��Mrc�����y)a�
                The packet wasn't received quickly enough.  Try sending another
                one.  It doesn't matter if the packet for which this was the
                timeout eventually arrives: makeAttempt throws away the
                Deferred on which this function is the errback, so when
                datagramReceived callbacks, so it won't be on this Deferred, so
                it won't raise an AlreadyCalledError.
                Nr()�errr�s �r�ebPacketTimeoutzQUDPTests.test_datagramReceivedError.<locals>.makeAttempt.<locals>.ebPacketTimeout�s
����
rg�������?z&Timed out in testDatagramReceivedError)�fail�	Exceptionr7�failIfIdenticalrrr�rr
rJr�r�rl�addCallbacks�
addErrbackrr�r�TimeoutError)r��packetDeferredr�r�r�r0�attemptsr|r�r�rr�s    @�������rr�z8UDPTests.test_datagramReceivedError.<locals>.makeAttempt�s����,��I�I�;�<�
� � �� � �$�(I�
��h�l�l�1�o�/�/�F�"�^�^�-�N����~�.����"�"�6�D�I�I�t�y�y�+A�B�
"� 	
�
�'�'�(8�/�J��%�%�m�&;�&;�<�!�+�+���&�&��"�"�#K�L��K��U!�,�!�)�)�+�,�s�D�D,�+D,)
rr
r_rHrr^r�rV�listr�)
rr�r�r0r�r|r�r�rlr�s
`  @@@@@@@r�test_datagramReceivedErrorz#UDPTests.test_datagramReceivedError�s����
���(�
�	�	�!�!�+�.����� � ��F�k�B��	W�	���i�(��|�|�~����b�	�?����8	�8	�t	�
��rc��Gd�d�}tjdt��}|�|_|j	dd�|j|jg�}|jt|�d�y)ai
        C{'<broadcast>'} is an alternative way to say C{'255.255.255.255'}
        ({socket.gethostbyname("<broadcast>")} returns C{'255.255.255.255'}),
        so because it becomes a valid IP address, no deprecation warning about
        passing hostnames to L{twisted.internet.udp.Port.write} needs to be
        emitted by C{write()} in this case.
        c��eZdZd�Zy)�6UDPTests.test_NoWarningOnBroadcast.<locals>.fakeSocketc��yrr()r�foo�bars   r�sendtoz=UDPTests.test_NoWarningOnBroadcast.<locals>.fakeSocket.sendto�s��rN)r%r&r'r�r(rr�
fakeSocketr��s��
rr�rstest)z<broadcast>i�N)	r	�Portr*�socketr��
flushWarnings�test_NoWarningOnBroadcastrWr�)rr�r[�warningss    rr�z"UDPTests.test_NoWarningOnBroadcast�se��	�	�
�H�H�Q���!���<���	����.�/��%�%�t�'E�'E�&F�G������X���*rN)r%r&r'rargrorxr�r�os�environ�getr�r�r�r�r�r(rrrOrOmsh��(� ?�(+�&�8B�H�
�
�
���'�(�,<�<�,��'�	�'�R:�x$�$g�R+rrOc�L�eZdZdZej
ed�sdZd�Zd�Z	d�Z
y)�ReactorShutdownInteractionTestsz!Test reactor shutdown interactionNrMc�p�t�|_tjd|jd��|_y)zStart a UDP portrrQrRN)r*r`rr^rlrs r�setUpz%ReactorShutdownInteractionTests.setUps%���h����%�%�a�����L��	rc�6�|jj�S)zStop the UDP port)rlrYrs r�tearDownz(ReactorShutdownInteractionTests.tearDowns���y�y�&�&�(�(rc�~���tj��tj�x}�j_��fd�}|j	|��fd�}�j	|��jj
j
dd�jj
j�jf��S)z0Test reactor shutdown while in a recvfrom() loopc����jjj�tjd�j
d�yr�)r`rr�connectionLostrr�r)rZ�finishedrs ��r�pktRecezQReactorShutdownInteractionTests.testShutdownFromDatagramReceived.<locals>.pktReces3����K�K�!�!�0�0�2�
���a��!2�!2�D�9rc�&���j�yr)r��rZrs �r�flushErrorszUReactorShutdownInteractionTests.testShutdownFromDatagramReceived.<locals>.flushErrors(s���

�"�"�$rs@rQ)	rr
r`r.r_rrr�rVrl)r�prr�rr�s`   @r� testShutdownFromDatagramReceivedz@ReactorShutdownInteractionTests.testShutdownFromDatagramReceiveds�����>�>�#��*/�.�.�*:�:��T�[�[�
'�	:�	���w��	%�	���[�)������#�#���d�k�k�&;�&;�&C�&C�&E�&J�&J�K�	
��r)r%r&r'rFr�IReactorUDPr�skipr�r�rr(rrr�r��s,��+�!�:�!�!�'�4�0�2��M�
)�$rr��'This reactor does not support multicastc��eZdZejjd�dk(rejj�rdZ	e
jed�sdZ	d�Z
d�Zd�Zd	�Zd
�Zd�Zeejj)�xrejj+�d�d
��Zd�Zeejj)�d�d��Zy)�MulticastTestsr�r�z Does not work on Azure PipelinesNrc�x�t�|_t�|_t	j
d|j�|_t	j
d|j�|_|jjjd|jjj�j�y)NrrQ)r*r`r4r|r�listenMulticastrdr{rrr�rVrlrs rr�zMulticastTests.setUpDsw���h����h����,�,�Q����<��
��,�,�Q����<��
������%�%�k�4�;�;�3H�3H�3P�3P�3R�3W�3W�Xrc��tt|jj�t|jj�g�Sr)rrrdrYr{rs rr�zMulticastTests.tearDownLs8����d�j�j�6�6�7��d�j�j�6�6�7�
�
�	
rc��|j|jfD]q}|j|jj	�d�|jjd�|j|jj	�d��sy)Nrr�)r|r`rWrr�getTTL�setTTL)r�os  r�testTTLzMulticastTests.testTTLTsj�����d�k�k�)�	6�A����Q�[�[�/�/�1�1�5�
�K�K���q�!����Q�[�[�/�/�1�1�5�	6rc�����j�jjj�d��jjj	���jjjd�}��fd�}|j
|���fd�}|j
|��fd�}|j
|�|S)zv
        Test that after loopback mode has been set, multicast packets are
        delivered to their sender.
        r�225.0.0.250c���t�x}�j_�jjj	dd�j
f�|S)Nr�r�r
r`r.rrr�rl�rZr r0rs  ��r�cbJoinedz.MulticastTests.test_loopback.<locals>.cbJoinedcs>���-5�Z�7�A����*��K�K�!�!�'�'��=�$�)�)�2L�M��Hrc�����jt�jj�d��jjjd��j�jjj
�d��jjjdd�jf�t�}tjd|jd�|S)Nrrr�r)
rWr�r`rrr�setLoopbackMode�getLoopbackModer�rlr
rr�rrs  ��r�cbPacketz.MulticastTests.test_loopback.<locals>.cbPacketjs�������S����!4�!4�5�q�9��K�K�!�!�1�1�!�4����T�[�[�2�2�B�B�D�a�H��K�K�!�!�'�'��=�$�)�)�2L�M��
�A����a����T�2��Hrc�d���jt�jj�d�yr)rWr�r`rrs �r�
cbNoPacketz0MulticastTests.test_loopback.<locals>.cbNoPacketws"������S����!4�!4�5�q�9r)rWr`rrrrV�	joinGroupr_)r�joinedrrrr0s`    @r�
test_loopbackzMulticastTests.test_loopbackZs����
	
������.�.�>�>�@�!�D��{�{�$�$�,�,�.�����&�&�0�0��?��	�
	���8�$�		�	���8�$�	:�	���:�&��
rc����j�jjj�d��j�jjj�d��jjjd�}�jjjd�}t
||g�}�fd�}|j|�|S)zK
        Test C{getOutgoingInterface} and C{setOutgoingInterface}.
        z0.0.0.0rQc�����j�jjj�d��j�jjj�d�y)NrQ)rWr|rr�getOutgoingInterfacer`rs �r�cbInterfacesz3MulticastTests.test_interface.<locals>.cbInterfaces�sI������T�[�[�2�2�G�G�I�;�W����T�[�[�2�2�G�G�I�;�Wr)rWr|rrr"r`�setOutgoingInterfacerr_)r�d1�d2r�r#s`    r�test_interfacezMulticastTests.test_interface~s����	
������.�.�C�C�E�y�Q�������.�.�C�C�E�y�Q�
�[�[�
"�
"�
7�
7��
D��
�[�[�
"�
"�
7�
7��
D����B�x�(��	X�	���<�(��
rc�����jjjd�}�fd�}|j|��fd�}|j|��fd�}|j|�|S)zE
        Test that multicast a group can be joined and left.
        rc�N���jjjd�S�Nr)r|rr�
leaveGrouprs �r�clientJoinedz3MulticastTests.test_joinLeave.<locals>.clientJoined������;�;�(�(�3�3�M�B�Brc�N���jjjd�Sr*)r`rrrrs �r�
clientLeftz1MulticastTests.test_joinLeave.<locals>.clientLeft�s����;�;�(�(�2�2�=�A�Arc�N���jjjd�Sr*)r`rrr+rs �r�serverJoinedz3MulticastTests.test_joinLeave.<locals>.serverJoined�r-r)r|rrrr_)rr r,r/r1s`    r�test_joinLeavezMulticastTests.test_joinLeave�s`���
�K�K�!�!�+�+�M�:��	C�	
�
�
�l�#�	B�	
�
�
�j�!�	C�	
�
�
�l�#��rz2Windows' UDP multicast is not yet fully supported.c��|j|jjjd�tj
�S)z�
        Test that an attempt to join an address which is not a multicast
        address fails with L{error.MulticastJoinError}.
        rQ)r�r|rrrr�MulticastJoinErrorrs r�test_joinFailurezMulticastTests.test_joinFailure�s7���!�!��K�K�!�!�+�+�K�8�%�:R�:R�
�	
rc�h�����t��tjd����jjj���jjj
d�}���fd�}|j|��fd�}|j|��fd�}|j|�|S)zn
        Test that a multicast group can be joined and messages sent to and
        received from it.
        rrc���t�x}�j_�jj	dd�j
f�|S)N�hello worldrr)rZr r0�crs  ���rrz/MulticastTests.test_multicast.<locals>.cbJoined�s8���-5�Z�7�A����*�
�K�K���n�}�d�i�i�.H�I��Hrc�^���j�jjddd�y�Nrr8)rWr`rrs �rrz/MulticastTests.test_multicast.<locals>.cbPacket�s'������T�[�[�0�0��3�A�6��Grc�\���t�j�}|j�fd��|S)Nc����Srr(�r��passthroughs �rr�z@MulticastTests.test_multicast.<locals>.cleanup.<locals>.<lambda>�����;�r)rrYr_)r?r�r[s` �rr�z.MulticastTests.test_multicast.<locals>.cleanup�s%���"�1�?�?�3�F����6�7��Mr)r*rr
r`rrrVrr_)rrrrr�r0r9r[s`    @@@r�test_multicastzMulticastTests.test_multicast�s����

�H���#�#�A�q�)���{�{�$�$�,�,�.�����&�&�0�0��?��	�
	���8�$�	H�	���8�$�	�
	���7�#��
rzjon non-linux platforms it appears multiple processes can listen, but not multiple sockets in same process?c�������	�
�t��tjd�d����j�j�t��tj��d���	d�
t�jjj�
��j�
��	j�
�g�}����
fd�}|j|����fd�}|j|���	fd�}|j|�|S)z�
        Test that multiple sockets can listen on the same multicast port and
        that they both receive multicast messages directed to that address.
        rT)�listenMultiplerc���t�x}�_t�x}�_�jjd��f�t	||g�S)Nr8)r
r.rrr�r)rZr%r&�firstClient�portno�secondClient�theGroups   ����rr1z5MulticastTests.test_multiListen.<locals>.serverJoined�sK���.6�j�8�B��+�/7�z�9�B��,��!�!�'�'���6�8J�K� �"�b��*�*rc����j�jddd��j�jddd�yr;r�)rZrErGrs ���r�
gotPacketsz3MulticastTests.test_multiListen.<locals>.gotPackets�sC������[�0�0��3�A�6��G����\�1�1�!�4�Q�7��Hrc����tt�j�t�j�g�}|j�fd��|S)Nc����Srr(r>s �rr�zBMulticastTests.test_multiListen.<locals>.cleanup.<locals>.<lambda>r@r)rrrYr_)r?r��	firstPort�
secondPorts` ��rr�z0MulticastTests.test_multiListen.<locals>.cleanupsD���"�!�)�"9�"9�:�!�*�":�":�;���F�
���6�7��Mr)r*rr
rVrlrr`rrrr_r�)rrr1rJr�rErMrFrGrNrHs`    @@@@@@r�test_multiListenzMulticastTests.test_multiListen�s�����h���+�+�A�{�4�P�	��"�"�$�)�)���x���,�,�V�\�RV�W�
� ������%�%�/�/��9��#�#�H�-��$�$�X�.�
�
��	+�	���<�(�	I�	���:�&�	�	���w���
r)r%r&r'r�r�r�r
�platform�isMacOSXrr�IReactorMulticastrr�r�rrr'r2r�	isWindows�isVistar5rArOr(rrrr6s���	�
�
���'�(�,<�<����%�%�'�1��'�:�'�'���6�8��Y�
�6�"�H�$�0����"�"�$�G�W�-=�-=�-E�-E�-G�)G�<��
�	�
��@����"�"�$�	��/�
�/rr)!rFr��unittestr�twisted.internetrrrrrr	�twisted.internet.deferr
rr�twisted.pythonr
�twisted.trial.unittestrr�DatagramProtocolr*�ConnectedDatagramProtocolr4rBr�rErHrrOr�rRrr(rr�<module>r\s0��
�

��M�M�I�I�"�+���&�U�H�-�-���U�H�6�6��.����Y��@��)�)�@�,�"�J�"�"�7�D�1�1�3V�W�N+�x�N+�X�N+�b�"�J�"�"�7�D�1�1�3V�W�3�h�3�X�3�l�$�
�$�$�W�d�3�3�-��Q�X�Q�	�Qr

Zerion Mini Shell 1.0