%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f���	�z�UdZddlZddlZddlZddlmZddlmZmZm	Z	m
Z
mZmZm
Z
ddlmZddlmZddlmZddlmZdd	lmZmZeeed
<	ed�dZdd
lmZmZddl m!Z!ddl"m#Z#ddl$m%Z%m&Z&m'Z'ddl(m)Z)m*Z*m+Z+ddl,m-Z-ddl.m/Z/ddl0m1Z1ddl2m3Z3ddl4m5Z5ddl6m7Z7ddl8m9Z9m:Z:m;Z;ddlm<Z<ddl=m>Z>m?Z?e@ZAeZBes'ddlCmDZDmEZEmFZFmGZGmHZHmIZImJZJmKZKddlLmMZMmNZNmOZOmPZPmQZQmBZBmAZAneZRee'�Gd�d��ZSe!e'eS��Gd�d e-eS�ZTGd!�d"�ZUGd#�d$�ZVGd%�d&e?�ZWGd'�d(�ZXGd)�d*�ZYGd+�d,eYeXe?�ZZe[eZd-eVeZj�eZj�d.�/��Gd0�d1eYeXe?�Z^e[e^d-eVeZj�eZj�d2�/��Gd3�d4eYeXe?�Z_e[e_d-eUe_j�e_j���eeB�Gd5�d6eA��Z`Gd7�d8�ZaGd9�d:eaeXe?�ZbGd;�d<eaeXe?�ZcGd=�d>e?�ZdGd?�d@�ZeGdA�dBe?�ZfGdC�dDe?�Zgee3�GdE�dFe)��ZhGdG�dHeee?�ZiGdI�dJe/�ZjGdK�dLeee?�ZkGdM�dN�ZlGdO�dPele?eY�ZmGdQ�dRele?ea�Zny#eef$rdZY��^wxYw)Sz#
Tests for L{twisted.pair.tuntap}.
�N)�deque)�EAGAIN�EBADF�EINVAL�ENODEV�ENOENT�EPERM�EWOULDBLOCK)�cycle)�	randrange)�SIGINT)�Optional)�ObjectNotFound�namedAny�platformSkipzfcntl.ioctlz'Platform is missing fcntl/ioctl support)�	Interface�implementer)�verifyObject)�CannotListenError)�IAddress�IListeningPort�
IReactorFDSet)�AbstractDatagramProtocol�DatagramProtocol�Factory)�Clock)�EthernetProtocol)�
IPProtocol)�IRawPacketProtocol)�RawUDPProtocol)�	iterbytes)�addObserver�removeObserver�textFromEventDict)�fullyQualifiedName)�SkipTest�SynchronousTestCase)�_H�_PI_SIZE�MemoryIOSystem�Tunnel�	_ethernet�_ip�_IPv4�_udp)�	_IFNAMSIZ�
_TUNSETIFF�
TunnelAddress�TunnelFlags�
TuntapPort�_IInputOutputSystem�_RealSystemc�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�ReactorFDSeta6
    An implementation of L{IReactorFDSet} which only keeps track of which
    descriptors have been registered for reading and writing.

    This implementation isn't actually capable of determining readability or
    writeability and generates no events for the descriptors registered with
    it.

    @ivar _readers: A L{set} of L{IReadDescriptor} providers which the reactor
        is supposedly monitoring for read events.

    @ivar _writers: A L{set} of L{IWriteDescriptor} providers which the reactor
        is supposedly monitoring for write events.
    c��t�|_t�|_|jj|_|jj|_y�N)�set�_readers�_writers�add�	addReader�	addWriter��selfs �?/usr/lib/python3/dist-packages/twisted/pair/test/test_tuntap.py�__init__zReactorFDSet.__init__cs6�����
����
����*�*������*�*���c�:�|jj|�yr:)r<�discard)rB�readers  rC�removeReaderzReactorFDSet.removeReaderi����
�
���f�%rEc�:�|jj|�yr:)r=rG)rB�writers  rC�removeWriterzReactorFDSet.removeWriterlrJrEc�,�t|j�Sr:)�iterr<rAs rC�
getReaderszReactorFDSet.getReaderso����D�M�M�"�"rEc�,�t|j�Sr:)rOr=rAs rC�
getWriterszReactorFDSet.getWritersrrQrEc���	t|j|jz�t�|_t�|_S#t�|_t�|_wxYwr:)�listr<r=r;rAs rC�	removeAllzReactorFDSet.removeAllusD��	"���
�
��
�
�5�6��E�D�M��E�D�M�� �E�D�M��E�D�M�s�!A� A"N)
�__name__�
__module__�__qualname__�__doc__rDrIrMrPrSrV�rErCr8r8Rs%��
�+�&�&�#�#�"rEr8c��eZdZdZd�Zy)�
FSSetClockzI
    An L{FSSetClock} is a L{IReactorFDSet} and an L{IReactorClock}.
    c�X�tj|�tj|�yr:)rrDr8rAs rCrDzFSSetClock.__init__�s��
���t�����d�#rEN)rWrXrYrZrDr[rErCr]r]�s���$rEr]c�2�eZdZdZed��Zd�Zd�Zd�Zy)�	TunHelperzM
    A helper for tests of tun-related functionality (ip-level tunnels).
    c�D�tjtjzSr:)r3�IFF_TUN�	IFF_NO_PIrAs rC�TUNNEL_TYPEzTunHelper.TUNNEL_TYPE�s���"�"�[�%:�%:�:�:rEc� �||_||_y)aw
        @param tunnelRemote: The source address for UDP datagrams originated
            from this helper.  This is an IPv4 dotted-quad string.
        @type tunnelRemote: L{bytes}

        @param tunnelLocal: The destination address for UDP datagrams
            originated from this helper.  This is an IPv4 dotted-quad string.
        @type tunnelLocal: L{bytes}
        N)�tunnelRemote�tunnelLocal)rBrfrgs   rCrDzTunHelper.__init__�s��)���&��rEc	�^�t|j|jt|||����S)a
        Construct an ip datagram containing a udp datagram containing the given
        application-level payload.

        @param source: The source port for the UDP datagram being encapsulated.
        @type source: L{int}

        @param destination: The destination port for the UDP datagram being
            encapsulated.
        @type destination: L{int}

        @param payload: The application data to include in the udp datagram.
        @type payload: L{bytes}

        @return: An ethernet frame.
        @rtype: L{bytes}
        )�src�dst�payload)r-rfrgr/)rB�source�destinationrks    rC�encapsulatezTunHelper.encapsulate�s/��$��!�!�� � ��V��g�F�
�	
rEc����g�t�}�fd�}||_t�}|jd|�t	���jd|���fd�}|S)a�
        Get a function for parsing a datagram read from a I{tun} device.

        @return: A function which accepts a datagram exactly as might be read
            from a I{tun} device.  The datagram is expected to ultimately carry
            a UDP datagram.  When called, it returns a L{list} of L{tuple}s.
            Each tuple has the UDP application data as the first element and
            the sender address as the second element.
        c�(���j|�yr:��append��args�	datagramss �rC�capturez!TunHelper.parser.<locals>.capture��������T�"rE�90�c�2���j|dddd��S)NF)�datagramReceived)�dataru�ips ��rC�parsezTunHelper.parser.<locals>.parse�s!���
����e�T�4��>��rE)rr{r �addProtor)rB�receiverrv�udpr~rur}s     @@rC�parserzTunHelper.parser�sX����	�#�%��	#�%,��!�������U�H�%�
�\��
���B���	��rEN�	rWrXrYrZ�propertyrdrDrnr�r[rErCr`r`�s*����;��;�'�
�0rEr`c�2�eZdZdZed��Zd�Zd�Zd�Zy)�	TapHelperzS
    A helper for tests of tap-related functionality (ethernet-level tunnels).
    c�d�tj}|js|tjz}|Sr:)r3�IFF_TAP�pirc)rB�flags  rCrdzTapHelper.TUNNEL_TYPE�s)���"�"���w�w��K�)�)�)�D��rEc�.�||_||_||_y)a
        @param tunnelRemote: The source address for UDP datagrams originated
            from this helper.  This is an IPv4 dotted-quad string.
        @type tunnelRemote: L{bytes}

        @param tunnelLocal: The destination address for UDP datagrams
            originated from this helper.  This is an IPv4 dotted-quad string.
        @type tunnelLocal: L{bytes}

        @param pi: A flag indicating whether this helper will generate and
            consume a protocol information (PI) header.
        @type pi: L{bool}
        N)rfrgr�)rBrfrgr�s    rCrDzTapHelper.__init__�s��)���&�����rEc���t|j|j�}|j|||�}t	ddt
|��}|jr"t
}d}t|�t|�z|z}|S)a<
        Construct an ethernet frame containing an ip datagram containing a udp
        datagram containing the given application-level payload.

        @param source: The source port for the UDP datagram being encapsulated.
        @type source: L{int}

        @param destination: The destination port for the UDP datagram being
            encapsulated.
        @type destination: L{int}

        @param payload: The application data to include in the udp datagram.
        @type payload: L{bytes}

        @return: An ethernet frame.
        @rtype: L{bytes}
        ss������)rirj�protocolrkr)r`rfrgrnr,r.r�r()	rBrlrmrk�tunr}�framer��flagss	         rCrnzTapHelper.encapsulate�ss��$��)�)�4�+;�+;�<��
�_�_�V�[�'�
:���+�+���	
���7�7��H��E��u�I��8��,�u�4�E��rEc������g�t�}�fd�}||_t�}|jd|�t	�}|jd|�t���jd|����fd�}|S)a�
        Get a function for parsing a datagram read from a I{tap} device.

        @return: A function which accepts a datagram exactly as might be read
            from a I{tap} device.  The datagram is expected to ultimately carry
            a UDP datagram.  When called, it returns a L{list} of L{tuple}s.
            Each tuple has the UDP application data as the first element and
            the sender address as the second element.
        c�(���j|�yr:rqrss �rCrvz!TapHelper.parser.<locals>.capture'rwrErxryic�T���jr	|td}�j|��Sr:)r�r)r{)�datagramru�etherrBs ���rCr�z TapHelper.parser.<locals>.parser5s.����w�w�#�H�I�.��
�"�"�8�,��rE)rr{r rrr)rBr�rvr�r}r�rur�s`     @@rCr�zTapHelper.parsersn����	�#�%��	#�%,��!�������U�H�%�
�\��
���B��� �"��
���u�b�!�		��
rENr�r[rErCr�r��s+��������$ �D&rEr�c��eZdZdZd�Zy)�TunnelTestszs
    L{Tunnel} is mostly tested by other test cases but some tests don't fit
    there.  Those tests are here.
    c��tt�tjd�}|j	t
|jd�y)z�
        Blocking reads are not implemented by L{Tunnel.read}.  Attempting one
        results in L{NotImplementedError} being raised.
        N�)r+r*�os�O_RDONLY�assertRaises�NotImplementedError�read�rB�tunnels  rC�test_blockingReadzTunnelTests.test_blockingReadIs0��
��(�"�+�+�t�<�����-�v�{�{�D�ArEN)rWrXrYrZr�r[rErCr�r�Cs
���
BrEr�c�L�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
y)
�TunnelDeviceTestsMixinzZ
    A mixin defining tests that apply to L{_IInputOutputSystem}
    implementations.
    c��|j�|_|jjdtjtj
z�|_|j|jj|j�|jj}tjdtfz|j|j�}|jj!|jt"|�y)zk
        Create the L{_IInputOutputSystem} provider under test and open a tunnel
        using it.
        �/dev/net/tunz%dsHN)�createSystem�system�openr��O_RDWR�
O_NONBLOCK�fileno�
addCleanup�close�helperrd�struct�packr0�_TUNNEL_DEVICE�value�ioctlr1)rB�mode�configs   rC�setUpzTunnelDeviceTestsMixin.setUpXs���
�'�'�)����k�k�&�&���	�	�B�M�M�8Q�R���������)�)�4�;�;�7��{�{�&�&�����V�y�l�2�D�4G�4G����T�������$�+�+�z�6�:rEc�V�|jtt|j��y)zH
        The object under test provides L{_IInputOutputSystem}.
        N)�
assertTruerr5r�rAs rC�test_interfacez%TunnelDeviceTestsMixin.test_interfacees��	
����%8�$�+�+�F�GrEc��|jjdtj�}|jj	|�|S)a@
        Get an invalid file descriptor.

        @return: An integer which is not a valid file descriptor at the time of
            this call.  After any future system call which allocates a new file
            descriptor, there is no guarantee the returned file descriptor will
            still be invalid.
        r�)r�r�r�r�r�)rB�fds  rC�_invalidFileDescriptorz-TunnelDeviceTestsMixin._invalidFileDescriptorks5���[�[�
�
�o�r�y�y�
9�������"���	rEc��|j�}|jt|jj|d�}|jt|j�y)z�
        The device's C{read} implementation raises L{OSError} with an errno of
        C{EBADF} when called on a file descriptor which is not valid (ie, which
        has no associated file description).
        r�N)r�r��OSErrorr�r��assertEqualr�errno�rBr��excs   rC�test_readEBADFz%TunnelDeviceTestsMixin.test_readEBADFxsF���
(�
(�
*���������)9�)9�2�t�D�������	�	�*rEc��|j�}|jt|jj|d�}|jt|j�y)z�
        The device's C{write} implementation raises L{OSError} with an errno of
        C{EBADF} when called on a file descriptor which is not valid (ie, which
        has no associated file description).
        sbytesN)r�r�r�r��writer�rr�r�s   rC�test_writeEBADFz&TunnelDeviceTestsMixin.test_writeEBADF�sF���
(�
(�
*���������):�):�B��I�������	�	�*rEc��|j�}|jt|jj|�}|jt|j�y)z�
        The device's C{close} implementation raises L{OSError} with an errno of
        C{EBADF} when called on a file descriptor which is not valid (ie, which
        has no associated file description).
        N)r�r�r�r�r�r�rr�r�s   rC�test_closeEBADFz&TunnelDeviceTestsMixin.test_closeEBADF�sD���
(�
(�
*���������):�):�B�?�������	�	�*rEc���|j�}|jt|jj|t
d�}|j
t|j�y)z�
        The device's C{ioctl} implementation raises L{OSError} with an errno of
        C{EBADF} when called on a file descriptor which is not valid (ie, which
        has no associated file description).
        stap0N)	r�r��IOErrorr�r�r1r�rr�r�s   rC�test_ioctlEBADFz&TunnelDeviceTestsMixin.test_ioctlEBADF�sH���
(�
(�
*���������):�):�B�
�G�T�������	�	�*rEc��d}|jt|jj|j|d�}|jt|j�y)z�
        The device's C{ioctl} implementation raises L{IOError} with an errno of
        C{EINVAL} when called with a request (second argument) which is not a
        supported operation.
        l�>[=sgarbageN)r�r�r�r�r�r�rr�)rB�requestr�s   rC�test_ioctlEINVALz'TunnelDeviceTestsMixin.test_ioctlEINVAL�sH��������T�[�[�&�&����W�j�
��	
�������+rEc��|jj�}d}td�D]�}td�}d|fz}|jj||jdf�}td�D]@}	|jj|jd�}||�}	||f|	vrd}n|	dd�=�B|s��n|s|jd	�yy#t$r$}
|
jttfvrYd}
~
�B�d}
~
wwxYw)
z�
        If a UDP datagram is sent to an address reachable by the tunnel device
        then it can be read out of the tunnel device.
        F�d��hello world:%drxr�TNz$Never saw probe UDP packet on tunnel)r�r��rangerr��sendUDP�_TUNNEL_REMOTEr�r�r�r�rr
�fail)rBr~�found�i�key�messagerl�j�packetru�es           rC�test_receivez#TunnelDeviceTestsMixin.test_receive�s
��
���"�"�$�����s��	�A��E�"�C�'�3�&�0�G��[�[�(�(��4�3F�3F��2N�O�F�
�3�Z�
%��%�!�[�[�-�-�d�k�k�4�@�F�!&�f�
�I���(�I�5� $���!�!��
%���-	�0��I�I�<�=������w�w�6�;�"7�7�����s�3&C
�
	C:�C5�4C5�5C:c���td�}d|fz}|jtjtj��tjd�|j
j
|j|jd�}|jjdd|�}|j
j|j|�|jd�}|j||�y)z�
        If a UDP datagram is written the tunnel device then it is received by
        the network to which it is addressed.
        r�r��xrxiP�r�N)rr��socket�setdefaulttimeout�getdefaulttimeoutr��
receiveUDPr��
_TUNNEL_LOCALr�rnr��recvr�)rBr�r��portr�s     rC�	test_sendz TunnelDeviceTestsMixin.test_send�s�������#�s�f�,��	
����0�0�&�2J�2J�2L�M�� � ��%��{�{�%�%�d�k�k�4�3E�3E�u�M�����(�(���w�?��	
�����$�+�+�v�.����4�������&�)rEN)rWrXrYrZr�r�r�r�r�r�r�r�r�r�r[rErCr�r�Rs;���
;�H��+�+�+�+�,�$>�L$*rEr�c�"�eZdZdZdZdZdZd�Zy)�FakeDeviceTestsMixinz�
    Define a mixin for use with test cases that require an
    L{_IInputOutputSystem} provider.  This mixin hands out L{MemoryIOSystem}
    instances as the provider of that interface.
    stap-twistedtests
172.16.2.1s
172.16.2.2c�b�t�}|jtjt�|S)z�
        Create and return a brand new L{MemoryIOSystem}.

        The L{MemoryIOSystem} knows how to open new tunnel devices.

        @return: The newly created I/O system object.
        @rtype: L{MemoryIOSystem}
        )r*�registerSpecialDevicer+�_DEVICE_NAME�rBr�s  rCr�z!FakeDeviceTestsMixin.createSystems'�� �!���$�$�V�%8�%8�&�A��
rEN)rWrXrYrZr�r�r�r�r[rErCr�r��s���(�N�!�M�"�N�rEr�c��eZdZdZy)�FakeTapDeviceTestszQ
    Run various tap-type tunnel unit tests against an in-memory I/O system.
    N�rWrXrYrZr[rErCr�r����rEr�r�F�r�c��eZdZdZy)�FakeTapDeviceWithPITestszp
    Run various tap-type tunnel unit tests against an in-memory I/O system with
    the PI header enabled.
    Nr�r[rErCr�r�%s��rEr�Tc��eZdZdZy)�FakeTunDeviceTestszQ
    Run various tun-type tunnel unit tests against an in-memory I/O system.
    Nr�r[rErCr�r�7r�rEr�c�8��eZdZdZ�fd�Z�fd�Zd�Zd�Z�xZS)�TestRealSystemz�
    Add extra skipping logic so tests that try to create real tunnel devices on
    platforms where those are not supported automatically get skipped.
    c���	t�|�|g|��i|��S#t$r.}|jtt
fvr|dk(rt
d���d}~wwxYw)z�
        Attempt an open, but if the file is /dev/net/tun and it does not exist,
        translate the error into L{SkipTest} so that tests that require
        platform support for tuntap devices are skipped instead of failed.
        r�zPlatform lacks /dev/net/tunN)�superr�r�r�rrr&)rB�filenamert�kwargsr��	__class__s     �rCr�zTestRealSystem.openMsZ���	��7�<��:�4�:�6�:�:���	��w�w�6�6�*�*�x�?�/J��<�=�=���	�s��	A
�)A�A
c���	t�|�|i|��S#t$r$}t|jk(rtd���d}~wwxYw)z�
        Attempt an ioctl, but translate permission denied errors into
        L{SkipTest} so that tests that require elevated system privileges and
        do not have them are skipped instead of failed.
        z%Permission to configure device deniedN)r�r�r�r	r�r&)rBrtr�r�r�s    �rCr�zTestRealSystem.ioctl\sG���	��7�=�$�1�&�1�1���	�������F�G�G���	�s��	?�:�?c���tjtjtj�}|jd�|j	||�|j�S)a�
        Use the platform network stack to send a datagram to the given address.

        @param datagram: A UDP datagram payload to send.
        @type datagram: L{bytes}

        @param address: The destination to which to send the datagram.
        @type address: L{tuple} of (L{bytes}, L{int})

        @return: The address from which the UDP datagram was sent.
        @rtype: L{tuple} of (L{bytes}, L{int})
        )z
172.16.0.1r)r��AF_INET�
SOCK_DGRAM�bind�sendto�getsockname)rBr��address�ss    rCr�zTestRealSystem.sendUDPisE��
�M�M�&�.�.�&�*;�*;�<��	��� �!�	����7�#��}�}��rEc��tjtjtj�}|j||f�|S)a�
        Use the platform network stack to receive a datagram sent to the given
        address.

        @param fileno: The file descriptor of the tunnel used to send the
            datagram.  This is ignored because a real socket is used to receive
            the datagram.
        @type fileno: L{int}

        @param host: The IPv4 address at which the datagram will be received.
        @type host: L{bytes}

        @param port: The UDP port number at which the datagram will be
            received.
        @type port: L{int}

        @return: A L{socket.socket} which can be used to receive the specified
            datagram.
        )r�rrr)rBr��hostr�rs     rCr�zTestRealSystem.receiveUDP{s3��(
�M�M�&�.�.�&�*;�*;�<��	����d�|���rE)	rWrXrYrZr�r�r�r��
__classcell__)r�s@rCr�r�Fs����

���$rEr�c��eZdZdZeZd�Zy)�RealDeviceTestsMixinz�
    Define a mixin for use with test cases that require an
    L{_IInputOutputSystem} provider.  This mixin hands out L{TestRealSystem}
    instances as the provider of that interface.
    c��t�S)z�
        Create a real I/O system that can be used to open real tunnel device
        provided by the underlying system and previously configured.

        @return: The newly created I/O system object.
        @rtype: L{TestRealSystem}
        )r�rAs rCr�z!RealDeviceTestsMixin.createSystem�s
����rEN)rWrXrYrZr�skipr�r[rErCrr�s����D� rErc�2�eZdZdZdZdZdZeeed��Zy)�&RealDeviceWithProtocolInformationTestsz|
    Run various tap-type tunnel unit tests, with "protocol information" (PI)
    turned on, against a real I/O system.
    s
tap-twtest-pis
172.16.1.1s
172.16.1.2Tr�N�	rWrXrYrZr�r�r�r�r�r[rErCrr�s(���
&�N�!�M�"�N��~�}��
>�FrErc�2�eZdZdZdZdZdZeeed��Zy)�)RealDeviceWithoutProtocolInformationTestsz}
    Run various tap-type tunnel unit tests, with "protocol information" (PI)
    turned off, against a real I/O system.
    s
tap-twtests
172.16.0.1s
172.16.0.2Fr�Nrr[rErCrr�s&���
#�N�!�M�"�N�
�~�}��
?�FrErc��eZdZdZd�Zd�Zy)�TuntapPortTestszR
    Tests for L{TuntapPort} behavior that is independent of the tunnel type.
    c�j�tdt��}|jtt|��y)zF
        A L{TuntapPort} instance provides L{IListeningPort}.
        �deviceN)r4rr�rr�rBr�s  rCr�zTuntapPortTests.test_interface�s'���)�%5�%7�8������^�T�:�;rEc�l�tdt��}|j|jt�y)zg
        When not initialized with an I/O system, L{TuntapPort} uses a
        L{_RealSystem}.
        rN)r4r�assertIsInstance�_systemr6rs  rC�test_realSystemzTuntapPortTests.test_realSystem�s(��
�)�%5�%7�8�����d�l�l�K�8rEN)rWrXrYrZr�rr[rErCrr�s���<�9rErc���eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d �Z"d!�Z#d"�Z$d#�Z%d$�Z&y%)&�TunnelTestsMixinz�
    A mixin defining tests for L{TuntapPort}.

    These tests run against L{MemoryIOSystem} (proven equivalent to the real
    thing by the tests above) to avoid performing any real I/O.
    c��d|_t�|_|jjtj
t�|jjt|jj|j��|_t�|_
t|j|j|j|j��|_y)zW
        Create an in-memory I/O system and set up a L{TuntapPort} against it.
        �tun0)�reactorr�N)�namer*r�r�r+r��factory�
buildProtocolr2r�rdr�r]r!r4r�rAs rCr�zTunnelTestsMixin.setUp�s�����	�$�&������)�)�&�*=�*=�v�F����2�2��$�+�+�1�1�4�9�9�=�
��
�"�|�����I�I�t�}�}�d�l�l�4�;�;�
��	rEc�J�|tjtjzzS)a/
        Mask off any flags except for L{TunnelType.IFF_TUN} and
        L{TunnelType.IFF_TAP}.

        @param flags: Flags from L{TunnelType} to mask.
        @type flags: L{FlagConstant}

        @return: The flags given by C{flags} except the two type flags.
        @rtype: L{FlagConstant}
        )r3rbr�)rBr�s  rC�_tunnelTypeOnlyz TunnelTestsMixin._tunnelTypeOnly�s ����+�+�k�.A�.A�A�B�BrEc���|j}|jj�|jj|j�}|j|j
z|jzddttd�z
zz|jjddf}|j|j|j|j|jf}|j||�y)z�
        L{TuntapPort.startListening} opens the tunnel factory character special
        device C{"/dev/net/tun"} and configures it as a I{tun} tunnel.
        r �FTN)r�r��startListening�	getTunnelr��	O_CLOEXECr�r0�len�	interface�	openFlags�
requestedNamer"�blocking�closeOnExecr�)rBr�r��expected�actuals     rC�test_startListeningOpensDevicez/TunnelTestsMixin.test_startListeningOpensDevices���
�����	�	� � �"����&�&�t�y�y�1��
�M�M�F�,�,�,�v�/@�/@�@��g��S��\�!9�:�:��I�I�����
��
���� � ��K�K��O�O����
��	
����6�*rEc��|jj�|j|jj�y)zg
        L{TuntapPort.startListening} sets C{connected} on the port object to
        C{True}.
        N)r�r)r��	connectedrAs rC� test_startListeningSetsConnectedz1TunnelTestsMixin.test_startListeningSetsConnecteds*��
	
�	�	� � �"�����	�	�+�+�,rEc��|jj�|j|j|jj�y)z�
        L{TuntapPort.startListening} calls C{makeConnection} on the protocol
        the port was initialized with, passing the port as an argument.
        N)r�r)�assertIsr��	transportrAs rC�#test_startListeningConnectsProtocolz4TunnelTestsMixin.test_startListeningConnectsProtocol%s0��
	
�	�	� � �"��
�
�d�i�i����!8�!8�9rEc��|jj�|j|j|jj	��y)z�
        L{TuntapPort.startListening} passes the port instance to the reactor's
        C{addReader} method to begin watching the port's file descriptor for
        data to read.
        N)r�r)�assertInr!rPrAs rC� test_startListeningStartsReadingz1TunnelTestsMixin.test_startListeningStartsReading-s3��	
�	�	� � �"��
�
�d�i�i����!8�!8�!:�;rEc��|jjjd�|jt|j
j�y)z�
        L{TuntapPort.startListening} raises L{CannotListenError} if opening the
        tunnel factory character special device fails.
        r�N�r��permissions�remover�rr�r)rAs rC�%test_startListeningHandlesOpenFailurez6TunnelTestsMixin.test_startListeningHandlesOpenFailure6s7��
	
�����&�&�v�.����+�T�Y�Y�-E�-E�FrEc��|jjjd�|jt|j
j�y)z�
        L{TuntapPort.startListening} raises L{CannotListenError} if the
        C{ioctl} call to configure the tunnel device fails.
        r�Nr@rAs rC�*test_startListeningHandlesConfigureFailurez;TunnelTestsMixin.test_startListeningHandlesConfigureFailure>s7��
	
�����&�&�w�/����+�T�Y�Y�-E�-E�FrEc���|j�}|j||jj��|jj	d�|j|j
|��y)a<
        Verify that the C{stopListening} method of an L{IListeningPort} removes
        that port from the reactor's "readers" set and also that the
        L{Deferred} returned by that method fires with L{None}.

        @param port: The port object to stop.
        @type port: L{IListeningPort} provider
        rN)�
stopListening�assertNotInr!rP�advance�assertIsNone�successResultOf)rBr��stoppeds   rC�	_stopPortzTunnelTestsMixin._stopPortFsZ���$�$�&������t�|�|�6�6�8�9������Q�����$�.�.�w�7�8rEc���|jj�|jj�}|j|j�|j	||j
j�y)z�
        L{TuntapPort.stopListening} returns a L{Deferred} which fires after the
        port has been removed from the reactor's reader list by passing it to
        the reactor's C{removeReader} method.
        N)r�r)r�rMrHr��
_openFiles)rBr�s  rC�test_stopListeningStopsReadingz/TunnelTestsMixin.test_stopListeningStopsReadingUsP��	
�	�	� � �"����!�!�#�����t�y�y�!��������!7�!7�8rEc��|jj�|j|j�|j|jj�y)z�
        After the L{Deferred} returned by L{TuntapPort.stopListening} fires,
        the C{connected} attribute of the port object is set to C{False}.
        N)r�r)rM�assertFalser6rAs rC�!test_stopListeningUnsetsConnectedz2TunnelTestsMixin.test_stopListeningUnsetsConnectedas<��
	
�	�	� � �"����t�y�y�!�������,�,�-rEc��|jj�|j|j�|j|jj
�y)zt
        L{TuntapPort.stopListening} calls C{doStop} on the protocol the port
        was initialized with.
        N)r�r)rMrJr�r:rAs rC�test_stopListeningStopsProtocolz0TunnelTestsMixin.test_stopListeningStopsProtocoljs<��
	
�	�	� � �"����t�y�y�!����$�-�-�1�1�2rEc�x�|jj�}|j|j|��y)z�
        L{TuntapPort.stopListening} returns a L{Deferred} which succeeds
        immediately if it is called when the port is not listening.
        N)r�rGrJrK)rBrLs  rC�test_stopListeningWhenStoppedz.TunnelTestsMixin.test_stopListeningWhenStoppedss/��
�)�)�)�)�+�����$�.�.�w�7�8rEc��|jj�|jj�|jj�}|jj	d�|j|j
|��y)z�
        It is safe and a no-op to call L{TuntapPort.stopListening} more than
        once with no intervening L{TuntapPort.startListening} call.
        rN)r�r)rGr!rIrJrK)rB�seconds  rC�test_multipleStopListeningz+TunnelTestsMixin.test_multipleStopListening{sa��
	
�	�	� � �"��	�	���!����(�(�*�������Q�����$�.�.�v�6�7rEc���|jj�|jj�|jj	d�|j|jj�|j|jg�}|jt|dd�|jd|dd�|jdt|��y)zP
        L{TuntapPort.loseConnection} stops the port and is deprecated.
        r�categoryz�twisted.pair.tuntap.TuntapPort.loseConnection was deprecated in Twisted 14.0.0; please use twisted.pair.tuntap.TuntapPort.stopListening insteadr��N)r�r)�loseConnectionr!rIrRr6�
flushWarnings�test_loseConnectionr��DeprecationWarningr,)rB�warningss  rCr`z$TunnelTestsMixin.test_loseConnection�s���	
�	�	� � �"��	�	� � �"������Q��������,�,�-��%�%�t�'?�'?�&@�A�����+�X�a�[��-D�E����
$�
�Q�K�	�"�		
�	
����C��M�*rEc��|jj�|jj|j�}||_|jj�|j
g|jj�y)ah
        Test that L{TuntapPort.doRead} has no side-effects under a certain
        exception condition.

        @param style: An exception instance to arrange for the (python wrapper
            around the) underlying platform I{read} call to fail with.

        @raise C{self.failureException}: If there are any observable
            side-effects.
        N)	r�r)r�r*�nonBlockingExceptionStyle�doReadr�r��received)rB�styler�s   rC�_stopsReadingTestz"TunnelTestsMixin._stopsReadingTest�s^��	
�	�	� � �"����&�&�t�y�y�1��+0��(��	�	��������T�]�]�3�3�4rEc�B�|jtj�y)zr
        Once L{TuntapPort.doRead} encounters an I{EAGAIN} errno from a C{read}
        call, it returns.
        N)rhr+�EAGAIN_STYLErAs rC�test_eagainStopsReadingz(TunnelTestsMixin.test_eagainStopsReading�s��
	
���v�2�2�3rEc�B�|jtj�y)zw
        Once L{TuntapPort.doRead} encounters an I{EWOULDBLOCK} errno from a
        C{read} call, it returns.
        N)rhr+�EWOULDBLOCK_STYLErAs rC�test_ewouldblockStopsReadingz-TunnelTestsMixin.test_ewouldblockStopsReading�s��
	
���v�7�7�8rEc�B�|jtj�y)zq
        Once L{TuntapPort.doRead} encounters an I{EINTR} errno from a C{read}
        call, it returns.
        N)rhr+�EINTR_STYLErAs rC�test_eintrblockStopsReadingz,TunnelTestsMixin.test_eintrblockStopsReading�s��
	
���v�1�1�2rEc�f�Gd�dt�}|j||j|��y)z�
        If L{Tuntap.doRead} encounters any exception other than one explicitly
        handled by the code, the exception propagates to the caller.
        c��eZdZy)�ETunnelTestsMixin.test_unhandledReadError.<locals>.UnexpectedExceptionN)rWrXrYr[rErC�UnexpectedExceptionrt�s��rEruN)�	Exceptionr�rh)rBrus  rC�test_unhandledReadErrorz(TunnelTestsMixin.test_unhandledReadError�s/��	�)�	�	
�����!7�!7�9L�9N�	
rEc�b�|jt|jttd��y)z�
        Just like C{test_unhandledReadError}, but for the case where the
        exception that is not explicitly handled happens to be of type
        C{EnvironmentError} (C{OSError} or C{IOError}).
        zOperation not permittedN)r�r�rhr	rAs rC�"test_unhandledEnvironmentReadErrorz3TunnelTestsMixin.test_unhandledEnvironmentReadError�s'��	
����T�+�+�W�U�<U�-V�	
rEc�r�d|jjdz
z}|jj�|jj	|j�}|j
j
|�|jj�|j|g|jj�y)z�
        L{TuntapPort.doRead} reads a datagram of fewer than
        C{TuntapPort.maxPacketSize} from the port's file descriptor and passes
        it to its protocol's C{datagramReceived} method.
        �xr]N�r��
maxPacketSizer)r�r*�
readBufferrrrer�r�rf�rBr�r�s   rC�test_doReadSmallDatagramz)TunnelTestsMixin.test_doReadSmallDatagram�s����4�9�9�2�2�Q�6�7���	�	� � �"����&�&�t�y�y�1����� � ��*��	�	�������(��T�]�]�%;�%;�<rEc�r�d|jjz}|jj�|jj	|j�}|j
j
|dz�|jj�|j|g|jj�y)z�
        L{TuntapPort.doRead} reads the first part of a datagram of more than
        C{TuntapPort.maxPacketSize} from the port's file descriptor and passes
        the truncated data to its protocol's C{datagramReceived} method.
        r{�yNr|rs   rC�test_doReadLargeDatagramz)TunnelTestsMixin.test_doReadLargeDatagram�s����$�)�)�1�1�1���	�	� � �"����&�&�t�y�y�1����� � ��D��1��	�	�������(��T�]�]�%;�%;�<rEc��ttd��}d}g}||jjkrd|j	t|�|jjz�||jjz
}||jjkr�d|jj�|jj|j�}|jj|�|jj	d�|jj�|j||jj�y)z�
        L{TuntapPort.doRead} reads several datagrams, of up to
        C{TuntapPort.maxThroughput} bytes total, before returning.
        sabcdefghijklmnopqrstuvwxyzrs"excessive datagram, not to be readN)rr!r��
maxThroughputrr�nextr}r)r�r*r~�extendrer�r�rf)rB�values�totalrur�s     rC�test_doReadSeveralDatagramsz,TunnelTestsMixin.test_doReadSeveralDatagrams�s���
�y�!>�?�@�����	��d�i�i�-�-�-����T�&�\�D�I�I�,C�,C�C�D��T�Y�Y�,�,�,�E��d�i�i�-�-�-�	
�	�	� � �"����&�&�t�y�y�1����� � ��+���� � �!F�G��	�	��������D�M�M�$:�$:�;rEc�2�|jj�|jj|j�jjd�d|j_|jj�|jt�S)z�
        Deliver some data to a L{TuntapPort} hooked up to an application
        protocol that raises an exception from its C{datagramReceived} method.

        @return: Whatever L{AttributeError} exceptions are logged.
        spingN)r�r)r�r*r~rrr�rfre�flushLoggedErrors�AttributeErrorrAs rC�_datagramReceivedExceptionz+TunnelTestsMixin._datagramReceivedExceptionsj��	
�	�	� � �"������d�i�i�(�3�3�:�:�7�C�"&��
�
���	�	�����%�%�n�5�5rEc�Z�|j�}|jdt|��y)zt
        If the protocol's C{datagramReceived} method raises an exception, the
        exception is logged.
        r]N)r�r�r,)rB�errorss  rC�test_datagramReceivedExceptionz/TunnelTestsMixin.test_datagramReceivedExceptions&��
�0�0�2������C��K�(rEc�T�g}t|j�|jt|j�|j	�td�|D��}t
|�}|jdt|jj��d�|j�d�y)z�
        The exception raised by C{datagramReceived} is logged with a message
        identifying the offending protocol.
        c3�,K�|]}|ds�	|���y�w)�isErrorNr[)�.0�ms  rC�	<genexpr>zTTunnelTestsMixin.test_datagramReceivedExceptionIdentifiesProtocol.<locals>.<genexpr>'s����9�1�A�i�L�Q�9�s�
�zUnhandled exception from z.datagramReceivedrN)r"rrr�r#r�r�r$r�r%r�r��
splitlines)rB�messages�errorr�s    rC�0test_datagramReceivedExceptionIdentifiesProtocolzATunnelTestsMixin.test_datagramReceivedExceptionIdentifiesProtocols���
���H�O�O�$��������8��'�'�)��9��9�9��#�E�*�����!�$�-�-�"9�"9�:�
=���� ��#�	
rEc��d}|jj�|jj|�|j|jj|j�jt|g��y)zG
        L{TuntapPort.write} sends a datagram into the tunnel.
        s
a b c d e f gN)r�r)r�r�r�r*�writeBufferr�rBr�s  rC�
test_writezTunnelTestsMixin.test_write/s\��$���	�	� � �"��	�	����!�����K�K�!�!�$�)�)�,�8�8�%��
�:K�	
rEc�B�|jj�|jj|j�}|jjt�|jjd�|jtdg�|j�y)z�
        If the platform write call is interrupted (causing the Python wrapper
        to raise C{IOError} with errno set to C{EINTR}), the write is re-tried.
        shello, worldN)r�r)r�r*�pendingSignalsrrr
r�r�rr�r�s  rC�test_interruptedWritez&TunnelTestsMixin.test_interruptedWrite:sn��
	
�	�	� � �"����&�&�t�y�y�1�����$�$�V�,��	�	����(������0�1�6�3E�3E�FrEc��|jj�|jj|j�}|j	t
|jjd|jzdz�y)z{
        Any exception raised by the underlying write call, except for EINTR, is
        propagated to the caller.
        r{r�N)r�r)r�r*r�r�r��SEND_BUFFER_SIZEr�s  rC�test_unhandledWriteErrorz)TunnelTestsMixin.test_unhandledWriteErrorEsY��
	
�	�	� � �"����&�&�t�y�y�1������T�Y�Y�_�_�d�V�-D�-D�&D�t�&K�	
rEc�&�gd�}|jj�|jj|�|j|jj|j�jtdj|�g��y)z�
        L{TuntapPort.writeSequence} sends a datagram into the tunnel by
        concatenating the byte strings in the list passed to it.
        )�a�b�c�drEN)	r�r)�
writeSequencer�r�r*r�r�joinr�s  rC�test_writeSequencez#TunnelTestsMixin.test_writeSequencePsh��
,���	�	� � �"��	�	����)�����K�K�!�!�$�)�)�,�8�8�%����(�AS�@T�:U�	
rEc�D�|jj�|jj�}|jt	|j|jj�|jj|j�j�|�y)zp
        L{TuntapPort.getHost} returns a L{TunnelAddress} including the tunnel's
        type and name.
        N)r�r)�getHostr�r2r&r�rdr�r*r")rBrs  rC�test_getHostzTunnelTestsMixin.test_getHost\su��
	
�	�	� � �"��)�)�#�#�%�������$�$�T�[�[�%<�%<�=����%�%�d�i�i�0�5�5�
�
�	
rEc��|jj�|jt|j�t	|j
j��dj|j|jj�j|jj|j�j�}|jt|j�j|�dk7�y)��
        The string representation of a L{TuntapPort} instance includes the
        tunnel type and interface and the protocol associated with the port.
        z listening on {}/{}>���N)r�r)�assertRegex�strr%r�r��formatr&r�rdr"r�r*r��find�rBr2s  rC�test_listeningStringz%TunnelTestsMixin.test_listeningStringks���
	
�	�	� � �"�����T�Y�Y��);�D�M�M�<S�<S�)T�U�)�0�0�� � ����!8�!8�9�>�>��K�K�!�!�$�)�)�,�1�1�
��	
����D�I�I��+�+�H�5��;�<rEc��|jt|j�t|jj
��dj
|j|jj�j|j�}|jt|j�j|�dk7�y)r�z not listening on {}/{}>r�N)
r�r�r�r%r�r�r�r&r�rdr"r�r�r�s  rC�test_unlisteningStringz'TunnelTestsMixin.test_unlisteningStringys���
	
����T�Y�Y��);�D�M�M�<S�<S�)T�U�-�4�4�� � ����!8�!8�9�>�>��I�I�
��	
����D�I�I��+�+�H�5��;�<rEc��|j|jjj�d|j	|j
j�j�d�|jj��y)z
        L{TuntapPort.logPrefix} returns a string identifying the application
        protocol and the type of tunnel.
        z (�)N)
r�r�r�rWr&r�rdr"r��	logPrefixrAs rC�test_logPrefixzTunnelTestsMixin.test_logPrefix�s\��
	
����
�
�'�'�0�0��$�$�T�[�[�%<�%<�=�B�B�
�

�I�I���!�
	
rEN)'rWrXrYrZr�r&r4r7r;r>rCrErMrPrSrUrWrZr`rhrkrnrqrwryr�r�r�r�r�r�r�r�r�r�r�r�r�r�r[rErCrr�s����

�C�+�2-�:�<�G�G�
9�
9�.�3�9�	8�+�*5�"4�9�3�
�
�=�=�<�(6� )�
�"	
�	G�	
�

�

�=�=�
rErc�"�eZdZdZd�Zd�Zd�Zy)�TunnelAddressTestsz%
    Tests for L{TunnelAddress}.
    c	�r�|jttttj
d���y)zD
        A L{TunnelAddress} instances provides L{IAddress}.
        �tap0N)r�rrr2r3r�rAs rC�test_interfacesz"TunnelAddressTests.test_interfaces�s'��	
�����=��1D�1D�f�#M�N�	
rEc���ttjd�}|jd|d�|jd|d�|j	|j
g�}d}|jt|dd�|j||dd�|jt|dd�|j||dd�|jdt|��y	)
z�
        A L{TunnelAddress} instance can be indexed to retrieve either the byte
        string C{"TUNTAP"} or the name of the tunnel interface, while
        triggering a deprecation warning.
        r��TUNTAPrr]zUTunnelAddress.__getitem__ is deprecated since Twisted 14.0.0  Use attributes instead.r\r��N)r2r3r�r�r_�
test_indexingrar,)rBrrbr�s    rCr�z TunnelAddressTests.test_indexing�s��� �� 3� 3�V�<������7�1�:�.��������,��%�%�t�'9�'9�&:�;��
&�	�	
���+�X�a�[��-D�E�����(�1�+�i�"8�9����+�X�a�[��-D�E�����(�1�+�i�"8�9�����C��M�*rEc�l�|jtttjd���d�y)z�
        The string representation of a L{TunnelAddress} instance includes the
        class name and the values of the C{type} and C{name} attributes.
        r)r"z*TunnelAddress type=IFF_TUN name=b'device'>N)r��reprr2r3rbrAs rC�	test_reprzTunnelAddressTests.test_repr�s*��
	
�����{�2�2��C�D�8�	
rEN)rWrXrYrZr�r�r�r[rErCr�r��s���
�+�(
rEr�c�R�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zy
)�TunnelAddressEqualityTestsz^
    Tests for the implementation of equality (C{==} and C{!=}) for
    L{TunnelAddress}.
    c��ttjd�|_ttjtjzd�|_ttj
d�|_ttjd�|_y)Nrstap1stun1)r2r3rb�firstrYr��
variedType�
variedNamerAs rCr�z TunnelAddressEqualityTests.setUp�sd��"�;�#6�#6�	�B��
�$����+�"5�"5�5�y�
���(��(;�(;�W�E���'��(;�(;�W�E��rEc�T�|j|j|jk(�y)z>
        A L{TunnelAddress} compares equal to itself.
        N�r�r�rAs rC�test_selfComparesEqualz1TunnelAddressEqualityTests.test_selfComparesEqual�s��	
����
�
�d�j�j�0�1rEc�T�|j|j|jk7�y)zI
        A L{TunnelAddress} doesn't compare not equal to itself.
        N�rRr�rAs rC�test_selfNotComparesNotEqualz7TunnelAddressEqualityTests.test_selfNotComparesNotEqual�s��	
������t�z�z�1�2rEc�T�|j|j|jk(�y)z�
        Two L{TunnelAddress} instances with the same value for the C{type} and
        C{name} attributes compare equal to each other.
        N)r�r�rYrAs rC� test_sameAttributesComparesEqualz;TunnelAddressEqualityTests.test_sameAttributesComparesEqual�s��
	
����
�
�d�k�k�1�2rEc�T�|j|j|jk7�y)z�
        Two L{TunnelAddress} instances with the same value for the C{type} and
        C{name} attributes don't compare not equal to each other.
        N)rRr�rYrAs rC�&test_sameAttributesNotComparesNotEqualzATunnelAddressEqualityTests.test_sameAttributesNotComparesNotEqual�s��
	
������t�{�{�2�3rEc�T�|j|j|jk(�y)z�
        Two L{TunnelAddress} instances that differ only by the value of their
        type don't compare equal to each other.
        N)rRr�r�rAs rC�"test_differentTypeComparesNotEqualz=TunnelAddressEqualityTests.test_differentTypeComparesNotEqual����
	
������t���6�7rEc�T�|j|j|jk7�y)z�
        Two L{TunnelAddress} instances that differ only by the value of their
        type compare not equal to each other.
        N)r�r�r�rAs rC�"test_differentTypeNotComparesEqualz=TunnelAddressEqualityTests.test_differentTypeNotComparesEqual����
	
����
�
�d�o�o�5�6rEc�T�|j|j|jk(�y)z�
        Two L{TunnelAddress} instances that differ only by the value of their
        name don't compare equal to each other.
        N)rRr�r�rAs rC�"test_differentNameComparesNotEqualz=TunnelAddressEqualityTests.test_differentNameComparesNotEqual�r�rEc�T�|j|j|jk7�y)z�
        Two L{TunnelAddress} instances that differ only by the value of their
        name compare not equal to each other.
        N)r�r�r�rAs rC�"test_differentNameNotComparesEqualz=TunnelAddressEqualityTests.test_differentNameNotComparesEqualr�rEc�@�|j|j|k(�y)zc
        A L{TunnelAddress} doesn't compare equal to an instance of another
        class.
        Nr�rAs rC�#test_differentClassNotComparesEqualz>TunnelAddressEqualityTests.test_differentClassNotComparesEqual
s��
	
������t�+�,rEc�@�|j|j|k7�y)zX
        A L{TunnelAddress} compares not equal to an instance of another class.
        Nr�rAs rC�#test_differentClassComparesNotEqualz>TunnelAddressEqualityTests.test_differentClassComparesNotEquals��	
����
�
�d�*�+rEN)rWrXrYrZr�r�r�r�r�r�r�r�r�r�r�r[rErCr�r��s?���
F� 2�3�3�4�8�7�8�7�-�,rEr�c�&�eZdZdZd�Z	dd�Zd�Zy)�IPRecordingProtocol�H
    A protocol which merely records the datagrams delivered to it.
    c��g|_yr:�rfrAs rC�
startProtocolz!IPRecordingProtocol.startProtocol!�	����
rENc�:�|jj|�yr:�rfrr)rBr��partial�destrlr�s      rCr{z$IPRecordingProtocol.datagramReceived$s��	
�
�
���X�&rEc��yr:r[)rB�num�protos   rCrzIPRecordingProtocol.addProto)s��rE)FNNN)rWrXrYrZr�r{rr[rErCr�r�s����IM�'�

rEr�c�>�eZdZdZe�Zee_edd�Z	y)�TunTestszJ
    Tests for L{TuntapPort} when used to open a Linux I{tun} tunnel.
    N)
rWrXrYrZrr#r�r�r`r�r[rErCr�r�.s$����i�G�*�G��
�t�T�
"�FrEr�c��eZdZdZd�Zdd�Zy)�EthernetRecordingProtocolr�c��g|_yr:r�rAs rCr�z'EthernetRecordingProtocol.startProtocol>r�rEc�:�|jj|�yr:r�)rBr�r�s   rCr{z*EthernetRecordingProtocol.datagramReceivedAs���
�
���X�&rEN)F)rWrXrYrZr�r{r[rErCr�r�9s����'rEr�c�B�eZdZdZe�Zee_eddd��Z	y)�TapTestszJ
    Tests for L{TuntapPort} when used to open a Linux I{tap} tunnel.
    NFr�)
rWrXrYrZrr#r�r�r�r�r[rErCr�r�Es&����i�G�0�G��
�t�T�e�
,�FrEr�c��eZdZdZd�Zy)�IOSystemTestsMixinzH
    Tests that apply to any L{_IInputOutputSystem} implementation.
    c��|j�}|jt|jdtj
�y)zt
        L{_IInputOutputSystem.open} raises L{OSError} when called with a
        non-existent device path.
        s!/dev/there-is-no-such-device-everN)r�r�r�r�r�r�r�s  rC�test_noSuchDevicez$IOSystemTestsMixin.test_noSuchDeviceUs2��
�"�"�$������V�[�[�"F��	�	�	
rEN)rWrXrYrZrr[rErCrrPs���
rErc��eZdZdZy)�MemoryIOSystemTestszL
    General L{_IInputOutputSystem} tests applied to L{MemoryIOSystem}.
    Nr�r[rErCrr`r�rErc��eZdZdZy)�RealIOSystemTestszI
    General L{_IInputOutputSystem} tests applied to L{_RealSystem}.
    Nr�r[rErCrrhs��rEr)orZr�r�r��collectionsrr�rrrrrr	r
�	itertoolsr�randomr�signalr
�typingr�twisted.python.reflectrrr��__annotations__rr��zope.interfacerr�zope.interface.verifyr�twisted.internet.errorr�twisted.internet.interfacesrrr�twisted.internet.protocolrrr�twisted.internet.taskr�twisted.pair.ethernetr�twisted.pair.ipr�twisted.pair.rawr�twisted.pair.rawudpr �twisted.python.compatr!�twisted.python.logr"r#r$r%�twisted.trial.unittestr&r'�objectr6r5�twisted.pair.testingr(r)r*r+r,r-r.r/�twisted.pair.tuntapr0r1r2r3r4rr8r]r`r�r�r�r�r��setattrr�r�r�r�r�rrrrrr�r�r�r�r�r�rrrr[rErC�<module>r s ���

�
�
��K�K�K�����;��s�m����]���L�1�.�4�O�O���
(�2�&�/�.�+�M�M�5�@�
�� ���	�	�	�����D�
�]��'"�'"��'"�T
�]�L�N�+�$���$�M�M�`f�f�RB�%�B�f*�f*�R��2��0�2E�����
��)�)�+=�+K�+K�PU�����0�2E�����
��)�)�+=�+K�+K�PT�����0�2E�����
� �/�/�1C�1Q�1Q�R��
�
 �!�J�[�J�"�J�Z � �(?��0�2E�?�&
@��0�2E�
@� 9�)�9�*r
�r
�j
)
�,�)
�XW,�!4�W,�t
�
� �
�2�
�!�
�$#��!4�#�	'� 0�	'�-��!4�-�

�

� ��+�-A���*�,?�AU���a*	��'�=�<�L�=�s�J-�-	J:�9J:

Zerion Mini Shell 1.0