Uname:Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64

403WebShell
403Webshell
Server IP : 3.111.61.48  /  Your IP : 216.73.216.67
Web Server : Apache
System : Linux ip-10-0-5-176 6.8.0-1057-aws #60~22.04.1-Ubuntu SMP Wed May 27 08:16:59 UTC 2026 x86_64
User : ubuntu ( 1000)
PHP Version : 8.2.31
Disable Function : exec,passthru,shell_exec,system
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : OFF  |  Sudo : ON  |  Pkexec : ON
Directory :  /usr/lib/python3.10/test/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /usr/lib/python3.10/test/__pycache__/test_socket.cpython-310.pyc
o

�9j`��@s�ddlZddlmZddlmZddlmZddlmZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
Z
ddlZddlZddlZddlZddlZddlZddlZddlmZddlZddlZddlZddlZddlZddlZddlZddlZddl Z zddl!Z!Wne"y�dZ!Ynwzddl#Z#Wne"y�dZ#Ynwej$Z$d�%d	�Z&d
Z'e�(�dkZ)zddl*Z*Wne"y�dZ*Ynwdd
�Z+dd�Z,dd�Z-dd�Z.dd�Z/dd�Z0dd�Z1dd�Z2dd�Z3ej4dd��Z5e,�Z6e-�Z7e.�Z8e/�Z9e0�Z:e1�Z;e2�Z<e=e
d �Z>e3�Z?e�d!�j@ZAGd"d#�d#ejB�ZCGd$d%�d%ejB�ZDGd&d'�d'eD�ZEGd(d)�d)�ZFGd*d+�d+ejB�ZGGd,d-�d-ejB�ZHGd.d/�d/�ZIGd0d1�d1eCeI�ZJGd2d3�d3eDeI�ZKe�Le>d4�Gd5d6�d6eEeI��ZMGd7d8�d8eGeI�ZNGd9d:�d:eHeI�ZOe�Pe#dud;�e�Le<d<�e�Le+�d=kd>�Gd?d@�d@ejBeI����ZQGdAdB�dBeJ�ZRGdCdD�dDejBeI�ZSGdEdF�dFejB�ZTGdGdH�dHeT�ZUGdIdJ�dJeFeTeI�ZVGdKdL�dLeUeV�ZWGdMdN�dNeT�ZXGdOdP�dPeX�ZYGdQdR�dReT�ZZGdSdT�dTeZ�Z[GdUdV�dVeZ�Z\GdWdX�dXeZ�Z]GdYdZ�dZeZ�Z^Gd[d\�d\eZ�Z_Gd]d^�d^e_�Z`Gd_d`�d`e_�Zadadb�Zbdcdd�Zcdedf�ZdGdgdh�dhejB�Zee�Le6di�Gdjdk�dkejB��Zfe�Le6di�Gdldm�dmeN��Zge�Le7dn�Gdodp�dpejB��Zhe�Le8dq�Gdrds�dsejB��Zie�Le9dt�Gdudv�dvejB��Zje�Le9dt�Gdwdx�dxeO��Zke�Le;dy�Gdzd{�d{ejB��Zle�Pe#dud;�e�Le<d<�Gd|d}�d}ejB���Zme�Le?d~�Gdd��d�ejB��ZnGd�d��d�eR�ZoGd�d��d�eK�Zpe�Le>d4�Gd�d��d�eM��ZqGd�d��d�eF�ZrGd�d��d�er�ZsGd�d��d�er�ZtGd�d��d�er�ZuGd�d��d�er�ZvGd�d��d�er�ZwGd�d��d�er�ZxGd�d��d�ex�ZyGd�d��d�ey�ZzGd�d��d�ey�Z{Gd�d��d�er�Z|Gd�d��d�e|�Z}Gd�d��d�e|�Z~Gd�d��d�ese|�ZGd�d��d�ejB�Z�Gd�d��d�ex�Z�Gd�d��d�ex�Z�Gd�d��d�eteveVe\�Z�ece
j
d��Gd�d��d�e{e���Z�ece
j
d��Gd�d��d�e~e���Z�ece
j
d��Gd�d��d�ee���Z�Gd�d��d�eteveVe`�Z�ece
j
d��e�Lej�d��edd�d��Gd�d��d�e{e�����Z�ece
j
d��e�Lej�d��edd�d��Gd�d��d�e~e�����Z�ece
j
d��e�Lej�d��edd�d��Gd�d��d�ee�����Z�ece
j
d��e�Lej�d��ece
d��edd�d��Gd�d��d�e�e������Z�ece
j
d��e�Lej�d��ece
d��edd�d��Gd�dÄd�ese�e������Z�e�Le>d4�Gd�dńd�eteveVe]��Z�e�Le>d4�ece
j
d��Gd�dDŽd�e{e����Z�e�Le>d4�ece
j
d��Gd�dɄd�e~e����Z�e�Le>d4�ece
j
d��Gd�d˄d�ee����Z�e�Le>d4�Gd�d̈́d�eteveVea��Z�ece
j
d��e�Lej�d��e�Le>d4�edd�d��Gd�dτd�e{e������Z�ece
j
d��e�Lej�d��e�Le>d4�edd�d��Gd�dфd�e~e������Z�ece
j
d��e�Lej�d��e�Le>d4�edd�d��Gd�dӄd�ee������Z�ece
j
d��e�Lej�d��e�Le>d4�ece
d��edd�d��Gd�dՄd�e�e�������Z�ece
j
d��e�Lej�d��e�Le>d4�ece
d��edd�d��Gd�dׄd�ese�e�������Z�Gd�dلd�eweWe[�Z�ece
j
d��Gd�dۄd�eze���Z�ece
j
d��Gd�d݄d�e~e}e���Z�ece
j
d��Gd�d߄d�ee}e���Z�Gd�d�d�eueweWe^�Z�ece
j
d��e�Pe)d�edd�d�d�Gd�d�d�eze�����Z�ece
j
d��e�Pe)d�edd�d�d�Gd�d�d�e~e}e�����Z�ece
j
d��e�Pe)d�edd�d�d�Gd�d�d�ee}e�����Z�Gd�d�d�eweWeY�Z�ece
j
d��ece
d�Gd�d�d�eze����Z�ece
j
d��ece
d�Gd�d�d�e~e}e����Z�ece
j
d��ece
d�Gd�d�d�ee}e����Z�ece
j
d�d��ece
d�d�d��Gd�d��d�e�e����Z�ece
j
d�d��ece
d�d�d��Gd�d��d�ese�e����Z�Gd�d��d��Z�eced��e�Le=ed���p{e=ed���d�G�d�d��de�e\���Z�eced��e�Le=ed���p�e=ed���d�G�d�d��de�eFeUe[���Z�G�d�d��deJ�Z�G�d�d��deS�Z�G�d	�d
��d
eJ�Z�G�d�d��deR�Z�G�d
�d��de��Z�G�d�d��de��Z�G�d�d��de��Z�G�d�d��de��Z�G�d�d��de��Z�G�d�d��de��Z�G�d�d��de��Z�G�d�d��de�eo�Z�G�d�d��dejB�Z�G�d�d ��d eCeI�Z�G�d!�d"��d"eCeI�Z�G�d#�d$��d$eC�Z�G�d%�d&��d&eD�Z�e�Le>d4�G�d'�d(��d(eE��Z�G�d)�d*��d*ejB�Z�e�Lej�d+k�d,�G�d-�d.��d.ejB��Z�e�Le=e
d��d/�G�d0�d1��d1ejB��Z�G�d2�d3��d3eR�Z��d4Z��d5Z��d6Zd7�d8�Z�e�LeÃ�d9�G�d:�d;��d;ejB��Z�e�LeÃ�d9�G�d<�d=��d=ejBeI��Z�G�d>�d?��d?eJ�Z�G�d@�dA��dAejB�Z�e�Le=e
�dB��dC�G�dD�dE��dEejB��Z�e�LejɐdFk�dG�e�Le!�dH�G�dI�dJ��dJeC���Z�G�dK�dL��dLeJ�Z�e�Le=e�dM��dN�G�dO�dP��dPe˃�Z�e�Le:�dQ�G�dR�dS��dSejB��Z�e�Lej�dTk�dU�G�dV�dW��dWejB��Z�e�Lej�ϐdX��dY�G�dZ�d[��d[ejB��Z�G�d\�d]��d]ejB�Z�G�d^�d_��d_ejB�Z�ece
�d`�ece
�da�ece
d�G�db�dc��dcejB����ZӐdd�de�Z�eՐdfk�r�e�֡dSdS(g�N)�support)�	os_helper)�
socket_helper)�threading_helper)�proxyFuMichael Gilfix was hereሴ
�utf-8���AIXcCs~tdurdSttd�s
dSztdd��}t�|tjd�}Wd�n1s&wYWn
ty6YdSwt�d|�dS)N�IOCTL_VM_SOCKETS_GET_LOCAL_CIDz
/dev/vsock�rbz    �Ir)	�fcntl�hasattr�socket�open�ioctlr
�OSError�struct�unpack)�f�r�r�'/usr/lib/python3.10/test/test_socket.py�get_cid4s
���rc	C�>zt�tjtjtj�}WnttfyYdSw|��dS)z5Check whether CAN sockets are supported on this host.FT)r�PF_CAN�SOCK_RAW�CAN_RAW�AttributeErrorr�close��srrr�_have_socket_canA��r"c	Cr)z;Check whether CAN ISOTP sockets are supported on this host.FT)rr�
SOCK_DGRAM�	CAN_ISOTPrrrr rrr�_have_socket_can_isotpKr#r&c	Cr)z;Check whether CAN J1939 sockets are supported on this host.FT)rrr$�	CAN_J1939rrrr rrr�_have_socket_can_j1939Ur#r(c	C�<zt�tjtjd�}WnttfyYdSw|��dS)z5Check whether RDS sockets are supported on this host.rFT)r�PF_RDS�SOCK_SEQPACKETrrrr rrr�_have_socket_rds_��r,c	Cr))z8Check whether AF_ALG sockets are supported on this host.rFT)r�AF_ALGr+rrrr rrr�_have_socket_algir-r/c	Cr))z<Check whether AF_QIPCRTR sockets are supported on this host.rFT)r�
AF_QIPCRTRr$rrrr rrr�_have_socket_qipcrtrsr-r1cCst�du}|S)z:Check whether AF_VSOCK sockets are supported on this host.N)r)�retrrr�_have_socket_vsock}s
r3c	Cr)z>Check whether AF_BLUETOOTH sockets are supported on this host.FT)r�AF_BLUETOOTH�SOCK_STREAM�BTPROTO_RFCOMMrrrr rrr�_have_socket_bluetooth�s�r7c	cs8�t��}zt�|�dVWt�|�dSt�|�w�N)r�getdefaulttimeout�setdefaulttimeout)�timeout�old_timeoutrrr�socket_setdefaulttimeout�s�
r=�IPPROTO_UDPLITE�ic@�eZdZdd�Zdd�ZdS)�
SocketTCPTestcCs.t�tjtj�|_t�|j�|_|j��dSr8)r�AF_INETr5�servr�	bind_port�port�listen��selfrrr�setUp�szSocketTCPTest.setUpcC�|j��d|_dSr8�rCrrGrrr�tearDown��

zSocketTCPTest.tearDownN��__name__�
__module__�__qualname__rIrLrrrrrA�srAc@r@)�
SocketUDPTestcCs$t�tjtj�|_t�|j�|_dSr8)rrBr$rCrrDrErGrrrrI��zSocketUDPTest.setUpcCrJr8rKrGrrrrL�rMzSocketUDPTest.tearDownNrNrrrrrR�srRc@�eZdZdd�ZdS)�SocketUDPLITETestcCs(t�tjtjtj�|_t�|j�|_dSr8)rrBr$r>rCrrDrErGrrrrI�szSocketUDPLITETest.setUpN)rOrPrQrIrrrrrU��rUcs8eZdZdZ�fdd�Z�fdd�Z�fdd�Z�ZS)�ThreadSafeCleanupTestCasez�Subclass of unittest.TestCase with thread-safe cleanup methods.

    This subclass protects the addCleanup() and doCleanups() methods
    with a recursive lock.
    cs t�j|i|��t��|_dSr8)�super�__init__�	threading�RLock�
_cleanup_lock�rH�args�kwargs��	__class__rrrY��z"ThreadSafeCleanupTestCase.__init__c�<|j�t�j|i|��Wd�S1swYdSr8)r\rX�
addCleanupr]r`rrrd��$�z$ThreadSafeCleanupTestCase.addCleanupcrcr8)r\rX�
doCleanupsr]r`rrrf�rez$ThreadSafeCleanupTestCase.doCleanups)rOrPrQ�__doc__rYrdrf�
__classcell__rrr`rrW�s
rWc@sLeZdZdZdZdZ	dZe�e�Z		dZ
e
de�e
�d7Z
dd	�Zd
S)�
SocketCANTestz�To be able to run this test, a `vcan0` CAN interface can be created with
    the following commands:
    # modprobe vcan
    # ip link add dev vcan0 type vcan
    # ip link set up vcan0
    �vcan0�z=IB3x8sz@3I4l2I�x�cCs`t�tjtjtj�|_|�|jj�z|j�|jf�WdSt	y/|�
d|j�YdSw�N�%network interface `%s` does not exist)rrrrr!rdr�bind�	interfacer�skipTestrGrrrrIs��zSocketCANTest.setUpN)rOrPrQrgrq�bufsize�
can_frame_fmtr�calcsize�can_frame_size�bcm_cmd_msg_fmtrIrrrrri�s
ric@seZdZdZdZdd�ZdS)�
SocketRDSTestz\To be able to run this test, the `rds` kernel module must be loaded:
    # modprobe rds
    � cCsVt�tjtjd�|_|�|jj�z
t�|j�|_WdSt	y*|�
d�YdSw)Nrzunable to bind RDS socket)rr*r+rCrdrrrDrErrrrGrrrrIs�zSocketRDSTest.setUpN)rOrPrQrgrsrIrrrrrxsrxc@�@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�ThreadableTesta�Threadable Test class

    The ThreadableTest class makes it easy to create a threaded
    client/server pair from an existing unit test. To create a
    new threaded class from an existing unit test, use multiple
    inheritance:

        class NewClass (OldClass, ThreadableTest):
            pass

    This class defines two new fixture functions with obvious
    purposes for overriding:

        clientSetUp ()
        clientTearDown ()

    Any new test functions within the class must then define
    tests in pairs, where the test name is preceded with a
    '_' to indicate the client portion of the test. Ex:

        def testFoo(self):
            # Server portion

        def _testFoo(self):
            # Client portion

    Any exceptions raised by the clients during their tests
    are caught and transferred to the main thread to alert
    the testing framework.

    Note, the server setup function cannot call any blocking
    functions that rely on the client thread during setup,
    unless serverExplicitReady() is called just before
    the blocking call (such as in setting up a client/server
    connection and performing the accept() in setUp().
    cCs|j|_|j|_dSr8)rI�_ThreadableTest__setUp�_setUprGrrrrYFszThreadableTest.__init__cCs|j��dS)z�This method allows the server to explicitly indicate that
        it wants the client thread to proceed. This is useful if the
        server is about to execute a blocking routine that is
        dependent upon the client thread during its setup routine.N)�server_ready�setrGrrr�serverExplicitReadyKsz"ThreadableTest.serverExplicitReadycst���_�j�����jjddd�t���_t���_	t���_
t�d��_d�_
�fdd�}��|����}|�d�}||dd�}t�d|�}t��j|f��_zz���Wnd�_
�W�j��n�j��w�j	�����j
j�dS)N�Fcs�j��r
�j���dSr8)�queue�qsize�getrrGrr�raise_queued_exception]s

�z5ThreadableTest._setUp.<locals>.raise_queued_exception�.�_T)r�wait_threads_exit�wait_threads�	__enter__rd�__exit__rZ�Eventr~�client_ready�doner��Queue�server_crashed�id�rfind�getattr�thread�start_new_thread�	clientRun�
client_threadr|r�wait)rHr��
methodnamer?�test_methodrrGrr}Rs4






��
zThreadableTest._setUpc
Cs|j��z1z|��Wn#ty/}z|j�|�|��WYd}~W|j��dSd}~wwW|j��n|j��w|j	rF|��dSt
|d�sOtd��z,z|�Wntym}z|j�|�WYd}~nd}~wwW|��dSW|��dS|��w)N�__call__z%test_func must be a callable function)r~r��clientSetUp�
BaseExceptionr��put�clientTearDownr�rr�r�	TypeError)rH�	test_func�errrr�ts6
���

����zThreadableTest.clientRuncC�td��)Nz clientSetUp must be implemented.)�NotImplementedErrorrGrrrr���zThreadableTest.clientSetUpcCs|j��t��dSr8)r�rr��exitrGrrrr���
zThreadableTest.clientTearDownN)
rOrPrQrgrYr�r}r�r�r�rrrrr{ s%"r{c@�&eZdZd	dd�Zdd�Zdd�ZdS)
�ThreadedTCPSocketTest�runTestcC�tj||d�t�|�dS�N)�
methodName�rArYr{�rHr�rrrrY��zThreadedTCPSocketTest.__init__cC�t�tjtj�|_dSr8)rrBr5�clirGrrrr���z!ThreadedTCPSocketTest.clientSetUpcC�|j��d|_t�|�dSr8�r�rr{r�rGrrrr���
z$ThreadedTCPSocketTest.clientTearDownN�r��rOrPrQrYr�r�rrrrr���
r�c@r�)
�ThreadedUDPSocketTestr�cCr�r�)rRrYr{r�rrrrY�r�zThreadedUDPSocketTest.__init__cCr�r8)rrBr$r�rGrrrr��r�z!ThreadedUDPSocketTest.clientSetUpcCr�r8r�rGrrrr��r�z$ThreadedUDPSocketTest.clientTearDownNr�r�rrrrr��r�r�z'UDPLITE sockets required for this test.c@r�)
�ThreadedUDPLITESocketTestr�cCr�r�)rUrYr{r�rrrrY�r�z"ThreadedUDPLITESocketTest.__init__cCst�tjtjtj�|_dSr8)rrBr$r>r�rGrrrr���z%ThreadedUDPLITESocketTest.clientSetUpcCr�r8r�rGrrrr��r�z(ThreadedUDPLITESocketTest.clientTearDownNr�r�rrrrr��s
r�c@r�)
�ThreadedCANSocketTestr�cCr�r�)rirYr{r�rrrrY�r�zThreadedCANSocketTest.__init__cCsBt�tjtjtj�|_z|j�|jf�WdSty YdSwr8)rrrrr�rprqrrGrrrr��s�z!ThreadedCANSocketTest.clientSetUpcCr�r8r�rGrrrr��r�z$ThreadedCANSocketTest.clientTearDownNr�r�rrrrr��s
	r�c@r�)
�ThreadedRDSSocketTestr�cCr�r�)rxrYr{r�rrrrY�r�zThreadedRDSSocketTest.__init__cCsLt�tjtjd�|_z|j�tdf�|j��|_WdSty%YdSw�Nr)	rr*r+r�rp�HOST�getsockname�cli_addrrrGrrrr��s�z!ThreadedRDSSocketTest.clientSetUpcCr�r8r�rGrrrr��r�z$ThreadedRDSSocketTest.clientTearDownNr�r�rrrrr��s
r��
need fcntlz%VSOCK sockets required for this test.�z-This test can only be run on a virtual guest.c@�6eZdZd
dd�Zdd�Zdd�Zdd	�Zd
d�ZdS)�ThreadedVSOCKSocketStreamTestr�cC�tjj||d�t�|�dSr���unittest�TestCaserYr{r�rrrrY��z&ThreadedVSOCKSocketStreamTest.__init__cCsht�tjtj�|_|�|jj�|j�tjtf�|j�	�|�
�|j��\|_|_
|�|jj�dSr8)r�AF_VSOCKr5rCrdrrp�VMADDR_CID_ANY�	VSOCKPORTrFr��accept�conn�connaddrrGrrrrI�s
z#ThreadedVSOCKSocketStreamTest.setUpcCsDt�d�t�tjtj�|_|�|jj�t�}|j�	|t
f�dS)N皙�����?)�time�sleeprr�r5r�rdrr�connectr�)rH�cidrrrr��s

z)ThreadedVSOCKSocketStreamTest.clientSetUpcC�|j�d�}|�|t�dS�N�)r��recv�assertEqual�MSG�rH�msgrrr�
testStream�z(ThreadedVSOCKSocketStreamTest.testStreamcC�|j�t�|j��dSr8�r��sendr�rrGrrr�_testStream�z)ThreadedVSOCKSocketStreamTest._testStreamNr��rOrPrQrYrIr�r�r�rrrrr��s
	r�c@s:eZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�SocketConnectedTestz�Socket tests for client-server connection.

    self.cli_conn is a client socket connected to the server.  The
    setUp() method guarantees that it is connected to the server.
    r�cC�tj||d�dSr�)r�rYr�rrrrY�zSocketConnectedTest.__init__cCs*t�|�|��|j��\}}||_dSr8)r�rIr�rCr��cli_conn�rHr��addrrrrrI�

zSocketConnectedTest.setUpcCr�r8)r�rr�rLrGrrrrLr�zSocketConnectedTest.tearDowncCs(t�|�|j�t|jf�|j|_dSr8)r�r�r�r�r�rE�	serv_connrGrrrr�!s
zSocketConnectedTest.clientSetUpcCr�r8)r�rr�r�rGrrrr�&r�z"SocketConnectedTest.clientTearDownNr�)	rOrPrQrgrYrIrLr�r�rrrrr�
s
r�c@r�)�SocketPairTestr�cCr�r�r�r�rrrrY-r�zSocketPairTest.__init__cCst��\|_|_dSr8)r�
socketpairrCr�rGrrrrI1�zSocketPairTest.setUpcCrJr8rKrGrrrrL4rMzSocketPairTest.tearDowncC�dSr8rrGrrrr�8�zSocketPairTest.clientSetUpcCr�r8r�rGrrrr�;r�zSocketPairTest.clientTearDownNr�)rOrPrQrYrIrLr�r�rrrrr�+s
r�c@s(eZdZdZdd�Zdd�Zdd�ZdS)	�SocketTestBasez�A base class for socket tests.

    Subclasses must provide methods newSocket() to return a new socket
    and bindSock(sock) to bind it to an unused address.

    Creates a socket self.serv and sets self.serv_addr to its address.
    cC�|��|_|��dSr8)�	newSocketrC�
bindServerrGrrrrIPr�zSocketTestBase.setUpcC�|�|j�|j��|_dS)z9Bind server socket and set self.serv_addr to its address.N)�bindSockrCr��	serv_addrrGrrrr�T�zSocketTestBase.bindServercCrJr8rKrGrrrrLYrMzSocketTestBase.tearDownN)rOrPrQrgrIr�rLrrrrr�Gs
r�cs eZdZdZ�fdd�Z�ZS)�SocketListeningTestMixinz%Mixin to listen on the server socket.cst���|j��dSr8)rXrIrCrFrGr`rrrIa�
zSocketListeningTestMixin.setUp)rOrPrQrgrIrhrrr`rr�^sr�cs@eZdZdZ�fdd�Zdd�Zdd�Zdd	�Zd
d�Z�Z	S)�ThreadedSocketTestMixinz�Mixin to add client socket and allow client/server tests.

    Client socket is self.cli and its address is self.cli_addr.  See
    ThreadableTest for usage information.
    cs t�j|i|��t�|�dSr8)rXrYr{r]r`rrrYnrbz ThreadedSocketTestMixin.__init__cCr�r8)�newClientSocketr��
bindClientrGrrrr�rr�z#ThreadedSocketTestMixin.clientSetUpcCs|��S)z&Return a new socket for use as client.)r�rGrrrr�vsz'ThreadedSocketTestMixin.newClientSocketcCr�)z8Bind client socket and set self.cli_addr to its address.N)r�r�r�r�rGrrrrzr�z"ThreadedSocketTestMixin.bindClientcCr�r8r�rGrrrr�r�z&ThreadedSocketTestMixin.clientTearDown)
rOrPrQrgrYr�r�rr�rhrrr`rr�fsr�csDeZdZdZ�fdd�Z�fdd�Z�fdd�Z�fdd	�Z�ZS)
�ConnectedStreamTestMixinz�Mixin to allow client/server stream tests with connected client.

    Server's socket representing connection to client is self.cli_conn
    and client's connection to server is self.serv_conn.  (Based on
    SocketConnectedTest.)
    cs*t���|��|j��\}}||_dSr8)rXrIr�rCr�r�r�r`rrrI�r�zConnectedStreamTestMixin.setUpcs|j��d|_t���dSr8)r�rrXrLrGr`rrrL�r�z!ConnectedStreamTestMixin.tearDowncs$t���|j�|j�|j|_dSr8)rXr�r�r�r�r�rGr`rrr��s
z$ConnectedStreamTestMixin.clientSetUpcs6z
|j��d|_Wn	tyYnwt���dSr8)r�rrrXr�rGr`rrr��s

�z'ConnectedStreamTestMixin.clientTearDown)	rOrPrQrgrIrLr�r�rhrrr`rr�srcs(eZdZdZ�fdd�Zdd�Z�ZS)�UnixSocketTestBasez(Base class for Unix-domain socket tests.cs(t��|_|�tj|j�t���dSr8)�tempfile�mkdtemp�dir_pathrd�os�rmdirrXrIrGr`rrrI�s
zUnixSocketTestBase.setUpcCs,tj|jd�}t�||�|�tj|�dS)N)�dir)r�mktemprr�bind_unix_socketrdr�unlink)rH�sock�pathrrrr��szUnixSocketTestBase.bindSock)rOrPrQrgrIr�rhrrr`rr�src@�eZdZdZdd�ZdS)�UnixStreamBasez-Base class for Unix-domain SOCK_STREAM tests.cC�t�tjtj�Sr8)r�AF_UNIXr5rGrrrr���zUnixStreamBase.newSocketN�rOrPrQrgr�rrrrr��rcs,eZdZdZeZ�fdd�Zdd�Z�ZS)�InetTestBasez!Base class for IPv4 socket tests.cst���|jd|_dS�Nr�)rXrIr�rErGr`rrrI�s
zInetTestBase.setUpcCstj||jd�dS)N��host)rrDr�rHrrrrr��r�zInetTestBase.bindSock)	rOrPrQrgr�rrIr�rhrrr`rr�s
rc@r)�TCPTestBasez#Base class for TCP-over-IPv4 tests.cCrr8)rrBr5rGrrrr��rzTCPTestBase.newSocketNrrrrrr�rrc@r)�UDPTestBasez#Base class for UDP-over-IPv4 tests.cCrr8)rrBr$rGrrrr��rzUDPTestBase.newSocketNrrrrrr�rrc@r)�UDPLITETestBasez'Base class for UDPLITE-over-IPv4 tests.cC�t�tjtjtj�Sr8)rrBr$r>rGrrrr��r�zUDPLITETestBase.newSocketNrrrrrr�rrc@r)�SCTPStreamBasez;Base class for SCTP tests in one-to-one (SOCK_STREAM) mode.cCrr8)rrBr5�IPPROTO_SCTPrGrrrr��s�zSCTPStreamBase.newSocketNrrrrrr�rrc@seZdZdZejZdS)�
Inet6TestBasez!Base class for IPv6 socket tests.N)rOrPrQrgr�HOSTv6rrrrrr �s
r c@r)�UDP6TestBasez#Base class for UDP-over-IPv6 tests.cCrr8)r�AF_INET6r$rGrrrr��rzUDP6TestBase.newSocketNrrrrrr"�rr"c@r)�UDPLITE6TestBasez'Base class for UDPLITE-over-IPv6 tests.cCrr8)rr#r$r>rGrrrr��r�zUDPLITE6TestBase.newSocketNrrrrrr$�rr$cs*dd����fdd�}dd�}|r|S|S)aSkip decorated test if condition is true, add client_skip decorator.

    If the decorated object is not a class, sets its attribute
    "client_skip" to a decorator which will return an empty function
    if the test is to be skipped, or the original function if it is
    not.  This can be used to avoid running the client part of a
    skipped test when using ThreadableTest.
    c_r�r8r�r^r_rrr�client_passr�z%skipWithClientIf.<locals>.client_passcs*t���|�}t|t�s�fdd�|_|S)Ncs�Sr8r�r)r&rr�<lambda>
�z3skipWithClientIf.<locals>.skipdec.<locals>.<lambda>)r��skip�
isinstance�type�client_skip)�obj�retval�r&�reasonrr�skipdecs
z!skipWithClientIf.<locals>.skipdeccSs"t|t�st|d�sdd�|_|S)Nr-cSs|Sr8rr'rrrr(r)z5skipWithClientIf.<locals>.noskipdec.<locals>.<lambda>)r+r,rr-�r.rrr�	noskipdecs
z#skipWithClientIf.<locals>.noskipdecr)�	conditionr1r2r4rr0r�skipWithClientIf�s	r6cs0�fdd�|D�}t|dd�dd�|D���S)z�Skip decorated test if obj is missing any of the given attributes.

    Sets client_skip attribute as skipWithClientIf() does.
    csg|]	}t�|�s|�qSr)r��.0�namer3rr�
<listcomp>�z requireAttrs.<locals>.<listcomp>�don't have �, cs��|]}|VqdSr8rr7rrr�	<genexpr>��zrequireAttrs.<locals>.<genexpr>)r6�join)r.�
attributes�missingrr3r�requireAttrss�rDc
Gs�d}dd�|D�}|rdd�dd�|D��}n)dd�|D�}ztj|�}Wnty<}z
t|�}WYd}~n	d}~ww|��t|dud	�d�d
d�|D��|��S)aSkip decorated test if a socket cannot be created with given arguments.

    When an argument is given as a string, will use the value of that
    attribute of the socket module, or skip the test if it doesn't
    exist.  Sets client_skip attribute as skipWithClientIf() does.
    NcSs$g|]}t|t�rtt|�s|�qSr)r+�strrr�r8r.rrrr:%s
�
�z!requireSocket.<locals>.<listcomp>r<r=csr>r8rr7rrrr?(r@z requireSocket.<locals>.<genexpr>cSs$g|]}t|t�rtt|�n|�qSr)r+rEr�rrFrrrr:*s�zcan't create socket({0}): {1}css�|]}t|�VqdSr8)rE�r8�orrrr?6s�)rArrrErr6�format)r^�errrC�callargsr!r�rrr�
requireSockets(�����rLc@s�eZdZdd�Zdd�Ze�edud�dd��Zd	d
�Z	dd�Z
d
d�Zdd�Zdd�Z
e�ejdkd�dd��Ze�ejdkd�e�ejd�dd���Zdd�Zdd�Zd d!�Ze�eed"�d#�e�eed$�d%�d&d'���Ze�eed(�d)�d*d+��Ze�eed,�d-�d.d/��Ze�eed0�d1�d2d3��Ze�eed4�d5�d6d7��Zd8d9�Z d:d;�Z!e"j#d<d=��Z$d>d?�Z%d@dA�Z&e�eedB�dC�dDdE��Z'e�eedF�dG�dHdI��Z(e�eedF�dG�dJdK��Z)e�eedL�dM�dNdO��Z*e�eedL�dM�dPdQ��Z+dRdS�Z,dTdU�Z-dVdW�Z.dXdY�Z/dZd[�Z0d\d]�Z1d^d_�Z2e�ejdkd�d`da��Z3e�ejdkd�e�eedb�dc�ddde���Z4dfdg�Z5dhdi�Z6e�e"�7dj�dk�dldm��Z8dndo�Z9dpdq�Z:drds�Z;dtdu�Z<dvdw�Z=dxdy�Z>dzd{�Z?d|d}�Z@d~d�ZAd�d��ZBd�d��ZCe"j#d�d���ZDe�ejd��d�d���ZEe�ejd��d�d���ZFd�d��ZGe�ejd��e�Hejd�kd��e�HeId��e�eed(�d��d�d������ZJe�ejd��e�ejd�kd��d�d����ZKe�ejd��e�Hejd�kd��e�HeId��e�eed(�d��d�d������ZLe�ejd��e�ejd�kd��d�d����ZMd�d��ZNd�d��ZOd�d��ZPe�eed��d��d�d���ZQd�d��ZRd�d��ZSd�d��ZTd�d��ZUd�d��ZVe�Hejdkd��d�d���ZWd�d��ZXd�d��ZYdS)��GeneralModuleTestscCs<ddl}|�tj|ju�t��}|�|tj�|��dSr�)�_socket�
assertTruer�
SocketType�assertIsInstancer)rHrNr!rrr�test_SocketType_is_socketobject>s
z2GeneralModuleTests.test_SocketType_is_socketobjectcCs�t�tjtj�}|�S|�d|��t|��|�dtjt|��|�dtjt|��|�dt|��|�dt|��|�d�|�dt|��|�t|�	��t|��Wd�n1s`wY|�dt|��|�dt|��dS)	Nzfd=%iz	family=%sztype=%szproto=0�raddr��	127.0.0.1r�laddrz[closed])
rrBr5�assertIn�fileno�repr�assertNotInrprEr��rHr!rrr�	test_reprEs
�	zGeneralModuleTests.test_reprNzneed _socket modulecCszt�tjtj�}zd|��|j|j|jf}|�t	|�|�W|�
�n|�
�wd|j|j|jf}|�t	|�|�dS)Nz4<socket object, fd=%s, family=%s, type=%s, proto=%s>z4<socket object, fd=-1, family=%s, type=%s, proto=%s>)rNrrBr5rX�familyr,�protor�rYr)rHr!�expectedrrr�test_csocket_reprSs��z$GeneralModuleTests.test_csocket_reprcCs�t�tjtj��}t|�}|�|��|���Wd�n1s!wYd}t��z|��Wn
ty<YdSw|�	d�dS)NzSocket proxy still exists)
rrBr5rr�rXr�
gc_collect�ReferenceError�fail)rHr!�prrr�test_weakref`s��zGeneralModuleTests.test_weakrefcCs�d}|jt|dd��t�1swY|jt|dd��tj�1s&wY|jt|dd��tj�1s;wYdS)Nz$Error raising socket exception (%s).r�r�z
socket.herrorzsocket.gaierror)�assertRaisesrr�herror�gaierrorr�rrr�testSocketErrorms���z"GeneralModuleTests.testSocketErrorcCs�t�tjtj�}|�|j�|�d�|��}|�t��}|�	d|�Wd�n1s-wY|�
t|j�d�|�t��}|�	d|�Wd�n1sQwY|�
t|j�d�|�t��}|�	dd�Wd�n1suwY|�
dt|j��|�t��}|�	dd|�Wd�n1s�wY|�
t|j�d�|�t��}|�	dd|�Wd�n1s�wY|�
t|j�d�|�t��}|�	ddd�Wd�n1s�wY|�
dt|j��|�t��}|�	dd	|�Wd�n	1�s
wY|�t��}|�	ddd�Wd�n	1�s'wY|�t��
}|�	d�Wd�n	1�sBwY|�
d
t|j��|�t��}|�	dd|d�Wd�n	1�siwY|�
dt|j��dS)
N)�ru☠z*a bytes-like object is required, not 'str'y@z.a bytes-like object is required, not 'complex'�fooznot NoneTyper�barz	(1 given)�z	(4 given))rrBr$rdrrpr�rgr��sendtor�rE�	exceptionrW)rHr!�sockname�cmrrr�testSendtoErrorswsd
��������������z#GeneralModuleTests.testSendtoErrorscCs@tjtjr	tjtjtjtjtjtjtj	tj
dSr8)rrB�has_ipv6r#r5r$r�SOCK_RDMr+�
SOL_SOCKET�SO_REUSEADDRrGrrr�testCrucialConstants�s
z'GeneralModuleTests.testCrucialConstantscCs tjtjtjrtjdSdSr8)r�IPPROTO_TCP�IPPROTO_UDPrt�IPPROTO_IPV6rGrrr�testCrucialIpProtoConstants�s

�z.GeneralModuleTests.testCrucialIpProtoConstants�nt�Windows specificcC�4tjtjtjtjtjtjtjtjdSr8)	r�IPPROTO_ICLFXBM�
IPPROTO_ST�IPPROTO_CBT�IPPROTO_IGP�IPPROTO_RDP�IPPROTO_PGM�IPPROTO_L2TPrrGrrr�testWindowsSpecificConstants�s
z/GeneralModuleTests.testWindowsSpecificConstants�darwin�macOS specific test�IPv6 required for this testcCs0hd�}|D]}|�tt|�d|�d��qdS)N>�
IPV6_RTHDR�IPV6_TCLASS�IPV6_DSTOPTS�IPV6_HOPOPTS�IPV6_NEXTHOP�IPV6_PATHMTU�IPV6_PKTINFO�
IPV6_CHECKSUM�
IPV6_DONTFRAG�
IPV6_HOPLIMIT�IPV6_RECVRTHDR�IPV6_RECVTCLASS�IPV6_RECVDSTOPTS�IPV6_RECVHOPOPTS�IPV6_RECVPATHMTU�IPV6_RECVPKTINFO�IPV6_USE_MIN_MTU�IPV6_RECVHOPLIMIT�IPV6_RTHDRDSTOPTS�IPV6_RTHDR_TYPE_0zMissing RFC3542 socket option '�')rOrr)rH�opts�optrrr�test3542SocketOptions�s��z(GeneralModuleTests.test3542SocketOptionscCs�t��}zt�|�}Wnty|�d�Ynw|�|�d�dkd�z
t�|�\}}}Wnty=|�d�Ynw||g|}t�|�}||vrZ|�	d|t
|�f�dSdS)N�name lookup failurer�rzError resolving host to ip.z=Error testing host resolution mechanisms. (fqdn: %s, all: %s))r�gethostname�
gethostbynamerrrrO�find�
gethostbyaddr�getfqdnrcrY)rH�hostname�ip�hname�aliases�ipaddrs�all_host_names�fqhnrrr�testHostnameRes�s"��
�z"GeneralModuleTests.testHostnameRescCsLtjddfD]}|�t�|�|�qtjfD]
}|�|t�|�d�qdS)Nz10.0.0.1�255.255.255.255r�)r�HOSTv4r�rr�rWr�)rHr�rrrr�test_host_resolution�s
�z'GeneralModuleTests.test_host_resolutionc	Cs�d}dD]:}|jt|d��
t�|�Wd�n1swY|jt|d��
t�|�Wd�n1s9wYqdS)Nz[resolving an invalid IP address did not raise OSError; can be caused by a broken DNS server)z0.1.1.~1z1+.1.1.1z::1qz::1::2z1:1:1:1:1:1:1:1:1rf)rgrrr�r�)rH�explanationr�rrr� test_host_resolution_bad_address�s�����z3GeneralModuleTests.test_host_resolution_bad_address�sethostnameztest needs socket.sethostname()r�ztest needs socket.gethostname()c
Cs�t��}zt�d�Wnty*}z|jtjkr|�d�n�WYd}~nd}~wwz|�t��d�t�d�|�t��d�Wt�|�dSt�|�w)N�newztest should be run as rootsbarrm)rr�r�r�errno�EPERMrrr�)rH�oldhnr�rrr�test_sethostname	s���
z#GeneralModuleTests.test_sethostname�if_nameindexz$socket.if_nameindex() not available.cCs�t��}|D]8\}}|�|t�|�|t�|�|d�t�|�}|�|t�|�||�t�|�}|�|t�|�||�qdSr�)	rr�rQ�intrE�
assertGreater�if_nametoindexr��if_indextoname)rH�
interfaces�indexr9�_index�_namerrr�testInterfaceNameIndexs

�z)GeneralModuleTests.testInterfaceNameIndexr�z&socket.if_indextoname() not available.cC�$|�ttjd�|�ttjd�dS�Nr�	_DEADBEEF)rgrrr�r�rGrrr�testInvalidInterfaceIndexToName-�z2GeneralModuleTests.testInvalidInterfaceIndexToNamer�z&socket.if_nametoindex() not available.cCr�r�)rgr�rr�rrGrrr�testInvalidInterfaceNameToIndex3r�z2GeneralModuleTests.testInvalidInterfaceNameToIndex�getrefcountztest needs sys.getrefcount()cCsPzt�t�}t�td�WdSty't�t�|kr$|�d�YdSYdSw)Nrz$socket.getnameinfo loses a reference)�sysr�rOr�getnameinfor�rc)rH�origrrr�testRefCountGetNameInfo9s
��z*GeneralModuleTests.testRefCountGetNameInfocCs(z	t�dd�WdStyYdSw)N)rlrrrr)rr�rrGrrr�testInterpreterCrashEs
�z'GeneralModuleTests.testInterpreterCrashc	Cs�tjdtjdtjdtjdi}|��D]2\}}d|>d}dD]}|�||@||||@��|@�q||�}|�||@|�|�t|d�qdS)N� �r�)rr��i��r�igE#i2Tvl)	r�htonl�ntohl�htons�ntohs�itemsr�rg�
OverflowError)rH�sizes�func�size�maskr?�swappedrrr�testNtoHMs�"�zGeneralModuleTests.testNtoHcCs�ddl}gd�}|dg}ddddd>g}||jd|jdgd	|jg}|D]}t�|�t�|�q(|D]}t�|�t�|�q7|D]}|�t	tj|�|�t	tj|�qF|D]}|�t	tj|�|�t	tj|�q[dS)
Nr)rr�r�r����������lr����)
�	_testcapi�INT_MIN�INT_MAXrr�r�r�r�rgr�)rHr��
s_good_values�
l_good_values�l_bad_values�s_bad_values�krrr�testNtoHErrors[s.
���

�z!GeneralModuleTests.testNtoHErrorsc	Cs|j}tj�d�stjdvrd}nd}|D]}z	t�|d�}Wnty)Yqwt�ttd�r7t��dkrAt�|�}|||�zt�|d�}WntyTd}Ynw|||�t	j
se|t�|�|�|t�|d�|�|dur{|t�|d�|�|�t
tjd	�|�t
tjd
�dS)N)�freebsd�netbsd�gnukfreebsd)�linuxr�)�daytime�qotd�domain)�echor�r��tcp�getandroidapilevel��udpr�r�)r�r��platform�
startswithr�
getservbynamerrr�r�
is_android�
getservbyportrgr�)rH�eq�services�servicerE�port2�udpportrrr�
testGetServByss<
�


�
z GeneralModuleTests.testGetServByc	Cs.|�t��d�t���}|�|��d�Wd�n1swYtd��U|�t��d�t���}|�|��d�Wd�n1sHwYt�d�|�t��d�t���}|�|��d�Wd�n1sqwYWd�n1s�wY|�ttjd�|�ttjd�dS)N�
r��spam)	r�rr9�
gettimeoutr=r:rg�
ValueErrorr�)rHr!rrrr�testDefaultTimeout�s$
�

�

���z%GeneralModuleTests.testDefaultTimeout�	inet_atonztest needs socket.inet_aton()cCs(|�dt�d��|�dt�d��dS)N��0.0.0.0�����r�)r�rrrGrrr�testIPv4_inet_aton_fourbytes�sz/GeneralModuleTests.testIPv4_inet_aton_fourbytes�	inet_ptonztest needs socket.inet_pton()cs*ddlm}m�m���fdd�}�fdd�}��d|d����d|d	����d
|d����d|d
����d|d��tsF||d�||d�||d�||d�||d���d|d����d|d	����d
|d����d|d��||d�||d�||d�||d�||d�dS)Nr)rrrBc�
��|�Sr8r��a)rBrrrr(��
z5GeneralModuleTests.testIPv4toString.<locals>.<lambda>c���ttf||�Sr8�rgrr	�r�rrGrrr(��
�rr
s��z255.0.255.0s����z170.170.170.170��1.2.3.4rr�z0.0.0.z	300.0.0.0za.0.0.0z	1.2.3.4.5�::1)rrrrBr�r	�rHr�g�
assertInvalidr)rBrrHr�testIPv4toString�s.








z#GeneralModuleTests.testIPv4toStringc
s�zddlm�m�m}|s��d�Wnty!��d�YnwtjdkrKz��d�WntyJ}z|j	dkr@��d�WYd}~nd}~ww��fd	d
����fdd
�}��
d�d����
d�d
����
d�d����
d�d����
d�d����
d�d��|d�|d�|d�|d�|d�|d�|d�|d�ts�|d���
d�d ����
d!�d"����
d#�d$��|d%�|d&�|d'�|d(�|d)�|d*�dS)+Nr)rr#rt�IPv6 not available�+could not import needed symbols from socket�win32�::�&'�IPv6 might not be supportedcrr8rr)r#rrrr(�rz5GeneralModuleTests.testIPv6toString.<locals>.<lambda>c���ttf�|�Sr8rr�rrHrrr(�r�z0::0sz1::sE�v�V���$��z$45ef:76cb:1a:56ef:afeb:bac:1924:aeaes�B
�'Tzad42:abc::127:0:254:2s
z12:a::z0x20::z:::z::0::z1::abc::z1::abc::defz1:2:3:4:5:6z1:2:3:4:5:6:z1:2:3:4:5:6:7:8:0z1:2:3:4:5:6:7:8:s�*@z::254.42.23.64sB���*@z42::a29b:254.42.23.64sB�������*@z"42:a8b9:0:2:ffff:a29b:254.42.23.64z255.254.253.252z1::260.2.3.0z1::0.be.e.0z1:2:3:4:5:6:7:1.2.3.4z::1.2.3.4:0z0.100.200.0:3:4:5:6:7:8)rrr#rtrr�ImportErrorr�r�r�winerrorr�r	�rHrtr�rr)r#rrrHr�testIPv6toString�sr
��


�������z#GeneralModuleTests.testIPv6toString�	inet_ntopztest needs socket.inet_ntop()csddlm}m�m���fdd�}�fdd�}��d|d����d|d	����d
|d����d|d
��||d�||d�||d���d|td	�����d|d����d|d	����d
|d��||d�||d�||d���d|td	���dS)Nr)�	inet_ntoar-rBcrr8rr)rBr-rrr(%rz5GeneralModuleTests.testStringToIPv4.<locals>.<lambda>crr8rrrGrrr(&rz1.0.1.0sz
170.85.170.85s�U�Ur�rrrssr()rr.r-rBr��	bytearrayrr)rBr-rHr�testStringToIPv4!s$





z#GeneralModuleTests.testStringToIPv4c
szddlm�m�m}|s��d�Wnty!��d�YnwtjdkrKz��d�WntyJ}z|j	dkr@��d�WYd}~nd}~ww��fd	d
����fdd
�}��
d�d����
d
�d����
d�d����
d
�td���|d�|d�|d�dS)Nr)r-r#rtr r!r"r(r$r%crr8rr)r#r-rrr(Lrz5GeneralModuleTests.testStringToIPv6.<locals>.<lambda>cr&r8rrr'rrr(Mrr#rsz!aef:b01:506:1001:ffff:9997:55:170s
�����Upsss)rr-r#rtrrr)r�r�rr*r�r/r+r)r#rr-rHr�testStringToIPv6;s8
��


���z#GeneralModuleTests.testStringToIPv6cCs�t�tjtj�}|�|j�t��D]-}t��}z	|�	d|f�Wnt
y>}z|jtjks3|dkr4�WYd}~qd}~ww|�
�}z	t�t���}Wnt
y[|�d�Ynw|�|dd|fd|d�|�|d|�dS)Nr
�r�rz
%s invalidr�)rrBr5rdr�	itertools�countr�find_unused_portrprr��
EADDRINUSEr�r�r�rrrWr�)rHrr?rEr�r9�
my_ip_addrrrr�testSockName_s*����zGeneralModuleTests.testSockNamecCs@t�tjtj�}|�|j�|�tjtj�}|�|dkd�dS)Nrzinitial mode is reuse)	rrBr5rdr�
getsockoptrvrw�assertFalse�rHr�reuserrr�testGetSockOpt|sz!GeneralModuleTests.testGetSockOptcCsRt�tjtj�}|�|j�|�tjtjd�|�tjtj�}|�	|dkd�dS)Nr�rzfailed to set reuse mode)
rrBr5rdr�
setsockoptrvrwr9r:r;rrr�testSetSockOpt�s
z!GeneralModuleTests.testSetSockOptcCsNt�tjtj��
}|�d�Wd�n1swY|�t|jd�dS)Nr��spam)rrBr5�
settimeoutrgrr�rrrr�testSendAfterClose�s�z%GeneralModuleTests.testSendAfterClosec
Cs�t��}|�tjdf�tj|��d���z|��Wnty:}z|�|jtjtj	f�WYd}~dSd}~ww|�
d�dS)Nr�rXz#close() should raise EBADF/ENOTSOCK)rrp�
_LOCALHOSTrXrrrWr��EBADF�ENOTSOCKrc)rHrrJrrr�testCloseException�s$��z%GeneralModuleTests.testCloseExceptioncCs�t�tjtj��4}|�|jtj�ttd�r%|�|jtjtjBtjf�n|�|jtj�|�|j	d�Wd�dS1s?wYdS)N�SOCK_CLOEXECr)
rrBr5r�r]rrWr,rHr^rrrr�testNewAttributes�s

��"�z$GeneralModuleTests.testNewAttributescCs�t��}|�|j�t��}|d}|d}|�t|jt|f�|�t|jt|f�t	�
�D].}t��}z|�t|f�WdSty\}z|jtj
ksQ|dkrR�WYd}~q.d}~wwdS)Nr�r2)rrdrrr5rgr�rpr�r3r4rr�r6)rHrrE�big_port�neg_portr?r�rrr�test_getsockaddrarg�s&�����z&GeneralModuleTests.test_getsockaddrargcCs�|�ttjd��|�ttd��|�ttd��|�ttd��|�ttd��t��}|�|j�|�t|jdd�|�tjd�dS)Nr�
SIO_RCVALL�	RCVALL_ON�
RCVALL_OFF�SIO_KEEPALIVE_VALSr�)r��drQ)	rOrrrdrrgr	rrPr[rrr�test_sock_ioctl�sz"GeneralModuleTests.test_sock_ioctl�SIO_LOOPBACK_FAST_PATHz1Loopback fast path support required for this testc
Csrt��}|�|j�z	|�tjd�Wnty,}z
d}|j|kr'|�d��d}~ww|�t	|jtjd�dS)NTi='zQSIO_LOOPBACK_FAST_PATH is defined but doesn't implemented in this Windows version)
rrdrrrSrr*rrrgr�)rHr!�exc�
WSAEOPNOTSUPPrrr�test_sio_loopback_fast_path�s

��z.GeneralModuleTests.test_sio_loopback_fast_pathc

Cs6zt�dd�Wntjy!}z|jtjkr|�d��d}~wwt�td�D]
}|�t|�d�q(t�dd�t�dd�t�dd�t	j
rNt�dd�ttd�rYt�
�dkr_t�td	�t�td�t�td�t�tdtjtj�}|D]%\}}}}}|�|tj�|�t|�d
�|�|tj�|�t|�d�qwt�tddtj�}|D]\}}}}}|�|tj�q�t�tdddtj�t�tddddtj�t�ddtjtjdtj�t�td�}tjtdd
�}	|�||	�t�tdtj�}tjtdtjd�}	|�||	�t�tddtj�}tjtdtjd�}	|�||	�t�tdddtj�}tjtdtjd�}	|�||	�t�tddddtj�}tjtdtjd�}	|�||	�t�ddtjtjdtj�}tjddtjtjdtjd�}	|�||	�|�ttjdd�ttd��r�zt�dddddtj�WdStj�y�YdSwdS)N�	localhost�Pzbuggy libc versionr2rUrr�r��http�AddressFamily.AF_INET�SocketKind.SOCK_STREAMr)rrE�r]�r,)r^)�flags)rrEr]r,r^r^u��AI_NUMERICSERV)r�getaddrinforir��EAI_SERVICErrr�r��lenr�IPV6_ENABLEDrr�r�rBr5rE�SOL_TCP�
AI_PASSIVE�	AF_UNSPECrg�UnicodeEncodeErrorr_)
rHrJ�info�infosr]r,r��socktyper�brrr�testGetaddrinfo�s�
��
���
���z"GeneralModuleTests.testGetaddrinfocCs|�ttjdd�dS)N)zmail.python.orgrr)rgrrr�rGrrr�test_getnameinfo)�z#GeneralModuleTests.test_getnameinfo�networkznetwork is not enabledcCsdt�d��
t�d�Wd�n1swYd}t�|�t�|�t�|dtjtj�dS)Nz
python.orgu!испытание.pythontest.netr)r�transient_internetrr��gethostbyname_exr`rfr5)rHr�rrr�	test_idna-s�

zGeneralModuleTests.test_idnac
s\ttd�r
ttd�s��d��fdd�}�fdd�}t��\}}t�tj|�}zp|r0|�d���t��t�	d	�|�
d
tj�Wd�n1sMwY|r�t�tj|�t�	d	���t
|j
d
tj�Wt�	d�t�tj|�|��|��dSWt�	d�t�tj|�|��|��dSt�	d�t�tj|�|��|��w)N�alarmr�z9signal.alarm and socket.socketpair required for this testcs��ttjd�dSr��rgr	�math�acosh�r^rGrr�
ok_handlerDr�z@GeneralModuleTests.check_sendall_interrupted.<locals>.ok_handlercs��ttjd�dddS�Nrr�rtrwrGrr�raising_handlerFszEGeneralModuleTests.check_sendall_interrupted.<locals>.raising_handlerg�?r��xr)r�signalrrrr��SIGALRMrArg�ZeroDivisionErrorrs�sendallr�
SOCK_MAX_SIZE�TimeoutErrorr)rH�with_timeoutrxrz�cr!�	old_alarmrrGr�check_sendall_interrupted>s@


�

�
�

�
z,GeneralModuleTests.check_sendall_interruptedcC�|�d�dS�NF�r�rGrrr�test_sendall_interrupted]�z+GeneralModuleTests.test_sendall_interruptedcCr�)NTr�rGrrr�%test_sendall_interrupted_with_timeout`r�z8GeneralModuleTests.test_sendall_interrupted_with_timeoutcCs�t�tjtj�}t|�}|�t��}d}t��Wd�n1s"wY|�|t	|j
jd��t�tjtj�}|�d�}t|�}d}t��|�t��d}t��Wd�dS1sawYdS)Nrr)
rrBr5rY�assertWarns�ResourceWarningrrarWrE�warningr^�makefile)rHrrrrrrrr�test_dealloc_warncs 
�

"�z$GeneralModuleTests.test_dealloc_warncCsXt�tjtj��}|�d�}|��|�t|�d�Wd�dS1s%wYdS)Nrz<_io.BufferedReader name=-1>)rrBr5r�rr�rY�rHr�fprrr�test_name_closed_socketiots

"�z,GeneralModuleTests.test_name_closed_socketiocCs�t���>}|jddd�}|�|���|�|���|�|���|��|�t	|j�|�t	|j�|�t	|j�Wd�dS1sEwYdS)Nrr)�	buffering)
rr�rO�readabler:�writable�seekablerrgr	r�rrr�test_unusable_closed_socketiozs
"�z0GeneralModuleTests.test_unusable_closed_socketiocCs2t��}zC|�tdf�t�|���|�t��
|�d�Wd�n1s(wYW|�t��|��Wd�n1sBwYn|�t��|��Wd�w1s\wYw|�t��
t�d�Wd�n1swwY|�t��t�d�Wd�dS1s�wYdS)Nrr�r�)	rrpr�rrXrgrrFr�rrrr�test_socket_close�s*��
��
��"�z$GeneralModuleTests.test_socket_closecCs�dD]R}|j|d��Bt���.}d|vrdnd}|j||d��}|�|j|�Wd�n1s1wYWd�n1s@wYWd�n1sOwYqdS)N)rr�rw�w�wb��moderkr��encoding)�subTestrr�r�r�)rHr�rr�r�rrr�test_makefile_mode�s
�������z%GeneralModuleTests.test_makefile_modecCs�dD]G}|j|d��7t���#}|�td��
|�|�Wd�n1s&wYWd�n1s5wYWd�n1sDwYqdS)N)�rtrl�+rr�zinvalid mode)r�r�assertRaisesRegexr	r�)rHr�rrrr�test_makefile_invalid_mode�s
�������z-GeneralModuleTests.test_makefile_invalid_modecCs�t��}|�ttjd�D]}|�ttj||�qWd�n1s$wYttjd�D]$}t�t�tj|��}|�	|tj�t�t�tj
|��}|�	|tj
�q0dSr)r�range�pickle�HIGHEST_PROTOCOLrgr��dumps�loadsrBr�r5)rHr�protocolr]r,rrr�test_pickle�s���zGeneralModuleTests.test_picklec	Cs�dD]&}t�tjtj��}|�tdf�|�|�Wd�n1s#wYqt�tjtj��}|�tdf�|��Wd�dS1sHwYdS)N)rr�r)rrBr5rpr�rF)rH�backlog�srvrrr�test_listen_backlog�s��
"�z&GeneralModuleTests.test_listen_backlogcCsbddl}t�tjtj��}|�tdf�|�t|j|j	d�Wd�dS1s*wYdSry)
r�rrBr5rpr�rgr�rFr�)rHr�r�rrr�test_listen_backlog_overflow�s
"�z/GeneralModuleTests.test_listen_backlog_overflow�IPv6 required for this test.cCsh|�ttjtjddfd�t�tjtj��}|�t|jtjddf�Wd�dS1s-wYdS)Nrr�i����)	rgr�rr�rr!r#r5rpr[rrr�
test_flowinfo�s
�"�z GeneralModuleTests.test_flowinfocCs0t�ddtjtjtj�\�^}}|�|d�dS)N�ff02::1de:c0:face:8Dr)�ff02::1de:c0:face:8drrr)rr`r#r$rzr�)rHr��sockaddrrrr�test_getaddrinfo_ipv6_basic�s�z.GeneralModuleTests.test_getaddrinfo_ipv6_basiccCs0|�t��t�d��|�t��t�d��dS)Nr
r#)r�rr�rGrrr�test_getfqdn_filter_localhost�sz0GeneralModuleTests.test_getfqdn_filter_localhostr"zdoes not work on WindowszSymbolic scope id does not workz test needs socket.if_nameindex()cCsLt��d\}}t�d|dtjtjtj�\�^}}|�|ddd|f�dS)Nr�ff02::1de:c0:face:8D%rr�)rr�r`r#r$rzr�)rH�ifindex�test_interfacer�r�rrr�&test_getaddrinfo_ipv6_scopeid_symbolic�s�z9GeneralModuleTests.test_getaddrinfo_ipv6_scopeid_symbolicz.Numeric scope id does not work or undocumentedcCsDd}t�dt|�dtjtjtj�\�^}}|�|ddd|f�dS)N�*r�rr�r)rr`rEr#r$rzr�)rHr�r�r�rrr�%test_getaddrinfo_ipv6_scopeid_numeric�s
�z8GeneralModuleTests.test_getaddrinfo_ipv6_scopeid_numericcCsHt��d\}}ddd|f}t�|tjtjB�}|�|d|df�dS)Nrr�r�ff02::1de:c0:face:8d%�1234)rr�r��NI_NUMERICHOST�NI_NUMERICSERVr�)rHr�r�r��nameinforrr�&test_getnameinfo_ipv6_scopeid_symbolic�sz9GeneralModuleTests.test_getnameinfo_ipv6_scopeid_symboliccCs@d}ddd|f}t�|tjtjB�}|�|dt|�df�dS)Nr�r�rrr�r�)rr�r�r�r�rE)rHr�r�r�rrr�%test_getnameinfo_ipv6_scopeid_numericsz8GeneralModuleTests.test_getnameinfo_ipv6_scopeid_numericcCsZt�tjtj��}|�t|j�d�|�t|j�d�Wd�dS1s&wYdS)NrZr[)rrBr5r�rEr]r,r[rrr�test_str_for_enums
s"�z%GeneralModuleTests.test_str_for_enumscCs�ttdd�}ttdd�}tj|B|B}t�tj|��E}|�|jtj�|�d�|�|jtj�|�d�|�|jtj�|�d�|�|jtj�|�d�|�|jtj�Wd�dS1sbwYdS)N�
SOCK_NONBLOCKrrHr�TF)r�rr5rBr�r,rA�setblocking)rHr�rH�	sock_typer!rrr� test_socket_consistent_sock_types



"�z3GeneralModuleTests.test_socket_consistent_sock_typecCs�t�tjtj�}|��}ttjj���d}tdd�tjj�	�D��d}tj||d|d�� }|�
|j|�|�
|j|�|�
|jddh�Wd�dS1sQwYdS)Nr�css �|]\}}|dvr|VqdS)>rHr�Nr)r8r9�kindrrrr?/s���zEGeneralModuleTests.test_unknown_socket_family_repr.<locals>.<genexpr>r�)r]r,r^rXr)rrBr5�detach�max�
AddressFamily�__members__�values�
SocketKindr�r�r]r,rWr^)rHr�fd�unknown_family�unknown_typer!rrr�test_unknown_socket_family_repr$s"
���"�z2GeneralModuleTests.test_unknown_socket_family_repr�sendfileztest needs os.sendfile()c	CsGdd�d�}t���u}t�tjtj�}t�|�|�tj��|�||��Wd�n1s1wY|�t	��|�|dd��Wd�n1sOwY|�t
��|�|d��Wd�n1skwYWd�dSWd�dS1s�wYdS)Nc@r@)z<GeneralModuleTests.test__sendfile_use_sendfile.<locals>.FilecSs
||_dSr8�r�)rHr�rrrrY@�
zEGeneralModuleTests.test__sendfile_use_sendfile.<locals>.File.__init__cS�|jSr8r�rGrrrrXCszCGeneralModuleTests.test__sendfile_use_sendfile.<locals>.File.filenoN)rOrPrQrYrXrrrr�File?sr�r�r�)rrr�curdir�O_RDONLYrrg�_GiveupOnSendfile�_sendfile_use_sendfiler�r�)rHr�rr�rrr�test__sendfile_use_sendfile=s 

����"�z.GeneralModuleTests.test__sendfile_use_sendfilecCst|�|j|�|�|j|�|��}tj|d�}|�|j�|��|�|j|�|�|j|�|�|��|�dS�NrC)r�r]r,rXrrdrr�)rHr!r]�styper��s2rrr�_test_socket_filenoOsz&GeneralModuleTests._test_socket_filenocCsRt�tjtj�}|�|j�|�tjdf�|�|tjtj�t	td�rCt�tjtj
�}|�|j�|�tjdf�|�|tjtj
�tjrgt�tjtj�}|�|j�|�tj
dddf�|�|tjtj�t	td�r�t��}|�tj|�t�tjtj�}|�|j�z|�tj�|d��Wn
ty�YdSw|�|tjtj�dSdS)Nrr$rr)rrBr5rdrrprr�r�rr$rcr#r!rr�shutil�rmtreerrr
rA�PermissionError)rHr!�tmpdirrrr�test_socket_fileno\s8

�
��z%GeneralModuleTests.test_socket_filenocC�D|�t��tjtjtjdd�Wd�dS1swYdS)Ng@E@rC�rgr�rrBr5rGrrr� test_socket_fileno_rejects_float{�"�z3GeneralModuleTests.test_socket_fileno_rejects_floatcCr�)N�foorCr�rGrrr�&test_socket_fileno_rejects_other_typesr�z9GeneralModuleTests.test_socket_fileno_rejects_other_typescC�F|�td��tjtjtjdd�Wd�dS1swYdS)N�negative file descriptorr�rC�r�r	rrBr5rGrrr�)test_socket_fileno_rejects_invalid_socket�s"�z<GeneralModuleTests.test_socket_fileno_rejects_invalid_socketzWindows disallows -1 onlycCr�)Nr�i���rCr�rGrrr�#test_socket_fileno_rejects_negative�s"�z6GeneralModuleTests.test_socket_fileno_rejects_negativecCs�d}|�t��}tjt��d�Wd�n1swY|�|jjtj|f�|�t��}tjtj	tj
t��d�Wd�n1sFwY|�|jjtj|f�dS)Ni6'rC)rgrrr�make_bad_fdrWrpr�rErBr5)rH�WSAENOTSOCKrrrrr�$test_socket_fileno_requires_valid_fd�s���z7GeneralModuleTests.test_socket_fileno_requires_valid_fdc	Cs�t���P}|�t��tj|��d�Wd�n1swY|�t��}tjtjtj|��d�Wd�n1s>wY|�|j	j
t
j�Wd�dS1sWwYdSr�)r�NamedTemporaryFilergrrrXrBr5r�rpr�rF)rH�afilerrrrr�%test_socket_fileno_requires_socket_fd�s
���"�z8GeneralModuleTests.test_socket_fileno_requires_socket_fd)ZrOrPrQrRr\r��
skipUnlessrNr`rerjrsrxr|rr9r�r�r�rrcr�r�r�r�rrr�r�r�r�r�r�r�r�cpython_onlyr�rr
rrr,r0r1r8r=r?rBrGrIrLrRrVrlrm�is_resource_enabledrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r��skipIfr	r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrM<s


*


	�
�
�
�


,�
�
�
>�
�
"

�
N�




	
�

�



rMz!SocketCan required for this test.c@s�eZdZdd�Ze�eed�d�dd��Zdd�Z	e�eed�d�d	d
��Z
dd�Zd
d�Ze�eed�d�dd��Z
e�eed�d�dd��ZdS)�BasicCANTestcCstjtjtjdSr8)r�AF_CANrrrGrrrrx�s
z!BasicCANTest.testCrucialConstants�CAN_BCM�&socket.CAN_BCM required for this test.cC�tjtjtjtjtjtjtjtjtj	tj
tjtjtj
tjtjtjtjtjtjtjtjtjtjtjdSr8)rr�CAN_BCM_TX_SETUP�CAN_BCM_TX_DELETE�CAN_BCM_TX_READ�CAN_BCM_TX_SEND�CAN_BCM_RX_SETUP�CAN_BCM_RX_DELETE�CAN_BCM_RX_READ�CAN_BCM_TX_STATUS�CAN_BCM_TX_EXPIRED�CAN_BCM_RX_STATUS�CAN_BCM_RX_TIMEOUT�CAN_BCM_RX_CHANGED�CAN_BCM_SETTIMER�CAN_BCM_STARTTIMER�CAN_BCM_TX_COUNTEVT�CAN_BCM_TX_ANNOUNCE�CAN_BCM_TX_CP_CAN_ID�CAN_BCM_RX_FILTER_ID�CAN_BCM_RX_CHECK_DLC�CAN_BCM_RX_NO_AUTOTIMER�CAN_BCM_RX_ANNOUNCE_RESUME�CAN_BCM_TX_RESET_MULTI_IDX�CAN_BCM_RX_RTR_FRAMErGrrr�testBCMConstants�s0
zBasicCANTest.testBCMConstantscC�:t�tjtjtj��	}Wd�dS1swYdSr8�rrrrr[rrr�testCreateSocket��"�zBasicCANTest.testCreateSocketcCrr8)rrr$rr[rrr�testCreateBCMSocket��"�z BasicCANTest.testCreateBCMSocketcCsXt�tjtjtj��}d}|�|�|�|��|�Wd�dS1s%wYdS)N)rk)rrrrrpr�r�)rHr!�addressrrr�testBindAny�s

"�zBasicCANTest.testBindAnycCsLt�tjtjtj��}|�td|jd�Wd�dS1swYdS)N�interface name too long)�xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)rrrrr�rrpr[rrr�testTooLongInterfaceName�s
�"�z%BasicCANTest.testTooLongInterfaceName�CAN_RAW_LOOPBACKz/socket.CAN_RAW_LOOPBACK required for this test.c	Csnt�tjtjtj��#}dD]}|�tjtj|�|�||�tjtj��q
Wd�dS1s0wYdS)N)rr�)	rrrrr>�SOL_CAN_RAWr&r�r9)rHr!�loopbackrrr�testLoopback�s���"�zBasicCANTest.testLoopback�CAN_RAW_FILTERz-socket.CAN_RAW_FILTER required for this test.c	Cs�d\}}t�d||�}t�tjtjtj��*}|�tjtj|�|�	||�
tjtjd��|�tjtjt|��Wd�dS1sBwYdS)N)�iz=IIrm)r�packrrrrr>r'r*r�r9r/)rH�can_id�can_mask�
can_filterr!rrr�
testFilter�s�"�zBasicCANTest.testFilterN)rOrPrQrxr�r�rrrrrr"r%r)r0rrrrr��s*�
�
�
�r�c@s�eZdZddd�Zedd��Zedd��Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Ze
�eed�d�dd��Ze
�eed�d�dd��ZdS)�CANTestr�cCr�r�)r�rYr�rrrrY�r�zCANTest.__init__cCs&t|�}|�dd�}t�|j|||�S)zBuild a CAN frame.rm�)rb�ljustrr,rt)�clsr-�data�can_dlcrrr�build_can_frameszCANTest.build_can_framecCs&t�|j|�\}}}|||d|�fS)zDissect a CAN frame.N)rrrt)r4�framer-r6r5rrr�dissect_can_frameszCANTest.dissect_can_framecCs6|j�|j�\}}|�|j|�|�|d|j�dSr�)r!�recvfromrsr��cfrq�rHr;r�rrr�
testSendFrame
szCANTest.testSendFramecC� |�dd�|_|j�|j�dS)Nrs�r7r;r�r�rGrrr�_testSendFrame�zCANTest._testSendFramecCs$|j�|j�\}}|�|j|�dSr8)r!r:rsr�r;r<rrr�testSendMaxFramerSzCANTest.testSendMaxFramecCr>)Nrsr?rGrrr�_testSendMaxFramerAzCANTest._testSendMaxFramecC�D|j�|j�\}}|�|j|�|j�|j�\}}|�|j|�dSr8)r!r:rsr��cf1�cf2r<rrr�testSendMultiFrames�zCANTest.testSendMultiFramescCs<|�dd�|_|j�|j�|�dd�|_|j�|j�dS)N�sD3"�s�"3)r7rEr�r�rFrGrrr�_testSendMultiFrames%szCANTest._testSendMultiFramesrrcCsP|j�|j�\}}|�|j|�|�|�\}}}|�|j|�|�|j|�dSr8)r�r:rsr�r;r9r-r5)rHr;r�r-r6r5rrr�_testBCM,s
zCANTest._testBCMcCs�t�tjtjtj�}|�|j�|�|jf�d|_t	gd��|_
|�|j|j
�|_tj
}d}d}d}}}}d}	d}
t|j�dksFJ�t�|j||||||||	|
�
}||j}|�|�}
|�|
t|��dS)N�#)����ri"r�r�)rrr$rrdrr�rqr-�bytesr5r7r;rrbrr,rwr�r�)rH�bcm�opcoder^r4�
ival1_seconds�
ival1_usec�
ival2_seconds�
ival2_usec�
bcm_can_id�nframes�header�header_plus_frame�
bytes_sentrrr�testBCM5s6�

zCANTest.testBCMNr�)rOrPrQrY�classmethodr7r9r=r@rBrCrGrKr�r�rrrLr]rrrrr1�s(


�
�r1z!CAN ISOTP required for this test.csVeZdZ�fdd�Zdd�Zdd�Ze�ee	d�d�d	d
��Z
dd�Zd
d�Z�Z
S)�	ISOTPTestc�t�j|i|��d|_dS�Nrj�rXrYrqr]r`rrrYX�
zISOTPTest.__init__cCstjtjtjtjdSr8)rr�rr%r$rGrrrrx\s
zISOTPTest.testCrucialConstantscCrr8rr[rrrrbrzISOTPTest.testCreateSocketr%z(socket.CAN_ISOTP required for this test.cCrr8)rrr$r%r[rrr�testCreateISOTPSocketfr zISOTPTest.testCreateISOTPSocketc	Cs�t�tjtjtj��,}|�td��
|�d�Wd�n1s!wYWd�dSWd�dS1s9wYdS)Nr#)r$r�r�)rrr$r%r�rrpr[rrrr%ls��"�z"ISOTPTest.testTooLongInterfaceNamec
Cs�z2t�tjtjtj��}|jddf}|�|�|�|��|�Wd�WdS1s+wYWdStyU}z|j	t	j
krI|�d|j�n�WYd}~dSd}~ww)NrMiVro)rrr$r%rqrpr�r�rr��ENODEVrr�rHr!r�r�rrr�testBindrs
&�����zISOTPTest.testBind)rOrPrQrYrxrr�r�rrrdr%rgrhrrr`rr_Us�
r_z!CAN J1939 required for this test.csXeZdZ�fdd�Ze�eed�d�dd��Ze�eed�d�dd��Z	d	d
�Z
�ZS)�	J1939Testcr`rarbr]r`rrrY�rczJ1939Test.__init__r'z(socket.CAN_J1939 required for this test.cCrr8)rr'�J1939_MAX_UNICAST_ADDR�J1939_IDLE_ADDR�
J1939_NO_ADDR�
J1939_NO_NAME�J1939_PGN_REQUEST�J1939_PGN_ADDRESS_CLAIMED�J1939_PGN_ADDRESS_COMMANDED�J1939_PGN_PDU1_MAX�
J1939_PGN_MAX�J1939_NO_PGN�SO_J1939_FILTER�SO_J1939_PROMISC�SO_J1939_SEND_PRIO�SO_J1939_ERRQUEUE�SCM_J1939_DEST_ADDR�SCM_J1939_DEST_NAME�SCM_J1939_PRIO�SCM_J1939_ERRQUEUE�
J1939_NLA_PAD�J1939_NLA_BYTES_ACKED�J1939_EE_INFO_NONE�J1939_EE_INFO_TX_ABORT�J1939_FILTER_MAXrGrrr�testJ1939Constants�s0
zJ1939Test.testJ1939ConstantscCrr8)rrr$r'r[rrr�testCreateJ1939Socket�r zJ1939Test.testCreateJ1939Socketc
Cs�z6t�tjtjtj��!}|jtjtjtjf}|�|�|�	|�
�|�Wd�WdS1s/wYWdStyY}z|jtj
krM|�d|j�n�WYd}~dSd}~wwrn)rrr$r'rqrlrrrkrpr�r�rr�rerrrfrrrrg�s
&�����zJ1939Test.testBind)rOrPrQrYr�r�rrr�r�rgrhrrr`rrh�s�
!�
rhz#RDS sockets required for this test.c@s$eZdZdd�Zdd�Zdd�ZdS)�BasicRDSTestcCstjtjdSr8)r�AF_RDSr*rGrrrrx�s
z!BasicRDSTest.testCrucialConstantscCs8t�tjtjd��	}Wd�dS1swYdSr�)rr*r+r[rrrr�s"�zBasicRDSTest.testCreateSocketcCs`d}t�tjtjd��}|�tjtj|�|�tjtj|�Wd�dS1s)wYdS)Ni@r)rr*r+r>rv�	SO_RCVBUF�	SO_SNDBUF)rHrsr!rrr�testSocketBufferSize�s
"�z!BasicRDSTest.testSocketBufferSizeN)rOrPrQrxrr�rrrrr��sr�cs�eZdZddd�Z�fdd�Zdd�Zdd	�Zd
d�Zdd
�Ze	e
j
d�dd��Ze	e
j
d�dd��Zdd�Z
dd�Zdd�Zdd�Z�ZS)�RDSTestr�cCr�r�)r�rYr�rrrrY�r�zRDSTest.__init__cst���t��|_dSr8)rXrIrZr��evtrGr`rrrI�r�z
RDSTest.setUpcCs2|j�|j�\}}|�|j|�|�|j|�dSr8)rCr:rsr�r5r��rHr5r�rrr�testSendAndRecv�szRDSTest.testSendAndRecvcC�"d|_|j�|jdt|jf�dS�Nr@r�r5r�ror�rErGrrr�_testSendAndRecv��zRDSTest._testSendAndRecvcCsH|j�|jtj�\}}|�|j|�|j�|j�\}}|�|j|�dSr8)rCr:rsr�MSG_PEEKr�r5r�rrr�testPeek�szRDSTest.testPeekcCr�r�r�rGrrr�	_testPeek�r�zRDSTest._testPeek�recvmsgcCs(|j�|j�\}}}}|�|j|�dSr8)rCr�rsr�r5)rHr5�ancdata�	msg_flagsr�rrr�testSendAndRecvMsg�szRDSTest.testSendAndRecvMsg�sendmsgcCs&d|_|j�|jgddt|jf�dS)Ns<hello hello hello hello hello hello hello hello hello hello rr)r5r�r�r�rErGrrr�_testSendAndRecvMsg�s zRDSTest._testSendAndRecvMsgcCrDr8)rCr:rsr��data1�data2r�rrr�testSendAndRecvMulti�rHzRDSTest.testSendAndRecvMulticCs@d|_|j�|jdt|jf�d|_|j�|jdt|jf�dS)Nsbaconrsegg)r�r�ror�rEr�rGrrr�_testSendAndRecvMulti�szRDSTest._testSendAndRecvMulticCsLt�|jgggd�\}}}|�|j|�|j�|j�\}}|�|j|�dS)Ng@)�selectrCrWr:rsr�r5)rHrr�rlr5r�rrr�
testSelect	szRDSTest.testSelectcCr�)Nsselectrr�rGrrr�_testSelect	r�zRDSTest._testSelectr�)rOrPrQrYrIr�r�r�r�rDrr�r�r�r�r�r�rhrrr`rr��s




r�z'QIPCRTR sockets required for this test.c@s<eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
S)�BasicQIPCRTRTestcC�
tjdSr8)rr0rGrrrrx	r�z%BasicQIPCRTRTest.testCrucialConstantscC�6t�tjtj��	}Wd�dS1swYdSr8)rr0r$r[rrrr	�"�z!BasicQIPCRTRTest.testCreateSocketcCsJt�tjtj��}|�|��dd�Wd�dS1swYdS�Nr�r)rr0r$r�r�r[rrr�testUnbound	�"�zBasicQIPCRTRTest.testUnboundcCs`t�tjtj��}tj||��dd�|�|��dd�Wd�dS1s)wYdS)Nrrr�)rr0r$rrDr��assertNotEqualr[rrr�testBindSock	s"�zBasicQIPCRTRTest.testBindSockcCsJt�tjtj��}|jttj|dd�Wd�dS1swYdS)Nr�r)rr0r$rgrrrDr[rrr�testInvalidBindSock#	r�z$BasicQIPCRTRTest.testInvalidBindSockcCsTt�tjtj��}|�d�|�|��dd�Wd�dS1s#wYdS)N)�{r�r�r)rr0r$r�r�r�r[rrr�testAutoBindSock'	s
"�z!BasicQIPCRTRTest.testAutoBindSockN)	rOrPrQrxrr�r�r�r�rrrrr�	sr�c@�,eZdZdd�Zdd�Zdd�Zdd�Zd	S)
�BasicVSOCKTestcCr�r8)rr�rGrrrrx1	r�z#BasicVSOCKTest.testCrucialConstantscCrr8)	r�SO_VM_SOCKETS_BUFFER_SIZE�SO_VM_SOCKETS_BUFFER_MIN_SIZE�SO_VM_SOCKETS_BUFFER_MAX_SIZEr��VMADDR_PORT_ANY�VMADDR_CID_HOST�VM_SOCKETS_INVALID_VERSIONr
rGrrr�testVSOCKConstants4	s
z!BasicVSOCKTest.testVSOCKConstantscCr�r8)rr�r5r[rrrr>	r�zBasicVSOCKTest.testCreateSocketcCs�t�tjtj��l}|�tjtj�}|�tjtj�}|�tjtj�}|�tjtj|d�|�tjtj|d�|�tjtj|d�|�|d|�tjtj��|�|d|�tjtj��|�|d|�tjtj��Wd�dS1swwYdS�Nr�)	rr�r5r9r�r�r�r>r�)rHr!�orig_maxr��orig_minrrrr�B	sF���
�
�
�
��
��
��"�z#BasicVSOCKTest.testSocketBufferSizeN)rOrPrQrxr�rr�rrrrr�,	s

r�z)Bluetooth sockets required for this test.c@sveZdZdd�Zdd�Ze�ejdkd�dd��Z	e�ejdkd	�d
d��Z
e�ejdkp2ej�d�d
�dd��ZdS)�BasicBluetoothTestcCsRtjtjtjtjtjdkr%tjtjtj	tj�
d�s'tjdSdSdS)Nr"r�)r�
BDADDR_ANY�BDADDR_LOCALr4r6r�r��BTPROTO_HCI�SOL_HCI�
BTPROTO_L2CAPr��BTPROTO_SCOrGrrr�testBluetoothConstantsa	s

�z)BasicBluetoothTest.testBluetoothConstantscCrr8)rr4r5r6r[rrr�testCreateRfcommSocketo	rz)BasicBluetoothTest.testCreateRfcommSocketr"z&windows does not support L2CAP socketscCrr8)rr4r+r�r[rrr�testCreateL2capSockets	�"�z(BasicBluetoothTest.testCreateL2capSocketz$windows does not support HCI socketscCrr8)rr4rr�r[rrr�testCreateHciSocketx	r�z&BasicBluetoothTest.testCreateHciSocketr�z.windows and freebsd do not support SCO socketscCrr8)rr4r+r�r[rrr�testCreateScoSocket}	r z&BasicBluetoothTest.testCreateScoSocketN)
rOrPrQr�r�r�r�r�r�r�r�r�r�rrrrr�]	s

�r�c@s�eZdZd+dd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Ze�e�Zejd$d%��Zd&d'�Zd(d)�Zd*S),�BasicTCPTestr�cCr�r��r�rYr�rrrrY�	r�zBasicTCPTest.__init__cCr�r�)r�r�r�r�r�rrr�testRecv�	r�zBasicTCPTest.testRecvcC�|j�t�dSr8�r�r�r�rGrrr�	_testRecv�	rzBasicTCPTest._testRecvcCs8|j�tt�d�}|j�d�}||}|�|t�dS�N�r�)r�r�rbr�r�)rH�seg1�seg2r�rrr�testOverFlowRecv�	szBasicTCPTest.testOverFlowRecvcCr�r8r�rGrrr�_testOverFlowRecv�	rzBasicTCPTest._testOverFlowRecvcCs |j�d�\}}|�|t�dSr�)r�r:r�r��rHr�r�rrr�testRecvFrom�	�zBasicTCPTest.testRecvFromcCr�r8r�rGrrr�
_testRecvFrom�	rzBasicTCPTest._testRecvFromcCs@|j�tt�d�\}}|j�d�\}}||}|�|t�dSr�)r�r:rbr�r�)rHr�r�r�r�rrr�testOverFlowRecvFrom�	sz!BasicTCPTest.testOverFlowRecvFromcCr�r8r�rGrrr�_testOverFlowRecvFrom�	rz"BasicTCPTest._testOverFlowRecvFromcCs2d}	|j�d�}|sn||7}q|�|d�dS)N�r�r��ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)r�r�r�)rHr��readrrr�testSendAll�	s�zBasicTCPTest.testSendAllcCsd}|j�|�dS)Nr�)r�r)rH�	big_chunkrrr�_testSendAll�	szBasicTCPTest._testSendAllcCsP|j��}t�|tjtj�}|�|j�|�|tj�|�	d�}|�
|t�dSr�)r�rXr�fromfdrBr5rdrrQr�r�r�)rHr�rr�rrr�
testFromFd�	s

zBasicTCPTest.testFromFdcCr�r8r�rGrrr�_testFromFd�	rzBasicTCPTest._testFromFdcCs0|j��}|�|j�|�d�}|�|t�dSr�)r��duprdrr�r�r�)rHrr�rrr�testDup�	s

zBasicTCPTest.testDupcCr�r8r�rGrrr�_testDup�	rzBasicTCPTest._testDupcCs&|j�d�}|�|t�|j��dSr�)r�r�r�r�r�r�r�rrr�testShutdown�	szBasicTCPTest.testShutdowncCs|j�t�|j�d�dSr�)r�r�r��shutdownrGrrr�
_testShutdown�	r�zBasicTCPTest._testShutdowncCsXddl}|j�t�|�t|jj|jd�|�t|jjd|jd�|j�d�dS)Nrr�r�)	r�r�r�r�rgr�r�r��UINT_MAX�rHr�rrr�_testShutdown_overflow�	s��z#BasicTCPTest._testShutdown_overflowcCs�|j��}|j��}|�||�|�|jj�|�t|jjd�|j�	�t
j
t
jt
j|d�}|�
|j	�|�d�}|�|t�dS)Nr�rC)r�rXr�r�rO�_closedrgrr�rrrBr5rdr�)rHrXrrr�rrr�
testDetach�	s



zBasicTCPTest.testDetachcCr�r8r�rGrrr�_testDetach�	rzBasicTCPTest._testDetachNr�)rOrPrQrYr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rr��testShutdown_overflowr�r�r�rrrrr��	s.

		


r�c@�FeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dS)�BasicUDPTestr�cCr�r�)r�rYr�rrrrY
r�zBasicUDPTest.__init__cC� |j�tt��}|�|t�dSr8�rCr�rbr�r�r�rrr�testSendtoAndRecv
r�zBasicUDPTest.testSendtoAndRecvcC�|j�tdt|jf�dSr��r�ror�r�rErGrrr�_testSendtoAndRecv	
r�zBasicUDPTest._testSendtoAndRecvcC�$|j�tt��\}}|�|t�dSr8�rCr:rbr�r�r�rrrr�
�zBasicUDPTest.testRecvFromcCr�r�r�rGrrrr�
r�zBasicUDPTest._testRecvFromcC�|�t|jjd�dS�Nr��rgr	rCr:rGrrr�testRecvFromNegative
rnz!BasicUDPTest.testRecvFromNegativecCr�r�r�rGrrr�_testRecvFromNegative
r�z"BasicUDPTest._testRecvFromNegativeNr��
rOrPrQrYr�r�r�r�r�r�rrrrr��	s
r�c@r�)�BasicUDPLITETestr�cCr�r�)r�rYr�rrrrY 
r�zBasicUDPLITETest.__init__cCr�r8r�r�rrrr�#
r�z"BasicUDPLITETest.testSendtoAndRecvcCr�r�r�rGrrrr�(
r�z#BasicUDPLITETest._testSendtoAndRecvcCr�r8r�r�rrrr�+
r�zBasicUDPLITETest.testRecvFromcCr�r�r�rGrrrr�0
r�zBasicUDPLITETest._testRecvFromcCr�r�r�rGrrrr�3
rnz%BasicUDPLITETest.testRecvFromNegativecCr�r�r�rGrrrr�7
r�z&BasicUDPLITETest._testRecvFromNegativeNr�r�rrrrr�
s
r�cs�eZdZejZ�fdd�Zdd�ZdZdd�Z	dd	�Z
d
d�Zdd
�ZdZ
dD]
Ze
eeed�OZ
q'dZdZdZddd�Z�ZS)�SendrecvmsgBasecst��|_t���dSr8)rZr��
misc_eventrXrIrGr`rrrI\
r�zSendrecvmsgBase.setUpcCs|j�|�Sr8)�cli_sockr�r�rrr�sendToServer`
szSendrecvmsgBase.sendToServerrcGs|jj||jt|�d��Sr8)rr��sendmsg_to_server_defaultsrb�rHr^rrr�sendmsgToServerh
s�zSendrecvmsgBase.sendmsgToServercGs |j|g|�R�}|�|�|Sr8)r��registerRecvmsgResult)rHrrsr^�resultrrr�	doRecvmsgp
s
zSendrecvmsgBase.doRecvmsgcCr�r8r�rHrrrrrz
sz%SendrecvmsgBase.registerRecvmsgResultcCs|�||�dSr8�r��rH�addr1�addr2rrr�checkRecvmsgAddress�
�z#SendrecvmsgBase.checkRecvmsgAddressr)�
MSG_CTRUNC�MSG_OOBNc
Cs�|j}|j}|r||jO}||jO}n|dur!||jO}||jO}||M}||M}||O}||O}||@|@}|rCtd�|���||B|@}	|�||	@||	@�dS)Nz6contradictory set, unset requirements for flags {0:#x})�msg_flags_common_set�msg_flags_common_unset�msg_flags_eor_indicator�msg_flags_non_eor_indicator�	ExceptionrIr�)
rHr^�eor�checkset�
checkunset�ignore�
defaultset�defaultunset�inbothr�rrr�
checkFlags�
s&




�zSendrecvmsgBase.checkFlags)Nrrr)rOrPrQr�LOOPBACK_TIMEOUT�fail_timeoutrIrrrrrrrr9r�rrrrrrhrrr`rr�U
s 
r�c@rT)�RecvmsgIntoMixincGsht|�}|j|gg|�R�}|�|�|�|dd�|�|d|�t|d|d��f|dd�Sry)r/�recvmsg_intor�assertGreaterEqual�assertLessEqualrQ)rHrrsr^�bufrrrrr�
s
"zRecvmsgIntoMixin.doRecvmsgN)rOrPrQrrrrrr!�
�r!c� eZdZe�fdd��Z�ZS)�SendrecvmsgDgramFlagsBasec�t�jtjBSr8)rXrr�	MSG_TRUNCrGr`rrr�
�z5SendrecvmsgDgramFlagsBase.msg_flags_non_eor_indicator)rOrPrQ�propertyrrhrrr`rr(�
�r(cr')�SendrecvmsgSCTPFlagsBasecr)r8)rXrr�MSG_EORrGr`rrr�
r+z0SendrecvmsgSCTPFlagsBase.msg_flags_eor_indicator)rOrPrQr,rrhrrr`rr.�
r-r.c@s8eZdZedd��Zedd��Zedd��Zdd�Zd	S)
�SendrecvmsgConnectionlessBasecCr�r8)rCrGrrr�	serv_sock�
�z'SendrecvmsgConnectionlessBase.serv_sockcCr�r8)r�rGrrrr�
r2z&SendrecvmsgConnectionlessBase.cli_sockcCsggd|jfSr�)r�rGrrrr�
r+z8SendrecvmsgConnectionlessBase.sendmsg_to_server_defaultscCs|j�||j�Sr8)rror�r�rrrr�
rz*SendrecvmsgConnectionlessBase.sendToServerN)rOrPrQr,r1rrrrrrrr0�
s


r0c@s,eZdZedd��Zedd��Zdd�ZdS)�SendrecvmsgConnectedBasecCr�r8)r�rGrrrr1r2z"SendrecvmsgConnectedBase.serv_sockcCr�r8)r�rGrrrrr2z!SendrecvmsgConnectedBase.cli_sockcCr�r8rrrrrr�z,SendrecvmsgConnectedBase.checkRecvmsgAddressN)rOrPrQr,r1rrrrrrr3�
s

r3c�eZdZ�fdd�Z�ZS)�SendrecvmsgServerTimeoutBasec�t���|j�|j�dSr8)rXrIr1rAr rGr`rrrI�
z"SendrecvmsgServerTimeoutBase.setUp)rOrPrQrIrhrrr`rr6sr6c@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zeed�dd��Zejd d!��Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*S)+�SendmsgTestscC�|�|j�tt��t�dSr8�r�r1r�rbr�rGrrr�testSendmsg�zSendmsgTests.testSendmsgcCs|�|�tg�tt��dSr8�r�rr�rbrGrrr�_testSendmsg!�zSendmsgTests._testSendmsgcCr:r8r;rGrrr�testSendmsgDataGenerator$r=z%SendmsgTests.testSendmsgDataGeneratorcCs&|�|�dd�tfD��tt��dS)Ncsr>r8rrGrrrr?)r@z9SendmsgTests._testSendmsgDataGenerator.<locals>.<genexpr>r>rGrrr�_testSendmsgDataGenerator(s�z&SendmsgTests._testSendmsgDataGeneratorcCr:r8r;rGrrr�testSendmsgAncillaryGenerator,r=z*SendmsgTests.testSendmsgAncillaryGeneratorcCs(|�|�tgdd�dD��tt��dS)Ncsr>r8rrGrrrr?1r@z>SendmsgTests._testSendmsgAncillaryGenerator.<locals>.<genexpr>rr>rGrrr�_testSendmsgAncillaryGenerator0s�z+SendmsgTests._testSendmsgAncillaryGeneratorcCr:r8r;rGrrr�testSendmsgArray4r=zSendmsgTests.testSendmsgArraycCs$|�|�t�dt�g�tt��dS)N�B)r�r�arrayr�rbrGrrr�_testSendmsgArray8s�zSendmsgTests._testSendmsgArraycCr:r8r;rGrrr�testSendmsgGather<r=zSendmsgTests.testSendmsgGathercC�.|�|�tdd�tdd�g�tt��dS�Nr�r>rGrrr�_testSendmsgGather@s.zSendmsgTests._testSendmsgGathercC�|�|j�d�d�dS�Nr��done�r�r1r�rGrrr�testSendmsgBadArgsC�zSendmsgTests.testSendmsgBadArgscCs�|�t|jj�|�t|jd�|�t|jt��|�t|jt�g�|�t|jtt�g�|�t|jtgt��|�t|jtggt��|�t|jtggdt��|�d�dS)Nsnot in an iterablerrO)rgr�rr�r�objectr�rrGrrr�_testSendmsgBadArgsGs.
�
�
�
�
�

�
�z SendmsgTests._testSendmsgBadArgscCrMrNrPrGrrr�testSendmsgBadCmsgYrRzSendmsgTests.testSendmsgBadCmsgcCs�|�t|jtgt�g�|�t|jtgt�ddfg�|�t|jtgdt�dfg�|�t|jtgddt�fg�|�t|jtgdg�|�t|jtgdg�|�d�dS)Nr�data)rr)rrrVr�rO�rgr�rr�rSrrGrrr�_testSendmsgBadCmsg]s&

�
�
�
�
�
�z SendmsgTests._testSendmsgBadCmsg�
CMSG_SPACEcCrMrNrPrGrrr�testSendmsgBadMultiCmsglsz$SendmsgTests.testSendmsgBadMultiCmsgcCs@|�t|jtggd��|�t|jtgdt�g�|�d�dS)N�rrr�rOrWrGrrr�_testSendmsgBadMultiCmsgrs

�
�z%SendmsgTests._testSendmsgBadMultiCmsgcCrMrNrPrGrrr�testSendmsgExcessCmsgRejectz�z(SendmsgTests.testSendmsgExcessCmsgRejectcCsbttd�s*|�t��}|�tgddg�Wd�n1swY|�|jj�|�	d�dS)NrYr[rO)
rrrgrrr��assertIsNonerpr�r�rHrrrrr�_testSendmsgExcessCmsgRejects
�z)SendmsgTests._testSendmsgExcessCmsgRejectcCr�r8rrGrrr�testSendmsgAfterClose�sz"SendmsgTests.testSendmsgAfterClosecCs |j��|�t|jtg�dSr8)rrrgrrr�rGrrr�_testSendmsgAfterClose�s
z#SendmsgTests._testSendmsgAfterCloseN)rOrPrQr<r?rArBrCrDrErHrIrLrQrTrUrXrDrrZr-r\r]rarbrcrrrrr9s.

r9c@sReZdZdd�Zdd�Zdd�Zdd�Zeej	d	vd
�dd��Z
e
jd
d��ZdS)�SendmsgStreamTestscCr:r8r;rGrrr�testSendmsgExplicitNoneAddr�r=z.SendmsgStreamTests.testSendmsgExplicitNoneAddrcCs"|�|�tggdd�tt��dSr�r>rGrrr�_testSendmsgExplicitNoneAddr�s"z/SendmsgStreamTests._testSendmsgExplicitNoneAddrcC�.|�|j�d�d�|�|jj|jd��dS�Nr+�aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa�r;�r�r1r�rOrr�r rGrrr�testSendmsgTimeout�sz%SendmsgStreamTests.testSendmsgTimeoutc
Cs�z@|j�d�z	|�dg�q	tyYnty0}z
|jtjkr&�WYd}~n
d}~wwW|j�	�dSW|j�	�dS|j�	�w)N���Q��?Tri)
rrArr�rr��ENOMEMrcrr�rHrTrrr�_testSendmsgTimeout�s$�����	�z&SendmsgStreamTests._testSendmsgTimeout>r�z<MSG_DONTWAIT not known to work on this platform when sendingcCrgrhrkrGrrr�testSendmsgDontWait�sz&SendmsgStreamTests.testSendmsgDontWaitcCslz/|�t��}	|�dggtj�q1swY|�|jjtjtj	tj
f�W|j��dS|j��w)NTri)
rgrrr�MSG_DONTWAITrWrpr��EAGAIN�EWOULDBLOCKrnrrr`rrr�_testSendmsgDontWait�s��
�z'SendmsgStreamTests._testSendmsgDontWaitN)
rOrPrQrerfrlrpr6r�r�rqr-rurrrrrd�s
�
rdc@r@)�SendmsgConnectionlessTestscCr�r8rrGrrr�testSendmsgNoDestAddr�r4z0SendmsgConnectionlessTests.testSendmsgNoDestAddrcCs2|�t|jjtg�|�t|jjtggdd�dSr�)rgrrr�r�rGrrr�_testSendmsgNoDestAddr�s�
�z1SendmsgConnectionlessTests._testSendmsgNoDestAddrN)rOrPrQrwrxrrrrrv�srvc@s�eZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd �Zeed!�d"d#��Zejd$d%��Zeejd&�d'd(��Zejd)d*��Zd+S),�RecvmsgGenericTestscCsR|�|jtt��\}}}}|�|t�|�||j�|�|g�|j|dd�dS�NT�r�rr1rbr�r�rr�r�rHr�r�r^r�rrr�testRecvmsg�s
zRecvmsgGenericTests.testRecvmsgcC�|�t�dSr8�rr�rGrrr�_testRecvmsg�r�z RecvmsgGenericTests._testRecvmsgcCsV|�|jtt�dd�\}}}}|�|t�|�||j�|�|g�|j|dd�dS)NrTr{r|r}rrr�testRecvmsgExplicitDefaults��
�z/RecvmsgGenericTests.testRecvmsgExplicitDefaultscCrr8r�rGrrr�_testRecvmsgExplicitDefaults�r�z0RecvmsgGenericTests._testRecvmsgExplicitDefaultscCsV|�|jtt�d�\}}}}|�|t�|�||j�|�|g�|j|dd�dS)Nr�Tr{r|r}rrr�testRecvmsgShorter�r�z&RecvmsgGenericTests.testRecvmsgShortercCrr8r�rGrrr�_testRecvmsgShorterr�z'RecvmsgGenericTests._testRecvmsgShortercCs^|�|jtt�d�\}}}}|�|tdd��|�||j�|�|g�|j|dd�dS)Nr����Fr{r|r}rrr�testRecvmsgTruncs
�z$RecvmsgGenericTests.testRecvmsgTrunccCrr8r�rGrrr�_testRecvmsgTruncr�z%RecvmsgGenericTests._testRecvmsgTrunccC�T|�|jtt�d�\}}}}|�|t�|�||j�|�|g�|j|dd�dS)Nr�Tr{r|r}rrr�testRecvmsgShortAncillaryBuf��z0RecvmsgGenericTests.testRecvmsgShortAncillaryBufcCrr8r�rGrrr�_testRecvmsgShortAncillaryBufr�z1RecvmsgGenericTests._testRecvmsgShortAncillaryBufcCr�)N�(Tr{r|r}rrr�testRecvmsgLongAncillaryBufr�z/RecvmsgGenericTests.testRecvmsgLongAncillaryBufcCrr8r�rGrrr�_testRecvmsgLongAncillaryBuf&r�z0RecvmsgGenericTests._testRecvmsgLongAncillaryBufcCs"|j��|�t|j|jd�dSr�)r1rrgrrrGrrr�testRecvmsgAfterClose)s
z)RecvmsgGenericTests.testRecvmsgAfterClosecCr�r8rrGrrr�_testRecvmsgAfterClose.r�z*RecvmsgGenericTests._testRecvmsgAfterClosecCsBz|j�d�|�t|j|jtt��W|j��dS|j��w)Nrm)	r1rArgr�rrbr�rrrGrrr�testRecvmsgTimeout1s�z&RecvmsgGenericTests.testRecvmsgTimeoutcCs|�|jj|jd��dS�Nrj)rOrr�r rGrrr�_testRecvmsgTimeout:r�z'RecvmsgGenericTests._testRecvmsgTimeoutr�cCs|�|jtt�ddtj�\}}}}|�|tdd��|�||j�|�|g�|j	|dt
tdd�d�|�|jtt�dtj�\}}}}|�|t�|�||j�|�|g�|j	|dd�|�|jtt��\}}}}|�|t�|�||j�|�|g�|j	|dd�dS)	Nr�rr�Fr*�rrTr{)rr1rbr�rr�r�rr�rr�r}rrr�testRecvmsgPeek=s.�
��z#RecvmsgGenericTests.testRecvmsgPeekcCrr8r�rGrrr�_testRecvmsgPeek`r+z$RecvmsgGenericTests._testRecvmsgPeekr�cCs`|j�|j�|�|jtt��\}}}}|�|t�|�||j�|�|g�|j	|dd�dSrz)
r1rAr rrbr�r�rr�rr}rrr�testRecvmsgFromSendmsgdsz*RecvmsgGenericTests.testRecvmsgFromSendmsgcCrJrKr>rGrrr�_testRecvmsgFromSendmsgos.z+RecvmsgGenericTests._testRecvmsgFromSendmsgN)rOrPrQr~r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rDrr�r-r�r�r�rrrrry�s2						
"



ryc@r�)
�RecvmsgGenericStreamTestscCsN|�|jd�\}}}}|�|d�|�||j�|�|g�|j|dd�dS)Nr�r�r{)rr1r�rr�rr}rrr�testRecvmsgEOFxs
z(RecvmsgGenericStreamTests.testRecvmsgEOFcC�|j��dSr8)rrrGrrr�_testRecvmsgEOF�r�z)RecvmsgGenericStreamTests._testRecvmsgEOFcCs�|�|jtt�d�\}}}}|�||j�|�|g�|j|dd�|�|jd�\}}}}|�||j�|�|g�|j|dd�||}|�|t�dS)Nr�Fr{r�T)rr1rbr�rr�r�r)rHr�r�r^r�r�r�rrr�testRecvmsgOverflow�s
�z-RecvmsgGenericStreamTests.testRecvmsgOverflowcCrr8r�rGrrr�_testRecvmsgOverflow�r�z.RecvmsgGenericStreamTests._testRecvmsgOverflowN)rOrPrQr�r�r�r�rrrrr�ts
r�c@r@)�RecvmsgTestscCs|�t|jj�|�t|jjddd�|�t|jjtt�dd�|�t|jjtd�gdd�|�t|jjt�dd�|�t|jjtt�t�d�|�t|jjtt�dt��|j�tt�dd�\}}}}|�	|t�|�
||j�|�	|g�|j|dd�dS)Nr�rrTr{)
rgr�r1r�r	rbr�r/rSr�rr�rr}rrr�testRecvmsgBadArgs�s0�
�����zRecvmsgTests.testRecvmsgBadArgscCrr8r�rGrrr�_testRecvmsgBadArgs�r�z RecvmsgTests._testRecvmsgBadArgsN)rOrPrQr�r�rrrrr��sr�c@sLeZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dS)�RecvmsgIntoTestscCsLttt��}|�t|jj�|�t|jjtt�dd�|�t|jj|dd�|�t|jjt�gdd�|�t|jjdgdd�|�t|jj|t�gdd�|�t|jj|gdd�|�t|jj|gt�d�|�t|jj|gdt��|j�|gdd�\}}}}|�	|tt��|�	|tt��|�
||j�|�	|g�|j|dd�dS)NrsI'm not writabler�Tr{)
r/rbr�rgr�r1r"rSr	r�rr�r�rHr%�nbytesr�r^r�rrr�testRecvmsgIntoBadArgs�s@
��
����
�
�z'RecvmsgIntoTests.testRecvmsgIntoBadArgscCrr8r�rGrrr�_testRecvmsgIntoBadArgs�r�z(RecvmsgIntoTests._testRecvmsgIntoBadArgscCsxttt��}|j�dd�|fD��\}}}}|�|tt��|�|tt��|�||j�|�|g�|j|dd�dS)Ncsr>r8rrGrrrr?�r@z<RecvmsgIntoTests.testRecvmsgIntoGenerator.<locals>.<genexpr>Tr{)	r/rbr�r1r"r�rr�rr�rrr�testRecvmsgIntoGenerator�s�z)RecvmsgIntoTests.testRecvmsgIntoGeneratorcCrr8r�rGrrr�_testRecvmsgIntoGenerator�r�z*RecvmsgIntoTests._testRecvmsgIntoGeneratorcCsxt�ddgtt��}|j�|g�\}}}}|�|tt��|�|��t�|�||j�|�|g�|j	|dd�dS)NrFrTr{)
rGrbr�r1r"r��tobytesrr�rr�rrr�testRecvmsgIntoArray�sz%RecvmsgIntoTests.testRecvmsgIntoArraycCrr8r�rGrrr�_testRecvmsgIntoArray�r�z&RecvmsgIntoTests._testRecvmsgIntoArraycCs�td�}td�}td�}|j�|t|�dd�|g�\}}}}|�|td��|�|td��|�|td��|�|td	��|�||j�|�|g�|j|d
d�dS)Ns----s
0123456789s--------------r��	�Mary had a little lambsMarys
01 had a 9slittle lamb---Tr{)	r/r1r"�
memoryviewr�rbrr�r)rH�b1�b2�b3r�r�r^r�rrr�testRecvmsgIntoScatter�s�z'RecvmsgIntoTests.testRecvmsgIntoScattercCr�)Nr�)rrGrrr�_testRecvmsgIntoScatter
r�z(RecvmsgIntoTests._testRecvmsgIntoScatterN)rOrPrQr�r�r�r�r�r�r�r�rrrrr��s
r�c@s`eZdZzddlZWneydZYnwedej�Zee	d�dd��Z
ee	d�dd	��ZdS)
�CmsgMacroTestsrNi����CMSG_LENcCs�|jt�d�d}ttd��tt|d|��}|�t�d�t�d�jd�|D]}t�|�}|�|t�d�|�|�	||j�q*|�
ttjd�|�
ttj|�|�
ttjtj
�dS)Nrr��r?r�r�)�socklen_t_limitrr��listr�r�rG�itemsizer�r$rgr�r��maxsize)rH�toobigr��nr2rrr�testCMSG_LEN
s
zCmsgMacroTests.testCMSG_LENrYcCs�|jt�d�d}ttd��tt|d|��}t�d�}|�|t�d�jd�|D]*}t�|�}|�||�|�|t�	|��|�||t�	d��|�
||j�|}q,|�ttjd�|�ttj|�|�ttjt
j�dS)Nr�r�rr?r�r�)r�rrYr�r�r�rGr�r#r�r$rgr�r�r�)rHr�r��lastr�r2rrr�testCMSG_SPACE&
s

zCmsgMacroTests.testCMSG_SPACE)rOrPrQr�r)r��minr�rDrr�r�rrrrr�
s�
r�c@sHeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdddd�Z	dd�Z
dd�Zdd�Zdd�Z
eed�dd��Zejdd��Zdd�Zdd �Ze�ejd!kd"�e�ed#�eed�d$d%����Zeje�ejd!kd"�e�ed#�d&d'����Ze�ejd!kd"�e�ed#�eed�d(d)����Zeje�ejd!kd"�e�ed#�d*d+����Zd,d-�Ze�ejd!kd.�d/d0��Zd1d2�Z d3d4�Z!d5d6�Z"eed�d7d8��Z#e#jd9d:��Z$ded;d<�Z%d=d>�Z&d?d@�Z'dAdB�Z(dCdD�Z)dEdF�Z*dGdH�Z+dIdJ�Z,dKdL�Z-dMdN�Z.dOdP�Z/dedQdR�Z0dSdT�Z1dUdV�Z2dWdX�Z3dYdZ�Z4d[d\�Z5d]d^�Z6d_d`�Z7dadb�Z8dcS)f�
SCMRightsTesti����cCs\g}t|�D]%}t��\}}|�tj|�|�tj|�t�|t|��	��|�
|�q|Sr8)r�r�mkstemprdrrr�writerE�encode�append)rHr��fdsr?r�r
rrr�newFDsG
szSCMRightsTest.newFDscCsBt|�D]\}}t�|dtj�|�t�|d�t|����qdS)Nrr�)�	enumerater�lseek�SEEK_SETr�r�rEr�)rHr�r�r�rrr�checkFDsS
s�zSCMRightsTest.checkFDscCs|�|j|�dSr8)rd�closeRecvmsgFDsr	rrrrZ
r�z#SCMRightsTest.registerRecvmsgResultcCsn|dD]0\}}}|tjkr4|tjkr4t�d�}|�|dt|�t|�|j��|D]}t�|�q,qdS)Nr�r?)	rrv�
SCM_RIGHTSrG�	frombytesrbr�rr)rH�recvmsg_result�
cmsg_level�	cmsg_type�	cmsg_datar�r�rrrr�]
s


���zSCMRightsTest.closeRecvmsgFDsc
Cs8|�|�tgtjtjt�d|�|��fg�tt��dS)Nr?)	r�rr�rrvr�rGr�rb)rHr�rrr�createAndSendFDsi
s���zSCMRightsTest.createAndSendFDsr�rcCs�|\}}}}|�|t�|�||j�|j|dtj|d�|�|t�|�	t
|�|�t�d�}	|D]0}
|�|
t�|
\}}}
|�|tj
�|�|tj�|�|
t�|�t
|
�td�|	�|
�q2|�t
|	�|�|�|	�dS)NT�rrrr?r)r�r�rr�rrrrQr�r$rbrG�tuplervr�rQ�
SIZEOF_INTr�r�)rH�numfdsr�maxcmsgs�ignoreflagsr�r�r^r�r��itemr�r�r�rrr�checkRecvmsgFDss
s&�

zSCMRightsTest.checkRecvmsgFDscC� |�d|�|jtt�d��dS)Nr�r��r�rr1rbr�rGrrr�testFDPassSimple�
�
�zSCMRightsTest.testFDPassSimplec
Cs<|�|�tgtjtjt�d|�d����fg�t	t��dS)Nr?r�)
r�rr�rrvr�rGr�r�rbrGrrr�_testFDPassSimple�
s���zSCMRightsTest._testFDPassSimplecCr�)Nrnr�r�rGrrr�testMultipleFDPass�
r�z SCMRightsTest.testMultipleFDPasscCr��Nrn�r�rGrrr�_testMultipleFDPass�
r�z!SCMRightsTest._testMultipleFDPassrYcCs*|�d|�|jtt�t�dt���dSr�)r�rr1rbr�rrYr�rGrrr�testFDPassCMSG_SPACE�
s
��z"SCMRightsTest.testFDPassCMSG_SPACEcCr�r�r�rGrrr�_testFDPassCMSG_SPACE�
r+z#SCMRightsTest._testFDPassCMSG_SPACEc
Cs0|jd|�|jtt�t�dt��tjd�dS)Nr�rn�r�)	r�rr1rbr�rr�r�rrGrrr�testFDPassCMSG_LEN�
s�
�z SCMRightsTest.testFDPassCMSG_LENcCr�rr�rGrrr�_testFDPassCMSG_LEN�
r�z!SCMRightsTest._testFDPassCMSG_LENr�zskipping, see issue #12958zskipping, see issue #22397cCs$|jd|�|jtt�d�dd�dS)Nr�r�)r�r�rGrrr�testFDPassSeparate�
s
�z SCMRightsTest.testFDPassSeparatecC�X|�d�\}}|�|�tgtjtjt�d|g�ftjtjt�d|g�fg�tt��dS�Nr�r?�	r�r�rr�rrvr�rGrb�rH�fd0�fd1rrr�_testFDPassSeparate�
�����z!SCMRightsTest._testFDPassSeparatecCs@d}|j||�|jtt�t�t�t�t|��dtj	d�dS)Nr�)r�r�)
r�rr1rbr�rrYr�r�r)rH�num_fdsrrr�testFDPassSeparateMinSpace�
s��
�z(SCMRightsTest.testFDPassSeparateMinSpacecCr�r�r�r�rrr�_testFDPassSeparateMinSpace�
r�z)SCMRightsTest._testFDPassSeparateMinSpacec
Csfz	|�|g|�}Wnty(}z|�|jt�|�|g�}WYd}~nd}~ww|�|t|��dSr8)rrrQr�r�r�rb)rHr�r�r�r�rrr�sendAncillaryIfPossible�
s��z%SCMRightsTest.sendAncillaryIfPossiblezsee issue #24725cCs&|jd|�|jtt�d�tjd�dS)Nrr�r�)r�rr1rbr�rrrGrrr�testFDPassEmpty�
s
�
�zSCMRightsTest.testFDPassEmptycCs|�ttjtjdfg�dS�Nr�)r�r�rrvr�rGrrr�_testFDPassEmptys
�zSCMRightsTest._testFDPassEmptycCs�|�|jtt�d�\}}}}|�|t�|�||j�|j|dtj	d�|�
t|�d�|D]\}}}|�|tj�|�|tj�|�
t|�t�q.dS)Nr�Tr�r�)rr1rbr�r�rr�rrrr$rvr��
assertLessr��rHr�r�r^r�r�r�r�rrr�testFDPassPartialInts��z"SCMRightsTest.testFDPassPartialIntc	Cs4|�ttjtjt�d|jg���dd�fg�dS)Nr?r�)r�r�rrvr�rG�badfdr�rGrrr�_testFDPassPartialInts��z#SCMRightsTest._testFDPassPartialIntc	Cs�|�|jtt�d�\}}}}|�|t�|�||j�|j|dtj	d�|�
t|�d�t�d�}|D]%\}}}|�|tj�|�|tj
�|�|dt|�t|�|j��q3|�
t|�d�|�|�dS)Nr�Tr�r�r?)rr1rbr�r�rr�rrrr$rGrvr�r�r�r�)	rHr�r�r^r�r�r�r�r�rrr�testFDPassPartialIntInMiddles �

�z*SCMRightsTest.testFDPassPartialIntInMiddlec
CsZ|�d�\}}|�ttjtjt�d||jg���dd�ftjtjt�d|g�fg�dS)Nr�r?r�)	r�r�r�rrvr�rGr�r�r�rrr�_testFDPassPartialIntInMiddle.s����z+SCMRightsTest._testFDPassPartialIntInMiddlecCsJ|\}}}}|�|t�|�||j�|�|g�|j|dtj|d�dS)NT�rrr)r�r�rr�rrr)rHrr�r�r�r^r�rrr�checkTruncatedHeader:s
�z"SCMRightsTest.checkTruncatedHeadercCs"|j|�|jtt��tjd�dS�Nr��rrr1rbr�rrrGrrr�testCmsgTruncNoBufSizeDs
�z$SCMRightsTest.testCmsgTruncNoBufSizecCr�rr�rGrrr�_testCmsgTruncNoBufSizeMr�z%SCMRightsTest._testCmsgTruncNoBufSizecCs$|j|�|jtt�d�tjd�dS)Nrr�rrGrrr�testCmsgTrunc0Ps
�zSCMRightsTest.testCmsgTrunc0cCr�rr�rGrrr�_testCmsgTrunc0Ur�zSCMRightsTest._testCmsgTrunc0cCs|�|�|jtt�d��dSr)rrr1rbr�rGrrr�testCmsgTrunc1[szSCMRightsTest.testCmsgTrunc1cCr�rr�rGrrr�_testCmsgTrunc1^r�zSCMRightsTest._testCmsgTrunc1cCs"|�|�|jtt�td��dSr�)rrr1rbr�r�rGrrr�testCmsgTrunc2Intas
�zSCMRightsTest.testCmsgTrunc2IntcCr�rr�rGrrr�_testCmsgTrunc2Inthr�z SCMRightsTest._testCmsgTrunc2Intc	Cs(|�|�|jtt�t�d�d��dSry)rrr1rbr�rr�rGrrr�testCmsgTruncLen0Minus1ks
�z%SCMRightsTest.testCmsgTruncLen0Minus1cCr�rr�rGrrr�_testCmsgTruncLen0Minus1or�z&SCMRightsTest._testCmsgTruncLen0Minus1cCs�|�|jtt�|�\}}}}|�|t�|�||j�|j|dtj	d�|dkr.|gkr.dS|�t|�d�|d\}}	}
|�|tj
�|�|	tj�|�t|
�|�|�
t|
�|�t�d�}|�|
dt|
�t|
�|j��|�|�dS)NT�rrrr�r?)rr1rbr�r�rr�rrrrvr�r#r$rGr�r�r�)rH�ancbuf�maxdata�mindatar�r�r^r�r�r�r�r�rrr�checkTruncatedArrayus&�
�z!SCMRightsTest.checkTruncatedArraycCs|jt�d�dd�dS)Nr�rr�rrr�rGrrr�testCmsgTruncLen0��zSCMRightsTest.testCmsgTruncLen0cCr�rr�rGrrr�_testCmsgTruncLen0�r�z SCMRightsTest._testCmsgTruncLen0cCs|jt�d�ddd�dS)Nrr�rrrGrrr�testCmsgTruncLen0Plus1�r@z$SCMRightsTest.testCmsgTruncLen0Plus1cCr�r�r�rGrrr�_testCmsgTruncLen0Plus1�r�z%SCMRightsTest._testCmsgTruncLen0Plus1cCs|jt�t�td�dS)Nr�rrr�r�rGrrr�testCmsgTruncLen1�s
�zSCMRightsTest.testCmsgTruncLen1cCr�r�r�rGrrr�_testCmsgTruncLen1�r�z SCMRightsTest._testCmsgTruncLen1cCs(|jt�dt�ddtdd�dS)Nr�r�rrrGrrr�testCmsgTruncLen2Minus1�s

�z%SCMRightsTest.testCmsgTruncLen2Minus1cCr�r�r�rGrrr�_testCmsgTruncLen2Minus1�r�z&SCMRightsTest._testCmsgTruncLen2Minus1N)r�r�r)9rOrPrQr�r�r�rr�r�r�r�r�r�r�rDrr�r-r�r�r�r�r�r�r�r	r�r�r�r�r�r�r�r�rrrrrrr	r
rrr
rrrrrrrrrrr r!rrrrr�?
s�

	













	
r�c@seZdZdZdZdd�Zd^dd�Zeed	d
�dd��Z	e	j
d
d��Zeedd	d
�dd��Zej
dd��Z
eejd�eed	d
�dd���Zej
dd��Z		d^dd�Zeed	d
dd�dd��Zej
dd ��Zeedd	d
dd�d!d"��Zej
d#d$��Zeejd�eedd	d
dd�d%d&���Zej
d'd(��Zeejd�eedd	d
dd�d)d*���Zej
d+d,��Zd_d-d.�Zeed	d
�d/d0��Zej
d1d2��Zeed	d
�d3d4��Zej
d5d6��Zeed	d
�d7d8��Zej
d9d:��Zeed	d
�d;d<��Z e j
d=d>��Z!eed	d
�d?d@��Z"e"j
dAdB��Z#eed	d
�dCdD��Z$e$j
dEdF��Z%d_dGdH�Z&eedd	d
dd�dIdJ��Z'e'j
dKdL��Z(eedd	d
dd�dMdN��Z)e)j
dOdP��Z*eedd	d
dd�dQdR��Z+e+j
dSdT��Z,eedd	d
dd�dUdV��Z-e-j
dWdX��Z.eedd	d
dd�dYdZ��Z/e/j
d[d\��Z0d]S)`�RFC3542AncillaryTestr�r�cCs4i}|D]\}}}|�||f|�||||f<q|Sr8)rZ)rHr��dr�r�r�rrr�ancillaryMapping�s
z%RFC3542AncillaryTest.ancillaryMappingrOrcCs|j�tjtjd�|j��|�|jtt	�|�\}}}}|�
|t	�|�||j�|j
|dtj|d�|�
t|�d�|�|dt�|d\}}	}
|�
|tj�|�
|	tj�|�|
t�|�
t|
�t�t�d�}|�|
�|�|dd�|�|d|�dS)Nr�Tr�rr?)r1r>rr{r�rrrrbr�r�rr�rrrQr�r�rQr�rGr�r#r$)rH�
ancbufsize�maxhopr�r�r�r^r�r�r�r�rrrr�
checkHopLimit�s.
�
��

z"RFC3542AncillaryTest.checkHopLimitr�r�cC�|jdd�dS�Nr��r&)r(rGrrr�testRecvHopLimit�rz%RFC3542AncillaryTest.testRecvHopLimitcC�$|�|jj|jd��|�t�dSr��rOrr�r rr�rGrrr�_testRecvHopLimit�sz&RFC3542AncillaryTest._testRecvHopLimitrYcCs|jt�t�d�dS)Nr+)r(rrYr�rGrrr�testRecvHopLimitCMSG_SPACE��z/RFC3542AncillaryTest.testRecvHopLimitCMSG_SPACEcCr-r�r.rGrrr�_testRecvHopLimitCMSG_SPACE��z0RFC3542AncillaryTest._testRecvHopLimitCMSG_SPACEr�cC�|jd|jd�dS�Nr�)r&r')r(�	hop_limitrGrrr�testSetHopLimit�sz$RFC3542AncillaryTest.testSetHopLimitcCsL|�|jj|jd��|�|�tgtjtj	t
�
d|jg�fg�tt��dS�Nrjr?)
rOrr�r r�rr�rr{r�rGr6rbrGrrr�_testSetHopLimits���z%RFC3542AncillaryTest._testSetHopLimitcCsB|j�tjtjd�|j�tjtjd�|j��|�|jt	t
�|�\}}}}|�|t
�|�||j
�|j|dtj|d�|�t	|�d�|�|�}|tjtjf}	|�t	|	�t�t�d�}
|
�|	�|�|
dd�|�|
dd�|tjtjf}|�t	|�t�t�d�}
|
�|�|�|
dd�|�|
d|�dS)Nr�Tr�r�r?rrO)r1r>rr{r�r�rrrrbr�r�rr�rrr%r�r�rGr�r#r$r�)rHr&r'r�r�r�r^r��ancmap�tcdatar�hldatarrr�checkTrafficClassAndHopLimits:
�
�
��




z1RFC3542AncillaryTest.checkTrafficClassAndHopLimitr�r�cCr)r*)r=rGrrr�testRecvTrafficClassAndHopLimit/sz4RFC3542AncillaryTest.testRecvTrafficClassAndHopLimitcCr-r�r.rGrrr� _testRecvTrafficClassAndHopLimit5r3z5RFC3542AncillaryTest._testRecvTrafficClassAndHopLimitcCs|jt�t�dd�dS�Nr�r+)r=rrYr�rGrrr�)testRecvTrafficClassAndHopLimitCMSG_SPACE:s
�z>RFC3542AncillaryTest.testRecvTrafficClassAndHopLimitCMSG_SPACEcCr-r�r.rGrrr�*_testRecvTrafficClassAndHopLimitCMSG_SPACEBr3z?RFC3542AncillaryTest._testRecvTrafficClassAndHopLimitCMSG_SPACEcCr4r5�r=r6rGrrr�testSetTrafficClassAndHopLimitGs
�z3RFC3542AncillaryTest.testSetTrafficClassAndHopLimitcCsd|�|jj|jd��|�|�tgtjtj	t
�
d|jg�ftjtjt
�
d|j
g�fg�tt��dSr8)rOrr�r r�rr�rr{r�rG�
traffic_classr�r6rbrGrrr�_testSetTrafficClassAndHopLimitPs�����z4RFC3542AncillaryTest._testSetTrafficClassAndHopLimitcCr4r5rCrGrrr�testOddCmsgSize[s
�z$RFC3542AncillaryTest.testOddCmsgSizec
Cs�|�|jj|jd��z&|�tgtjtjt	�	d|j
g���dftjtjt	�	d|j
g�fg�}WdStyr}z5|�|jt�|�tgtjtjt	�	d|j
g�ftjtjt	�	d|j
g�fg�}|�|tt��WYd}~dSd}~ww)Nrjr?r2)rOrr�r rr�rr{r�rGrEr�r�r6rrQr�r�r�rb)rHr�r�rrr�_testOddCmsgSizees6���
�������z%RFC3542AncillaryTest._testOddCmsgSizecCs�|j�tjtjd�|j��|durdn|f}|j|jtt	�g|�R�\}}}}|�
|t	�|�||j�|�
|g�|j
|dtj|d�dS)Nr�rTr)r1r>rr{r�rrrrbr�r�rr�rr)rHr&r�r^r�r�r^r�rrr�checkHopLimitTruncatedHeader{s 
�
��
�z1RFC3542AncillaryTest.checkHopLimitTruncatedHeadercCs|jdtjd�dS)N�r&r��rIrrrGrrrr�s
�z+RFC3542AncillaryTest.testCmsgTruncNoBufSizecCr-r�r.rGrrrr�r3z,RFC3542AncillaryTest._testCmsgTruncNoBufSizecCs|jdtjd�dS)NrrJrKrGrrr�testSingleCmsgTrunc0�s
�z)RFC3542AncillaryTest.testSingleCmsgTrunc0cCr-r�r.rGrrr�_testSingleCmsgTrunc0�r3z*RFC3542AncillaryTest._testSingleCmsgTrunc0cCr))Nr�r+)rIrGrrr�testSingleCmsgTrunc1��z)RFC3542AncillaryTest.testSingleCmsgTrunc1cCr-r�r.rGrrr�_testSingleCmsgTrunc1�r3z*RFC3542AncillaryTest._testSingleCmsgTrunc1cCs|jdtd�dSr@)rIr�rGrrr�testSingleCmsgTrunc2Int��z,RFC3542AncillaryTest.testSingleCmsgTrunc2IntcCr-r�r.rGrrr�_testSingleCmsgTrunc2Int�r3z-RFC3542AncillaryTest._testSingleCmsgTrunc2IntcCs|jt�d�dd�dS)Nrr�r+)rIrr�rGrrr�testSingleCmsgTruncLen0Minus1��z2RFC3542AncillaryTest.testSingleCmsgTruncLen0Minus1cCr-r�r.rGrrr�_testSingleCmsgTruncLen0Minus1�r3z3RFC3542AncillaryTest._testSingleCmsgTruncLen0Minus1cCs�|j�tjtjd�|j��|�|jtt	�t�
t�d�\}}}}|�|t	�|�
||j�|j|dtjd�|�t|�d�|ra|d\}}}|�|tj�|�|tj�|�t|�t�dSdS)Nr�Trr)r1r>rr{r�rrrrbr�r�r�r�rr�rrr$r�r�r�rrr�testSingleCmsgTruncInData�s"
�
��z.RFC3542AncillaryTest.testSingleCmsgTruncInDatacCr-r�r.rGrrr�_testSingleCmsgTruncInData�r3z/RFC3542AncillaryTest._testSingleCmsgTruncInDatacCs|j�tjtjd�|j�tjtjd�|j��|�|jt	t
�|�\}}}}|�|t
�|�||j
�|j|dtj|d�|�t	|�d�|d\}}}	|�|tj�|�|tjtjh�|�t	|	�t�t�d�}
|
�|	�|�|
dd�|�|
dd�dS)Nr�Trrr?rO)r1r>rr{r�r�rrrrbr�r�rr�rrrWr�r�r�rGr�r#r$)rHr&r�r�r�r^r�r�r�r�rrrr�checkTruncatedSecondHeader�s0
�
�
��

z/RFC3542AncillaryTest.checkTruncatedSecondHeadercCs|jt�t�tjd�dSr)rYrrYr�rrGrrr�testSecondCmsgTrunc0s
�z)RFC3542AncillaryTest.testSecondCmsgTrunc0cCr-r�r.rGrrr�_testSecondCmsgTrunc0
r3z*RFC3542AncillaryTest._testSecondCmsgTrunc0cCs|�t�t�d�dSr�rYrrYr�rGrrr�testSecondCmsgTrunc1r^z)RFC3542AncillaryTest.testSecondCmsgTrunc1cCr-r�r.rGrrr�_testSecondCmsgTrunc1r3z*RFC3542AncillaryTest._testSecondCmsgTrunc1cCs|�t�t�dt�dSr�r\rGrrr�testSecondCmsgTrunc2Ints
�z,RFC3542AncillaryTest.testSecondCmsgTrunc2IntcCr-r�r.rGrrr�_testSecondCmsgTrunc2Intr3z-RFC3542AncillaryTest._testSecondCmsgTrunc2IntcCs"|�t�t�t�d�d�dSry)rYrrYr�r�rGrrr�testSecondCmsgTruncLen0Minus1$s
�
�z2RFC3542AncillaryTest.testSecondCmsgTruncLen0Minus1cCr-r�r.rGrrr�_testSecondCmsgTruncLen0Minus1*r3z3RFC3542AncillaryTest._testSecondCmsgTruncLen0Minus1c
CsR|j�tjtjd�|j�tjtjd�|j��|�|jt	t
�t�t�t�
t�d�\}}}}|�|t
�|�||j�|j|dtjd�tjtjh}|�d�\}}}|�|tj�|�|�|�t	|�t�t�d�}	|	�|�|�|	dd�|�|	dd�|r�|�d�\}}}|�|tj�|�|�|�t	|�t�|�|g�dS)Nr�Trrr?rO)r1r>rr{r�r�rrrrbr�rYr�r�r�rr�rrr�r��pop�removerGr�r#r$r�)
rHr�r�r^r��
cmsg_typesr�r�r�rrrr�testSecondCmsgTruncInData/s:
�
�

�



z.RFC3542AncillaryTest.testSecondCmsgTruncInDatacCr-r�r.rGrrr�_testSecondCmsgTruncInDataTr3z/RFC3542AncillaryTest._testSecondCmsgTruncInDataN)rOrr")1rOrPrQr6rEr%r(rDrr,r-r/r0r2r7r9r=r>r?rArBrDrFrGrHrIrrrLrMrNrPrQrSrTrVrWrXrYrZr[r]r^r_r`rarbrfrgrrrrr#�s�







	


�$�


�



�



�






















 �


�


�


�


�
#r#c@�eZdZdS)�SendrecvmsgUDPTestBaseN�rOrPrQrrrrri\�rir�c@rh)�SendmsgUDPTestNrjrrrrrla�rlr�c@rh)�RecvmsgUDPTestNrjrrrrrnermrnr"c@rh)�RecvmsgIntoUDPTestNrjrrrrroirmroc@rT)�SendrecvmsgUDP6TestBasecC� |�|dd�|dd��dSr�r
rrrrrr� z+SendrecvmsgUDP6TestBase.checkRecvmsgAddressN�rOrPrQrrrrrrpn�rpr�r#r$c@rh)�SendmsgUDP6TestNrjrrrrruw�ruc@rh)�RecvmsgUDP6TestNrjrrrrrw}rvrwc@rh)�RecvmsgIntoUDP6TestNrjrrrrrx�rvrxr{c@rh)�RecvmsgRFC3542AncillaryUDP6TestNrjrrrrry��ryc@rh)�#RecvmsgIntoRFC3542AncillaryUDP6TestNrjrrrrr{�sr{c@rh)�SendrecvmsgUDPLITETestBaseNrjrrrrr|�sr|c@rh)�SendmsgUDPLITETestNrjrrrrr}�rvr}c@rh)�RecvmsgUDPLITETestNrjrrrrr~�rvr~c@rh)�RecvmsgIntoUDPLITETestNrjrrrrr�rvrc@rT)�SendrecvmsgUDPLITE6TestBasecCrqr�r
rrrrr�rrz/SendrecvmsgUDPLITE6TestBase.checkRecvmsgAddressNrsrrrrr��sr�c@rh)�SendmsgUDPLITE6TestNrjrrrrr��rzr�c@rh)�RecvmsgUDPLITE6TestNrjrrrrr��rzr�c@rh)�RecvmsgIntoUDPLITE6TestNrjrrrrr��rzr�c@rh)�#RecvmsgRFC3542AncillaryUDPLITE6TestNrjrrrrr��sr�c@rh)�'RecvmsgIntoRFC3542AncillaryUDPLITE6TestNrjrrrrr��s	r�c@rh)�SendrecvmsgTCPTestBaseNrjrrrrr��rmr�c@rh)�SendmsgTCPTestNrjrrrrr��rmr�c@rh)�RecvmsgTCPTestNrjrrrrr��rkr�c@rh)�RecvmsgIntoTCPTestNrjrrrrr��rkr�c@rh)�SendrecvmsgSCTPStreamTestBaseNrjrrrrr�rkr�z6IPPROTO_SCTP: [Errno 62] Protocol not supported on AIXrBr5rc@rh)�SendmsgSCTPStreamTestNrjrrrrr�rvr�cr5)�RecvmsgSCTPStreamTestc
�Tz
tt|���WdSty)}z|jtjkr�|�d�WYd}~dSd}~ww�Nz4sporadic ENOTCONN (kernel issue?) - see issue #13876)rXr�r�rr��ENOTCONNrr�rHr�r`rrr����z$RecvmsgSCTPStreamTest.testRecvmsgEOF�rOrPrQr�rhrrr`rr��r�cr5)�RecvmsgIntoSCTPStreamTestc
r�r�)rXr�r�rr�r�rrr�r`rrr� r�z(RecvmsgIntoSCTPStreamTest.testRecvmsgEOFr�rrr`rr�r�r�c@rh)�SendrecvmsgUnixStreamTestBaseNrjrrrrr�)rmr�rc@rh)�SendmsgUnixStreamTestNrjrrrrr�-rkr�c@rh)�RecvmsgUnixStreamTestNrjrrrrr�2rvr�c@rh)�RecvmsgIntoUnixStreamTestNrjrrrrr�8rvr�rvr�c@rh)�RecvmsgSCMRightsStreamTestNrjrrrrr�>rkr�c@rh)�RecvmsgIntoSCMRightsStreamTestNrjrrrrr�Crvr�csLeZdZ�fdd�ZejZeed�rdZ	dd�Z
�ZSdZ	dd�Z
�ZS)	�InterruptedTimeoutBasecs2t���t�tjdd��}|�tjtj|�dS)NcSsddSr�r)�signumr8rrrr(Wsz.InterruptedTimeoutBase.setUp.<locals>.<lambda>)rXrIr|r}rd)rH�orig_alrm_handlerr`rrrITs

�zInterruptedTimeoutBase.setUp�	setitimerg�������?cCst�tj|�dSr8)r|r��ITIMER_REAL�rH�secondsrrr�setAlarmcr�zInterruptedTimeoutBase.setAlarmr�cCst�|�dSr8)r|rsr�rrrr�ir�)rOrPrQrIrrr;rr|�
alarm_timer�rhrrr`rr�Os
r��siginterruptrsr�z+Don't have signal.alarm or signal.setitimercsleZdZ�fdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Ze	e
j
d
�dd��Ze	e
j
d�dd��Z�Z
S)�InterruptedRecvTimeoutTestcr7r8)rXrIrCrAr;rGr`rrrIvr8z InterruptedRecvTimeoutTest.setUpc	Osrz2|�|j�|�t��}||i|��Wd�n1swYW|�d�dSW|�d�dS|�d�wr�)r�r�rgr~�rHr�r^r_rrrrr�checkInterruptedRecvzs��z/InterruptedRecvTimeoutTest.checkInterruptedRecvcC�|�|jjd�dSr�)r�rCr�rGrrr�testInterruptedRecvTimeout�r�z5InterruptedRecvTimeoutTest.testInterruptedRecvTimeoutcC�|�|jjtd��dSr�)r�rC�	recv_intor/rGrrr�testInterruptedRecvIntoTimeout�rz9InterruptedRecvTimeoutTest.testInterruptedRecvIntoTimeoutcCr�r�)r�rCr:rGrrr�testInterruptedRecvfromTimeout�r�z9InterruptedRecvTimeoutTest.testInterruptedRecvfromTimeoutcCr�r�)r�rC�
recvfrom_intor/rGrrr�"testInterruptedRecvfromIntoTimeout�rz=InterruptedRecvTimeoutTest.testInterruptedRecvfromIntoTimeoutr�cCr�r�)r�rCr�rGrrr�testInterruptedRecvmsgTimeout�rRz8InterruptedRecvTimeoutTest.testInterruptedRecvmsgTimeoutr"cCs|�|jjtd�g�dSr�)r�rCr"r/rGrrr�!testInterruptedRecvmsgIntoTimeout�rUz<InterruptedRecvTimeoutTest.testInterruptedRecvmsgIntoTimeout)rOrPrQrIr�r�r�r�r�rDrr�r�rhrrr`rr�os



r�csteZdZ�fdd�Zdd�Zdd�Ze�dd�d	d
��Ze�dd�dd��Z	e�dd�e
ejd
�dd���Z�Z
S)�InterruptedSendTimeoutTestcspt���|��|_|�|jj�tj|jd�}|�	�|j
��\|_}|�|jj�|�
�|j�|j�dS)N)�target)rXrIr�r�rdrrZ�Thread�	doConnect�startrCr�r�rArAr;)rH�
cli_threadr�r`rrrI�s

z InterruptedSendTimeoutTest.setUpcCs|j�|j�dSr8)r�r�r�rGrrrr��r�z$InterruptedSendTimeoutTest.doConnectc	OsXz%|�t��}	|�|j�||i|��q1swYW|�d�dS|�d�w�NTr)rgr~r�r�r�rrr�checkInterruptedSend�s��z/InterruptedSendTimeoutTest.checkInterruptedSendrrIcCr��Nri)r�r�r�rGrrr�testInterruptedSendTimeout�rRz5InterruptedSendTimeoutTest.testInterruptedSendTimeoutcCs|�|jjd|j�dSr�)r�r�ror�rGrrr�testInterruptedSendtoTimeout�s�z7InterruptedSendTimeoutTest.testInterruptedSendtoTimeoutr�cCs|�|jjdg�dSr�)r�r�r�rGrrr�testInterruptedSendmsgTimeout�r1z8InterruptedSendTimeoutTest.testInterruptedSendmsgTimeout)rOrPrQrIr�r�r�requires_mac_verr�r�rDrr�rhrrr`rr��s	





r�c@r@)�
TCPCloserTestcCsh|j��\}}|��|j}t�|gggd�\}}}|�||g�|�|�d�d�|��|��dS)N��?r�r�)rCr�rr�r�r�r�)rHr�r��sdr�r�rJrrr�	testClose�szTCPCloserTest.testClosecCs |j�t|jf�t�d�dS�Nr�)r�r�r�rEr�r�rGrrr�
_testClose�rbzTCPCloserTest._testCloseN)rOrPrQr�r�rrrrr���
r�c@sNeZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dS)�BasicSocketPairTestr�cCr�r�)r�rYr�rrrrY�r�zBasicSocketPairTest.__init__cCs\|�|tj�ttd�r|�|jtj�n|�|jtj�|�|jtj�|�|j	d�dS)Nrr)
rQrrr�r]rrBr,r5r^rrrr�_check_defaults�s
z#BasicSocketPairTest._check_defaultscC�|�|j�dSr8)r�r�rGrrr�
_testDefaults�rz!BasicSocketPairTest._testDefaultscCr�r8)r�rCrGrrr�testDefaults�rz BasicSocketPairTest.testDefaultscCr�r�)rCr�r�r�r�rrrr��r�zBasicSocketPairTest.testRecvcCr�r8)r�r�r�rGrrrr�rzBasicSocketPairTest._testRecvcCr�r8)rCr�r�rGrrr�testSendrzBasicSocketPairTest.testSendcCr�r�)r�r�r�r�r�rrr�	_testSendr�zBasicSocketPairTest._testSendNr�)rOrPrQrYr�r�r�r�r�r�r�rrrrr��s
	r�c@s�eZdZd&dd�Zdd�Zdd�Zdd	�Zejd
d��Z	e�e�Z
e�e
ed�d
�e�ddd�dd���Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%S)'�NonBlockingTCPTestsr�cCst��|_tj||d�dSr�)rZr��eventr�rYr�rrrrYr8zNonBlockingTCPTests.__init__cCsl|�|j��|�|dk}|�|��|�tdur4|du}t�|tjtj�}|�t|tj@�|�dSdS)N�)	r�rCr�getblockingr
�F_GETFLr�
O_NONBLOCK�bool)rHrr;�blocking�fd_blocking�flagrrr�assert_sock_timeouts�z'NonBlockingTCPTests.assert_sock_timeoutcCs�|j�d�|�|jd�|j�d�|�|jd�|j�d�|�|jd�|j�d�|�|jd�|j�d�|�|jd�|j�d�|�|jd�dS)NTFr�rr)rCr�r�rArGrrr�testSetBlocking#sz#NonBlockingTCPTests.testSetBlockingcCr�r8rrGrrr�_testSetBlocking7r�z$NonBlockingTCPTests._testSetBlockingcCsbddl}|j|jkr|�d�|j�d�|�|j��d�|j�|jd�|�|j���dS)Nrzneeds UINT_MAX < ULONG_MAXFr�r�)	r�r��	ULONG_MAXrrrCr�r�rr_r�rrr�testSetBlocking_overflow:s
z,NonBlockingTCPTests.testSetBlocking_overflowr�ztest needs socket.SOCK_NONBLOCKr���cCs4|j��t�tjtjtjB�|_|�|jd�dSr�)rCrrrBr5r�r�rGrrr�testInitNonBlockingIs


�z'NonBlockingTCPTests.testInitNonBlockingcCr�r8rrGrrr�_testInitNonBlockingSr�z(NonBlockingTCPTests._testInitNonBlockingcCsbtd��#|j�d�|j��\}}|�|j�|�|���Wd�dS1s*wYdS)Nr)r=rCrAr�rdrr_rr�rrr�testInheritFlagsBlockingVs
"�z,NonBlockingTCPTests.testInheritFlagsBlockingcC�|j�t|jf�dSr8�r�r�r�rErGrrr�_testInheritFlagsBlocking_r�z-NonBlockingTCPTests._testInheritFlagsBlockingcCshd}t|��$|j�d�|j��\}}|�|j�|�|��|�Wd�dS1s-wYdS)Ng4@r)r=rCrAr�rdrr�r)rH�default_timeoutr�r�rrr�testInheritFlagsTimeoutbs
"�z+NonBlockingTCPTests.testInheritFlagsTimeoutcCr�r8r�rGrrr�_testInheritFlagsTimeoutmr�z,NonBlockingTCPTests._testInheritFlagsTimeoutcCs�|j�d�t��}|�t��|j��\}}Wd�n1s!wYt��|}|�|d�|j�	�t
�
|jgggtj�\}}}|j|vrO|�
d�|j��\}}|�|j�|�|���dS)NFr�z'Error trying to do accept after select.)rCr�r��	monotonicrg�BlockingIOErrorr�r�r�rr�r�LONG_TIMEOUTrcrdrr_r)rH�
start_timer�r��dtr�r�rJrrr�
testAcceptps�


zNonBlockingTCPTests.testAcceptcCs |j��|j�t|jf�dSr8)r�r�r�r�r�rErGrrr�_testAccept�s
zNonBlockingTCPTests._testAcceptcCs�|j��\}}|�|j�|�d�|�t��|�tt	��}Wd�n1s)wY|j
��t�|gggt
j�\}}}||vrI|�d�|�tt	��}|�|t	�dS)NFz0Error during select call to non-blocking socket.)rCr�rdrr�rgr�r�rbr�r�rr�rr�rcr�)rHr�r�r�r�r�rJrrrr��s
�

zNonBlockingTCPTests.testRecvcCs,|j�t|jf�|j��|j�t�dSr8)r�r�r�rEr�r�rr�rGrrrr��s
zNonBlockingTCPTests._testRecvNr�)rOrPrQrYr�r�r�rr�r��_testSetBlocking_overflowr�r�rr�requires_linux_versionr�r�r�r�r�r�r�r�r�r�rrrrr�s,


�	r�c@s�eZdZdZdZdZdZdZdZe	Z
dZe	Zd;d	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4�Z"d5d6�Z#d7d8�Z$d9d:�Z%dS)<�FileObjectClassTestCaseaoUnit tests for the object returned by socket.makefile()

    self.read_file is the io object returned by makefile() on
    the client connection.  You can read from this file to
    get output from the server.

    self.write_file is the io object returned by makefile() on the
    server connection.  You can write to this file to send output
    to the client.
    r�r�strictNrr�r�cCr�r�r�r�rrrrY�r�z FileObjectClassTestCase.__init__cCsRdd�td�D�\|_|_|_|_t�|�|jj|j	|j
|j|j|j
d�|_dS)NcS�g|]}t���qSr)rZr��r8r?rrrr:�s�z1FileObjectClassTestCase.setUp.<locals>.<listcomp>rn�r��errors�newline)r��evt1�evt2�
serv_finished�cli_finishedr�rIr�r��	read_modersr�r�r��	read_filerGrrrrI�s�
�zFileObjectClassTestCase.setUpcC�6|j��|j��|�|jj�d|_t�|�dSr8)r�rr�rrO�closedr�rLrGrrrrL��


z FileObjectClassTestCase.tearDowncCs0t�|�|jj|j|j|j|j|jd�|_	dS)Nr�)
r�r�r�r��
write_modersr�r�r��
write_filerGrrrr��s
�z#FileObjectClassTestCase.clientSetUpcCr�r8)r�rrrrOr�r�r�rGrrrr��r�z&FileObjectClassTestCase.clientTearDowncCsv|j�d�|j�d�|�t|jjd�|�t��}|j�d�Wd�n1s+wY|�dt|j	��dS)Nr�r�z!cannot read from timed out object)
r�rAr�r�rgr�rrWrErp)rH�ctxrrr�testReadAfterTimeout�s�z,FileObjectClassTestCase.testReadAfterTimeoutcCs.|j�|jdd��|j��|j��dS)Nrr�)rr��	write_msg�flushr�r�rGrrr�_testReadAfterTimeout�s
z-FileObjectClassTestCase._testReadAfterTimeoutcCs<|j�t|j�d�}|j�d�}||}|�||j�dSrK)r�r�rb�read_msgr�)rH�	first_seg�
second_segr�rrr�
testSmallRead�sz%FileObjectClassTestCase.testSmallReadcC�|j�|j�|j��dSr8�rr�rrrGrrr�_testSmallRead�r�z&FileObjectClassTestCase._testSmallReadcC�|j��}|�||j�dSr8)r�r�r�rr�rrr�testFullRead�
z$FileObjectClassTestCase.testFullReadcCrr8)rr�rrrGrrr�
_testFullReadr�z%FileObjectClassTestCase._testFullReadcCs<t|j��}	|j�d�}|sn||7}q|�||j�dSr)r,rr�r�r�)rHr%�charrrr�testUnbufferedRead
s�z*FileObjectClassTestCase.testUnbufferedReadcCrr8rrGrrr�_testUnbufferedReadr�z+FileObjectClassTestCase._testUnbufferedReadcCrr8)r��readliner�r�rH�linerrr�testReadlinerz$FileObjectClassTestCase.testReadlinecCrr8rrGrrr�
_testReadliner�z%FileObjectClassTestCase._testReadlinecCs&|j��|j��}|�||j�dSr8)r�rr�r�r�rr�rrr�testCloseAfterMakefile!s

z.FileObjectClassTestCase.testCloseAfterMakefilecCrr8rrGrrr�_testCloseAfterMakefile(r�z/FileObjectClassTestCase._testCloseAfterMakefilecCs@|j��|j�tt��}t|jt�r|�	�}|�
||j�dSr8)r�rr�r�rbr�r+rrE�decoder�r�rrr�testMakefileAfterMakefileClose,s

z6FileObjectClassTestCase.testMakefileAfterMakefileClosecCrr8rrGrrr�_testMakefileAfterMakefileClose3r�z7FileObjectClassTestCase._testMakefileAfterMakefileClosecC�|�|jj�dSr8)rOr�r�rGrrr�testClosedAttr7r�z&FileObjectClassTestCase.testClosedAttrcCrr8)rOrr�rGrrr�_testClosedAttr:r�z'FileObjectClassTestCase._testClosedAttrcC�,|�|jj|j�|�|jj|j���dSr8)r�r�r�r�r9r�rXrGrrr�testAttributes=�z&FileObjectClassTestCase.testAttributescCr"r8)r�rr�rr9r�rXrGrrr�_testAttributesAr$z'FileObjectClassTestCase._testAttributescCs8|j��|�t|jj�|j��|�t|jj�dSr8)r�rrgr	rXr�rr�rGrrr�
testRealCloseEs

z%FileObjectClassTestCase.testRealClosecCr�r8rrGrrr�_testRealCloseKr�z&FileObjectClassTestCase._testRealCloser�)&rOrPrQrgrsr�r�r�r�r�rrrrYrIrLr�r�rrr
r
rrrrrrrrrrr r!r#r%r&r'rrrrr��sF


r�c@sdeZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�ZdS)�!UnbufferedFileObjectClassTestCasea�Repeat the tests from FileObjectClassTestCase with bufsize==0.

    In this case (and in this case only), it should be possible to
    create a file object, read a line from it, create another file
    object, read another line from it, without loss of data in the
    first file object's buffer.  Note that http.client relies on this
    when reading multiple requests from the same socket.rcCsL|j��}|�|d|j�|j�dd�|_|j��}|�|d|j�dS)N�A. rr�B. )r�rr�rr�r�rrrr�testUnbufferedReadline[s


z8UnbufferedFileObjectClassTestCase.testUnbufferedReadlinecCs2|j�d|j�|j�d|j�|j��dS)Nr)r*rrGrrr�_testUnbufferedReadlinecsz9UnbufferedFileObjectClassTestCase._testUnbufferedReadlinecCsD|j��|j�d�}|�||j�|j��|�t|jjd�dSr�)r�rr�r�rr�rgrr�rrr�testMakefileClosehs


z3UnbufferedFileObjectClassTestCase.testMakefileClosecCrr8rrGrrr�_testMakefileCloseqr�z4UnbufferedFileObjectClassTestCase._testMakefileClosecCs6t�|j�}|j��t�|j�}|�|d|�dSr)r�r�r�r�rr�)rH�refcount_before�refcount_afterrrr�testMakefileCloseSocketDestroyus
z@UnbufferedFileObjectClassTestCase.testMakefileCloseSocketDestroycCr�r8rrGrrr�_testMakefileCloseSocketDestroy{r�zAUnbufferedFileObjectClassTestCase._testMakefileCloseSocketDestroycCs|j�d�|�|j�td��d�|�|j�t|j�d�d�|j	�
�|j�d�|j�t|j�d�}|durKt
�d�|j�t|j�d�}td�}|j�|�}|�|d�||d|�}|�||j�|�|j�td��d�|�|j�d�d�dS)NFrr�r�g�?r�r�)r�r�r�r��readintor/r�rbrr�rr�r�r�r�)rHrr%r�r�rrr�testSmallReadNonBlocking�s 

z:UnbufferedFileObjectClassTestCase.testSmallReadNonBlockingcCs>|j�d�|j�|j�|j��|j��|j�d�dS)Nr��@)	r�r�rr�rrr�rr�rGrrr�_testSmallReadNonBlocking�s


z;UnbufferedFileObjectClassTestCase._testSmallReadNonBlockingcCs&|j�d�|jr|�|j�dSdS)Nr5)r�r��serv_skippedrrrGrrr�testWriteNonBlocking�s�z6UnbufferedFileObjectClassTestCase.testWriteNonBlockingcCsvd|_|j�d�dtj}d}|j�|�}|�|d�t|�D]}|j�|�}|dur/dS|�|d�q d|_dS)NFr{rrz$failed to saturate the socket buffer)	r7r�r�rr�rr�r�r�)rH�BIG�LIMITr�r?rrr�_testWriteNonBlocking�s

z7UnbufferedFileObjectClassTestCase._testWriteNonBlockingN)rOrPrQrgrsr+r,r-r.r1r2r4r6r8r;rrrrr(Os		r(c@�eZdZdZdS)�#LineBufferedFileObjectClassTestCaser�N�rOrPrQrsrrrrr=��r=c@r<)�$SmallBufferedFileObjectClassTestCaser�Nr>rrrrr@�r?r@c@s*eZdZdZdZe�d�ZdZeZ	dZ
dS)�"UnicodeReadFileObjectClassTestCase�=Tests for socket.makefile() in text mode (rather than binary)rrr�rkN�rOrPrQrgr�r�rrrrr�rrrrrA�s
rAc@s*eZdZdZdZeZdZe�d�Z	dZ
dS)�#UnicodeWriteFileObjectClassTestCaserBrr�rrkN)rOrPrQrgr�r�rrrrr�rrrrrD�s
rDc@s0eZdZdZdZe�d�ZdZe�d�Z	dZ
dS)�'UnicodeReadWriteFileObjectClassTestCaserBrrr�rkNrCrrrrrE�s

rEc@r)�NetworkConnectionTestzProve network connection.cCst�t|jf�|_|j|_dSr8)r�create_connectionr�rEr�r�rGrrrr��sz!NetworkConnectionTest.clientSetUpN)rOrPrQrgr�rrrrrF�rrFc@r<)�
BasicTCPTest2zLTests that NetworkConnection does not break existing TCP functionality.
    N)rOrPrQrgrrrrrH�srHc@sDeZdZGdd�dej�Zejdd��Zdd�Zdd�Z	d	d
�Z
dS)�NetworkConnectionNoServerc@rT)z$NetworkConnectionNoServer.MockSocketcGr�)Nz	timed out)r�rrrrr��r�z,NetworkConnectionNoServer.MockSocket.connectN)rOrPrQr�rrrr�
MockSocket�srJccs,�tj}|jt_z	dVW|t_dS|t_w)z*Return a socket which times out on connectN)rrJ)rH�
old_socketrrr�mocked_socket_module�s�z.NetworkConnectionNoServer.mocked_socket_modulecCsrt��}t�tjtj�}|�|j�|�t��}|�	t
|f�Wd�n1s)wY|�|jj
t
j�dSr8)rr5rrBr5rdrrgrr�r�r�rpr��ECONNREFUSED)rHrEr�rrrrr�test_connects�z&NetworkConnectionNoServer.test_connectcCs\t��}|�t��}t�t|f�Wd�n1swYt��}|�|j	j
|�dSr8)rr5rgrrrGr��get_socket_conn_refused_errsrWrpr�)rHrErr�expected_errnosrrr�test_create_connections�z0NetworkConnectionNoServer.test_create_connectioncCs�|���Lz	t�tdf�Wn$tyYn)ty2}ztjs'|jtj	kr(�WYd}~nd}~ww|�
d�Wd�dSWd�dSWd�dS1sSwYdS)NrzTimeoutError not raised)rLrrGr�r�rrrcr��EAFNOSUPPORTrcrorrr�test_create_connection_timeout s"
�����"�z8NetworkConnectionNoServer.test_create_connection_timeoutN)rOrPrQrrJ�
contextlib�contextmanagerrLrNrQrSrrrrrI�s
	rIc@sveZdZddd�Zdd�Zdd�Zdd	�ZeZd
d�ZeZ	dd
�Z
eZdd�ZeZ
dd�ZeZdd�ZeZdd�ZdS)�NetworkConnectionAttributesTestr�cCr�r�r�r�rrrrY1r�z(NetworkConnectionAttributesTest.__init__cCst��|_dSr8)rr5�source_portrGrrrr�5r�z+NetworkConnectionAttributesTest.clientSetUpcCr�r8r�rGrrrr�8r�z.NetworkConnectionAttributesTest.clientTearDowncCs|j��\}}|��dSr8)rCr�rr�rrr�_justAccept=sz+NetworkConnectionAttributesTest._justAcceptcCs:tjt|jftjd�|_|�|jj�|�	|jj
d�dS)Nrjr�)rrGr�rErrr�rdrr�r]rGrrr�_testFamilyBs
�z+NetworkConnectionAttributesTest._testFamilycCsJtjt|jftjd|jfd�|_|�|jj	�|�
|j��d|j�dS)Nrk)r;�source_addressr�)rrGr�rErrrWr�rdrr�r�rGrrr�_testSourceAddressIs�z2NetworkConnectionAttributesTest._testSourceAddressc	Csn|�t��du�t�d�zt�t|jf�|_|�|jj	�Wt�d�nt�d�w|�
|j��d�dS)Nr��rOrr9r:rGr�rEr�rdrr�rrGrrr�_testTimeoutDefaultSs
z3NetworkConnectionAttributesTest._testTimeoutDefaultc	Csr|�t��du�t�d�ztjt|jfdd�|_|�|jj	�Wt�d�nt�d�w|�
|j��d�dS�N�rjr\rGrrr�_testTimeoutNone_s
z0NetworkConnectionAttributesTest._testTimeoutNonecCs,tjt|jfdd�|_|�|j��d�dSr^)rrGr�rEr�r�rrGrrr�_testTimeoutValueNamedksz6NetworkConnectionAttributesTest._testTimeoutValueNamedcCs8t�t|jfd�|_|�|jj�|�|j��d�dS)Nr_)	rrGr�rEr�rdrr�rrGrrr�_testTimeoutValueNonamedpsz8NetworkConnectionAttributesTest._testTimeoutValueNonamedNr�)rOrPrQrYr�r�rX�
testFamilyrY�testSourceAddressr[�testTimeoutDefaultr]�testTimeoutNoner`�testTimeoutValueNamedra�testTimeoutValueNonamedrbrrrrrV/s"
	rVc@sBeZdZddd�Zdd�Zdd�Zdd	�ZeZd
d�Zdd
�Z	dS)�NetworkConnectionBehaviourTestr�cCr�r�r�r�rrrrYxr�z'NetworkConnectionBehaviourTest.__init__cCr�r8rrGrrrr�|r�z*NetworkConnectionBehaviourTest.clientSetUpcCr�r8r�rGrrrr�r�z-NetworkConnectionBehaviourTest.clientTearDowncCs2|j��\}}|�|j�t�d�|�d�dS)Nr��done!)rCr�rdrr�r�r�r�rrr�testInsideTimeout��
z0NetworkConnectionBehaviourTest.testInsideTimeoutcCs0t�t|jf�|_}|�d�}|�|d�dS)Nr2rj)rrGr�rEr�r�r�)rHrr5rrr�_testInsideTimeout�s
z1NetworkConnectionBehaviourTest._testInsideTimeoutcs2tjt|jfdd�|_�|�t�fdd��dS)Nr�rjcs
��d�S)Nr2)r�r�rrrr(�rzDNetworkConnectionBehaviourTest._testOutsideTimeout.<locals>.<lambda>)rrGr�rEr�rgr�rGrrnr�_testOutsideTimeout�sz2NetworkConnectionBehaviourTest._testOutsideTimeoutNr�)
rOrPrQrYr�r�rk�testOutsideTimeoutrmrorrrrrivs
ric@s6eZdZdd�Zdd�Ze�eed�d�dd��Z	d	S)
�TCPTimeoutTestc��fdd�}��t|d�dS)Ncs�j�d��j��dSr�)rCrAr�r%rGrr�
raise_timeout�r�z4TCPTimeoutTest.testTCPTimeout.<locals>.raise_timeoutz*Error generating a timeout exception (TCP)�rgr��rHrsrrGr�testTCPTimeout���zTCPTimeoutTest.testTCPTimeoutcCsvd}z
|j�d�|j��}Wn ty|�d�Ynty'd}Yn	|�d�Y|s9|�d�dSdS)NFr�z%caught timeout instead of error (TCP)Tz!caught unexpected exception (TCP)z3accept() returned success when we did not expect it)rCrAr�r�rcr�rH�okr�rrr�testTimeoutZero�s�zTCPTimeoutTest.testTimeoutZerorsztest needs signal.alarm()c
s*|j�d�Gdd�dt���fdd�}t�tj|�}zqzNzEzt�d�|j��}Wn,ty8|�d�Yn$�y@Yn|�dt	�
�dd�t��f�Yn|�d	�Wt�d
�nt�d
�wWn�yx|�d�YnwWt�tj|�dSWt�tj|�dSt�tj|�w)Nr5c@rh)z4TCPTimeoutTest.testInterruptedTimeout.<locals>.AlarmNrjrrrr�Alarm�sr{cs��r8r)r|r8�r{rr�
alarm_handler�r�z<TCPTimeoutTest.testInterruptedTimeout.<locals>.alarm_handlerr�zcaught timeout instead of Alarmz3caught other exception instead of Alarm: %s(%s):
%sznothing caughtrzgot Alarm in wrong place)
rCrArr|r}rsr�r�rcr��exc_info�	traceback�
format_exc)rHr}r�r�rr|r�testInterruptedTimeout�s4

�
����"z%TCPTimeoutTest.testInterruptedTimeoutN)
rOrPrQrvrzr�r�rr|r�rrrrrq�s�rqc@r@)�UDPTimeoutTestcrr)Nc��j�d��j�d�dS�Nr�r��rCrAr�r%rGrrrs�r�z4UDPTimeoutTest.testUDPTimeout.<locals>.raise_timeoutz*Error generating a timeout exception (UDP)rtrurrGr�testUDPTimeout�rwzUDPTimeoutTest.testUDPTimeoutcC�xd}z|j�d�|j�d�}Wn ty|�d�Ynty(d}Yn	|�d�Y|s:|�d�dSdS)NFr�r�z%caught timeout instead of error (UDP)Tz!caught unexpected exception (UDP)�1recv() returned success when we did not expect it�rCrAr�r�rcrrxrrrrz���zUDPTimeoutTest.testTimeoutZeroN)rOrPrQr�rzrrrrr��sr�c@r@)�UDPLITETimeoutTestcrr)Ncr�r�r�r%rGrrrs�r�z<UDPLITETimeoutTest.testUDPLITETimeout.<locals>.raise_timeoutz.Error generating a timeout exception (UDPLITE)rtrurrGr�testUDPLITETimeout�rwz%UDPLITETimeoutTest.testUDPLITETimeoutcCr�)NFr�r�z)caught timeout instead of error (UDPLITE)Tz%caught unexpected exception (UDPLITE)r�r�rxrrrrz�r�z"UDPLITETimeoutTest.testTimeoutZeroN)rOrPrQr�rzrrrrr��sr�c@r@)�TestExceptionscCsf|�ttt��|�ttjt��|�ttjt��|�ttjt��|�tj	t�|�tjt
�dSr8)rO�
issubclassrrrrhrir;�assertIs�errorr�rGrrr�testExceptionTreesz TestExceptions.testExceptionTreecCsxt�tjtjd�}t�tjtjd|���}|��|�|j�|�t��|�	d�Wd�dS1s5wYdS)NrF)
rrBr5rXrrdr�rgrr�)rH�sock0rrrr�test_setblocking_invalidfds�"�z)TestExceptions.test_setblocking_invalidfdN)rOrPrQr�r�rrrrr��sr�r��Linux specific testc@rz)�TestLinuxAbstractNamespace�lc
Cs�d}t�tjtj��_}|�|�|��t�tjtj��5}|�|���|��d�}|�|��|�|�|�	�|�Wd�n1sEwYWd�n1sTwYWd�dSWd�dS1slwYdS)Nspython-test-hello�r)
rrr5rprFr�r�r�r��getpeername)rHr!�s1r��s3rrr�testLinuxAbstractNamespaces
����"�z5TestLinuxAbstractNamespace.testLinuxAbstractNamespacecCsbdd|jd}t�tjtj��}|�|�|�|��|�Wd�dS1s*wYdS)Nr2�hr�)�
UNIX_PATH_MAXrrr5rpr�r��rHr!r!rrr�testMaxName%s

"�z&TestLinuxAbstractNamespace.testMaxNamecCsTdd|j}t�tjtj��}|�t|j|�Wd�dS1s#wYdS)N��h)r�rrr5rgrrpr�rrr�testNameOverflow+s"�z+TestLinuxAbstractNamespace.testNameOverflowcCsDt�tjtj�}z|�d�|�|��d�W|��dS|��w)Nz
pythontest�
pythontest)rrr5rpr�r�rr[rrr�testStrName0s

z&TestLinuxAbstractNamespace.testStrNamecCsTt�tjtj��}|�td��|�|��d�Wd�dS1s#wYdS)Nr�)rrr5rpr/r�r�r[rrr�testBytearrayName9s"�z,TestLinuxAbstractNamespace.testBytearrayNamec	Cs�d}t�tjtj��M}|�d�|�|��|�t�tjtj��}|�d�|�|��|�|�|��|���Wd�n1sBwYWd�dSWd�dS1sZwYdS)Ns
^[0-9a-f]{5}rk)rrr5rp�assertRegexr�r�)rH�abstract_addressr�r�rrr�testAutobind?s

��"�z'TestLinuxAbstractNamespace.testAutobindN)
rOrPrQr�r�r�r�r�r�r�rrrrr�s	r�ztest needs socket.AF_UNIXc@sneZdZdd�Zdd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	dd�Z
dd�Ze�
ejdkd�dd��ZdS)�TestUnixDomaincCr�r8)rrr5rrGrrrrIPr�zTestUnixDomain.setUpcCr�r8)rrrGrrrrLSr�zTestUnixDomain.tearDownc
Cs8zt�|�WSty|�d�|t����YdSw)NzBPathname {0!a} cannot be represented in file system encoding {1!r})r�fsencodergrrrIr��getfilesystemencoding�rHr
rrr�encodedVs�
��zTestUnixDomain.encodedc
CsZz	t�||�WdSty,}zt|�dkr |�d�|��n�WYd}~dSd}~ww)NzAF_UNIX path too longz6Pathname {0!a} is too long to serve as an AF_UNIX path)rr
rrErrrI)rHrr
r�rrrrpas����zTestUnixDomain.bindcCs|�|j��d�dS)N)rkN)rWrr�rGrrrr�mrnzTestUnixDomain.testUnboundcCs@tj�tj�}|�|j|�|�tj|�|�	|j�
�|�dSr8)rr
�abspathr�TESTFNrprrdrr�r�r�rrr�testStrAddrqszTestUnixDomain.testStrAddrcCsFtj�tj�}|�|j|�|��|�tj	|�|�
|j��|�dSr8)rr
r�rr�rprr�rdrr�r�r�rrr�
testBytesAddrxszTestUnixDomain.testBytesAddrcCsRtj�tj�}|�|�}|�|j|�dd��|�	tj
|�|�|j��|�dS)N�ascii�surrogateescape)
rr
r�r�TESTFN_UNICODEr�rprrrdrr�r�)rHr
rkrrr�testSurrogateescapeBinds

z&TestUnixDomain.testSurrogateescapeBindcCsTtjdur
|�d�tj�tj�}|�|j|�|�tj	|�|�
|j��|�dS)Nz!No unencodable filename available)r�TESTFN_UNENCODABLErrrr
r�rprrdrr�r�r�rrr�testUnencodableAddr�s

z"TestUnixDomain.testUnencodableAddrr�r�cCr�)Nrk)rgrrrprGrrr�testEmptyAddress�r1zTestUnixDomain.testEmptyAddressN)rOrPrQrIrLr�rpr�r�r�r�r�r�r�r�r�r�rrrrr�Ms	
r�c@s�eZdZdZddd�Zdd�Zdd�Zd	d
�ZeZdd�Z	eZ
d
d�Zdd�Zdd�Z
eZdd�ZeZdd�Zdd�Zdd�ZeZdS)�BufferIOTestzF
    Test the buffer versions of socket.recv() and socket.send().
    r�cCr�r�r�r�rrrrY�r�zBufferIOTest.__init__cCsZt�ddgtt��}|j�|�}|�|tt��|��}|dtt��}|�|t�dS�NrFr)rGrbr�r�r�r�r��rHr%r�r�rrr�testRecvIntoArray�szBufferIOTest.testRecvIntoArraycC�tt�}|j�|�dSr8�rQr�r�r��rHr%rrr�_testRecvIntoArray��zBufferIOTest._testRecvIntoArraycCsDtd�}|j�|�}|�|tt��|dtt��}|�|t�dSr�)r/r�r�r�rbr�r�rrr�testRecvIntoBytearray�s
z"BufferIOTest.testRecvIntoBytearraycCsHtd�}|j�t|��}|�|tt��|dtt��}|�|t�dSr�)r/r�r�r�r�rbr�r�rrr�testRecvIntoMemoryview��
z#BufferIOTest.testRecvIntoMemoryviewcCs^t�ddgtt��}|j�|�\}}|�|tt��|��}|dtt��}|�|t�dSr�)rGrbr�r�r�r�r��rHr%r�r�r�rrr�testRecvFromIntoArray�sz"BufferIOTest.testRecvFromIntoArraycCr�r8r�r�rrr�_testRecvFromIntoArray�r�z#BufferIOTest._testRecvFromIntoArraycCsHtd�}|j�|�\}}|�|tt��|dtt��}|�|t�dSr�)r/r�r�r�rbr�r�rrr�testRecvFromIntoBytearray�r�z&BufferIOTest.testRecvFromIntoBytearraycCsLtd�}|j�t|��\}}|�|tt��|dtt��}|�|t�dSr�)r/r�r�r�r�rbr�r�rrr�testRecvFromIntoMemoryview�s
z'BufferIOTest.testRecvFromIntoMemoryviewcCs td�}|�t|jj|d�dS)Nrmr�)r/rgr	r�r�r�rrr�testRecvFromIntoSmallBuffer�sz(BufferIOTest.testRecvFromIntoSmallBuffercCr�r8r�rGrrr�_testRecvFromIntoSmallBuffer�rz)BufferIOTest._testRecvFromIntoSmallBuffercCs$t�}|j�|�|j�|d�dSr�)r/r�r�r�rrr�testRecvFromIntoEmptyBuffer�sz(BufferIOTest.testRecvFromIntoEmptyBufferNr�)rOrPrQrgrYr�r�r��_testRecvIntoBytearrayr��_testRecvIntoMemoryviewr�r�r��_testRecvFromIntoBytearrayr��_testRecvFromIntoMemoryviewr�r�r��_testRecvFromIntoEmptyBufferrrrrr��s&
r�i�����c
Cs�ttd�sdSztddd�}Wn
tttfyYdSw|�|D]}|�d�r2Wd�dSq"Wd�dS1s>wYdS)	z�Check if the TIPC module is loaded

    The TIPC module is not loaded automatically on Ubuntu and probably
    other Linux distros.
    �AF_TIPCFz
/proc/modulesrr�ztipc NT)rrr�FileNotFoundError�IsADirectoryErrorr�r�)rrrrr�isTipcAvailable�s$
�
��
��r�z6TIPC module is not loaded, please 'sudo modprobe tipc'c@rT)�TIPCTestcCs�t�tjtj�}t�tjtj�}|�|j�|�|j�|�tjtjd�tjt	t
tf}|�|�tj
t	t
ttt
d�df}|�t|�|�d�\}}|�|��|�|�|t�dS)Nr�r�rr�)rr�rurdrr>rvrw�TIPC_ADDR_NAMESEQ�
TIPC_STYPE�
TIPC_LOWER�
TIPC_UPPERrp�TIPC_ADDR_NAMEr�ror�r:r�r�)rHr�r��srvaddr�sendaddrr��recvaddrrrr�testRDMs �
�zTIPCTest.testRDMN)rOrPrQr�rrrrr�r&r�c@r�)�TIPCThreadableTestr�cCr�r�r�r�rrrrYr�zTIPCThreadableTest.__init__cCs�t�tjtj�|_|�|jj�|j�tjtjd�tj	t
ttf}|j�
|�|j��|��|j��\|_|_|�|jj�dSr)rr�r5r�rdrr>rvrwr�r�r�r�rprFr�r�r�r�)rHr�rrrrI"s�
zTIPCThreadableTest.setUpcCsdt�d�t�tjtj�|_|�|jj�tjt	t
ttt
d�df}|j�
|�|j��|_dS)Nr�r�r)r�r�rr�r5r�rdrr�r�r�r�r�r�r��cliaddr)rHr�rrrr�.s
�zTIPCThreadableTest.clientSetUpcCs,|j�d�}|�|t�|�|j|j�dSr�)r�r�r�r�r�r�r�rrrr�:szTIPCThreadableTest.testStreamcCr�r8r�rGrrrr�?r�zTIPCThreadableTest._testStreamNr�r�rrrrr�s
r�c@s4eZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZdS)�ContextManagersTestcCs�t���}|�|j�Wd�n1swY|�|j�t���}|��Wd�n1s3wY|�|j�t���}|�t|jd�Wd�n1sUwY|�|j�dS�Nrl)rr:r�rOrrgrrrrrr�_testSocketClassFs
�

�
�z$ContextManagersTest._testSocketClasscC�2|j��\}}|�|j�|�d�}|�|�dSr��rCr�rdrr�r�rHr�r�r5rrr�testCreateConnectionBaseTrlz,ContextManagersTest.testCreateConnectionBasecCsl|j��}t�|��}|�|j�|�d�|�|�d�d�Wd�n1s)wY|�	|j�dS)Nrlr�)
rCr�rrGr:r�rr�r�rO�rHr!rrrr�_testCreateConnectionBaseZs

�z-ContextManagersTest._testCreateConnectionBasecCr�r�r�r�rrr�testCreateConnectionClosebrlz-ContextManagersTest.testCreateConnectionClosecCs\|j��}t�|��}|��Wd�n1swY|�|j�|�t|j	d�dSr�)
rCr�rrGrrOr�rgrrr�rrr�_testCreateConnectionClosehs

�z.ContextManagersTest._testCreateConnectionCloseN)rOrPrQr�r�r�r�r�rrrrr�Dsr�c@s�eZdZe�eed�d�e�ddd�dd���Z	dd	�Z
d
d�Zdd
�Ze�
edud�dd��Ze�
edud�dd��Zdd�ZdS)�InheritanceTestrHzSOCK_CLOEXEC not definedr�r�r�cCsZt�tjtjtjB��}|�|jtj�|�|���Wd�dS1s&wYdSr8)rrBr5rHr�r,r:�get_inheritabler[rrr�test_SOCK_CLOEXECqs
�"�z!InheritanceTest.test_SOCK_CLOEXECcCsBt��}|�|�|��d�Wd�dS1swYdSr�)rr�r�rrrr�test_default_inheritablezs"�z(InheritanceTest.test_default_inheritablec	Cs�t��}|�3|��}|��|�|�|��d�Wd�n1s$wYWd�dSWd�dS1s<wYdSr�)rr�rr�r�)rHr�newsockrrr�test_dups��"�zInheritanceTest.test_dupcCsft��}|�#|�d�|�|��d�|�d�|�|��d�Wd�dS1s,wYdS)NTF)r�set_inheritabler�r�rrrr�test_set_inheritable�s

"�z$InheritanceTest.test_set_inheritableNr�cCs�t��}|�2|��}|�|��d�t�|tj�}|tjM}t�|tj|�|�|��d�Wd�dS1s;wYdS)NFT)rrXr�r�r
�F_GETFD�
FD_CLOEXEC�F_SETFD)rHrr�r^rrr�test_get_inheritable_cloexec�s"�z,InheritanceTest.test_get_inheritable_cloexeccCs~t��}|�/|��}|�t�|tj�tj@tj�|�d�|�t�|tj�tj@d�Wd�dS1s8wYdSr�)rrXr�r
r�r�r�)rHrr�rrr�test_set_inheritable_cloexec�s�
�"�z,InheritanceTest.test_set_inheritable_cloexeccCsHt��\}}|�|j�|�|j�|�|��d�|�|��d�dSr�)rr�rdrr�r�)rHr�r�rrr�test_socketpair�s
zInheritanceTest.test_socketpair)rOrPrQr�r�rrrr�r�r�r�r�r�r
r�r�r�rrrrr�ps�	

r�r�zSOCK_NONBLOCK not definedc@s,eZdZddd�Ze�ddd�dd	��Zd
S)�NonblockConstantTestTr�cCs�|r7|�|jtj�|�|��|�|�t�|tjtj	�tj	@�|dkr.|�
|���dS|�|���dS|�|jtj�|�|��d�|�
t�|tjtj	�tj	@�|�|���dSr�)r�r,rr5rrOr
r�rr�r:r�)rHr!�nonblockr;rrr�
checkNonblock�s�	�z"NonblockConstantTest.checkNonblockr�r�r�cCs�t�tjtjtjB��G}|�|�|�d�|j|dd�|�d�|�|�|�d�|j|dd�|�d�|j|dd�|�d�|j|dd�Wd�n1sUwYt��}t�d�t���
}|�|�Wd�n1swwYt�d�t���}|�|d�Wd�n1s�wYt�d�t���}|j|dd�Wd�n1s�wYt�d�t���}|�|d�Wd�n1s�wYt�|�dS)NTF)r�g@rjr�)	rrBr5r�r�r�rAr9r:)rHr!�trrr�test_SOCK_NONBLOCK�sD
�






�

�

�

�

�z'NonblockConstantTest.test_SOCK_NONBLOCKN)Tr�)rOrPrQr�rr�rrrrrr��s
r�r}r~zneed multiprocessingc@s@eZdZedd��Zdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
S)�TestSocketSharingcCsD|��}|��}t�|�}|��\}}|�|�|��|��dSr8)r�r�	fromsharer�rr)r4�q�sdata�messager!r�r�rrr�remoteProcessServer�s

z%TestSocketSharing.remoteProcessServerc	Cs�t��}tj|j|fd�}|��|j�|j�}|j��}|j�	�|�
|�d}|�
|�t�|�}g}	|�
d�}|s>n|�|�q6|�	�d�|�}|�||�|��dS)N�r�r^s
slapmahfroTrQr�)�multiprocessingr��Processrr�rC�share�pidr�rr�rrGr�r�rAr�)	rHrrdr5r�rr!�m�receivedrrr�	testShares*






�
zTestSocketSharing.testSharecCs@|j�t���}|�ttj|dd��|�ttj|d�dS)Nr�rl)rCr
r�getpidrgr	rr)rHr5rrr�testShareLength'sz!TestSocketSharing.testShareLengthcCsf|�|��d�|�|��|���|�|j|j�|�|j|j�|jdkr1|�|j|j�dSdSr�)r�rr]r,r^)rH�org�otherrrr�compareSockets,s
�z TestSocketSharing.compareSocketscCsB|j�t���}t�|�}z|�|j|�W|��dS|��wr8)rCr
rrrrrr)rHr5r!rrr�testShareLocal<s

z TestSocketSharing.testShareLocalc
Cs�tjtjg}tjtjg}|D]B}|D]=}zt�||�}Wn	ty%Yqwz$|�t���}t�	|�}z|�
||�W|��n|��wW|��q|��wqdSr8)rrBr#r5r$rr
rrrrr)rH�families�typesrr��sourcer5�sharedrrr�	testTypesDs$�
��zTestSocketSharing.testTypesN)
rOrPrQr^rrrrrrrrrrr�s

#rc@seZdZdZdZdZdZejZ	e
dd��Ze
dd��Zd	d
�Z
dd�Zd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Z d1d2�Z!d3d4�Z"d5d6�Z#d7d8�Z$d9d:�Z%d;S)<�SendfileUsingSendTestz>
    Test the send() implementation of socket.sendfile().
    i�ryr�cCs�dd�}d�dd�t|j�D��}ttjd��}||j|j�D]}|�|�qWd�n1s1wYttjd��}|��|_	t
|j	�|jksLJ�Wd�dS1sWwYdS)Ncss>�||ksJ�||kr|V||8}||ks|r|VdSdSr8r)�total�steprrr�chunksds��
�z0SendfileUsingSendTest.setUpClass.<locals>.chunksr�cSsg|]
}t�tj����qSr)�random�choice�string�
ascii_lettersr�r�rrrr:ls�z4SendfileUsingSendTest.setUpClass.<locals>.<listcomp>r�r)rAr��BUFSIZErrr��FILESIZEr�r��FILEDATArb)r4r�chunkr�csizerrr�
setUpClassbs
���
"�z SendfileUsingSendTest.setUpClasscCst�tj�dSr8)rrr�)r4rrr�
tearDownClassurOz#SendfileUsingSendTest.tearDownClasscCs8|j�tj�|j��\}}|�|j�|�|j�|Sr8)rCrArr�r��TIMEOUTrdrr�rrr�accept_connys
z!SendfileUsingSendTest.accept_conncCs.g}	|�|j�}|sn|�|�qd�|�S)NTr�)r�r"r�rA)rHr�r
r%rrr�	recv_data�s
�
zSendfileUsingSendTest.recv_datacC�
t|d�S)N�_sendfile_use_send�r�rrrr�meth_from_sock�s
z$SendfileUsingSendTest.meth_from_sockc	Cs�|j��}ttjd�}t�|��<}|�!}|�|�}||�}|�||j	�|�|�
�|j	�Wd�n1s7wYWd�dSWd�dS1sOwYdS)Nr�rCr�rrr�rrGr/r�r#�tell�rHr!�filer�meth�sentrrr�_testRegularFile�s

P�z&SendfileUsingSendTest._testRegularFilecC�6|��}|�|�}|�t|�|j�|�||j�dSr8�r*r+r�rbr#r$�rHr�r5rrr�testRegularFile��
z%SendfileUsingSendTest.testRegularFilec	Cs�|j��}t�|j�}t�|��A}|�&}|�|�}|�||j	�|�|�
�|j	�|�tj|j
|�Wd�n1s<wYWd�dSWd�dS1sTwYdSr8)rCr��io�BytesIOr$rrGr�r�r#r1rgr�r�)rHr!r3rr5rrr�_testNonRegularFile�s

�P�z)SendfileUsingSendTest._testNonRegularFilecCr7r8r8r9rrr�testNonRegularFile�r;z(SendfileUsingSendTest.testNonRegularFilec	Cs�|j��}tjd}t|d��|�tj|�Wd�n1s!wYt|d�}t�|��:}|�}|�	|�}||�}|�
|d�|�
|��d�Wd�n1sUwYWd�dSWd�dS1smwYdS)N�2r�rr)rCr�rr�rrdrrrGr/r�r1)rHr!�filenamer3rr4r5rrr�_testEmptyFileSend�s

�

P�z(SendfileUsingSendTest._testEmptyFileSendcCs"|��}|�|�}|�|d�dSr�)r*r+r�r9rrr�testEmptyFileSend�s
z'SendfileUsingSendTest.testEmptyFileSendc	Cs�|j��}ttjd�}t�|��@}|�%}|�|�}||dd�}|�||j	d�|�|�
�|j	�Wd�n1s;wYWd�dSWd�dS1sSwYdS)Nr�)�offsetr0r2rrr�_testOffset�s

P�z!SendfileUsingSendTest._testOffsetcCsB|��}|�|�}|�t|�|jd�|�||jdd��dS)NrDr8r9rrr�
testOffset�s
z SendfileUsingSendTest.testOffsetc	C�|j��}ttjd�}tj|tjd�}|�>|�#d}|�	|�}|||d�}|�
||�|�
|��|�Wd�n1s>wYWd�dSWd�dS1sVwYdS)Nrrj�GKL�r4�rCr�rrr�rrGrrr/r�r1�rHr!r3rr4r4r5rrr�
_testCount��
�
P�z SendfileUsingSendTest._testCountcC�@d}|��}|�|�}|�t|�|�|�||jd|��dS)NrI�r*r+r�rbr$�rHr4r�r5rrr�	testCount��

zSendfileUsingSendTest.testCountc	CrH)Nrrjr�rJrKrLrrr�_testCountSmall�rNz%SendfileUsingSendTest._testCountSmallcCrOrrPrQrrr�testCountSmall�rSz$SendfileUsingSendTest.testCountSmallc	Cs�|j��}ttjd�}tj|dd��A}|�&}d}|�|�}||d|d�}|�||�|�|�	�|d�Wd�n1s>wYWd�dSWd�dS1sVwYdS)Nrr�rj駆��)rEr4)
rCr�rrr�rrGr/r�r1rLrrr�_testCountWithOffsets

P�z*SendfileUsingSendTest._testCountWithOffsetcCsDd}|��}|�|�}|�t|�|�|�||jd|d��dS)NrVrWrPrQrrr�testCountWithOffsets

z)SendfileUsingSendTest.testCountWithOffsetc	Cs�|j��}ttjd�}t�|��<}|�!}|�d�|�|�}|�	t
||�|�	t
|j|�Wd�n1s7wYWd�dSWd�dS1sOwYdS)NrF)rCr�rrr�rrGr�r/rgr	r��rHr!r3rr4rrr�_testNonBlockings


P�z&SendfileUsingSendTest._testNonBlockingcCs$|��}|�d�r|�d�dSdS)Nryz$was not supposed to receive any data)r*r�rc�rHr�rrr�testNonBlockings
�z%SendfileUsingSendTest.testNonBlockingc	Cs�|j��}ttjd�}tj|tjd�}|�3|�|�	|�}||�}|�
||j�Wd�n1s3wYWd�dSWd�dS1sKwYdS)Nrrj)rCr�rrr�rrGrrr/r�r#r2rrr�_testWithTimeout$s
�
P�z&SendfileUsingSendTest._testWithTimeoutcCr7r8r8r9rrr�testWithTimeout.r;z%SendfileUsingSendTest.testWithTimeoutc	Cs�|j��}ttjd��7}t�|��}|�d�|�|�}|�	t
||�Wd�n1s-wYWd�dSWd�dS1sEwYdS)Nrg{�G�z�?)rCr�rrr�rrGrAr/rgr�rZrrr�_testWithTimeoutTriggeredSend6s


��"�z3SendfileUsingSendTest._testWithTimeoutTriggeredSendcCs |��}|�d�t�d�dS)Ni�Xr�)r*r�r�r�r\rrr�testWithTimeoutTriggeredSend>s
z2SendfileUsingSendTest.testWithTimeoutTriggeredSendcCr�r8rrGrrr�_test_errorsEr�z"SendfileUsingSendTest._test_errorsc	Cs�ttjd��,}tjtjd��}|�|�}|�td||�Wd�n1s&wYWd�n1s5wYttjdd��)}t���}|�|�}|�td||�Wd�n1s^wYWd�n1smwYttjd��R}t���5}|�|�}|jtd||dd	�|jtd||d
d	�|jtd||dd	�|jtd||dd	�Wd�n1s�wYWd�dSWd�dS1s�wYdS)
Nrr]r5rr�zbinary modezpositive integerr@rJr�rr�)	rrr�rr$r/r�r	r�)rHr3r!r4rrr�test_errorsHsJ
����

����

������"�z!SendfileUsingSendTest.test_errorsN)&rOrPrQrgr#r"r$rrr)r^r'r(r*r+r/r6r:r>r?rBrCrFrGrMrRrTrUrXrYr[r]r^r_r`rarbrcrrrrrXsF

		
			
		
rr�z%os.sendfile() required for this test.c@r)�SendfileUsingSendfileTestzB
    Test the sendfile() implementation of socket.sendfile().
    cCr,)Nr�r.rrrrr/fr�z(SendfileUsingSendfileTest.meth_from_sockN)rOrPrQrgr/rrrrrd`srdzAF_ALG requiredc@s|eZdZdd�Ze�dd�dd��Zdd�Ze�dd	�d
d��Ze�dd�d
d��Z	e�dd	�dd��Z
dd�Zdd�ZdS)�LinuxKernelCryptoAPIc
CsZt�tjtjd�}z
|�||f�W|Sty,}z
|��t�t|�||��d}~wwr�)	rr.r+rpr�rr��SkipTestrE)rH�typr9rr�rrr�
create_algms���zLinuxKernelCryptoAPI.create_algrnr2c	Cst�d�}|�dd��r}|��\}}|�|�d�|�|�d�|�Wd�n1s-wY|��\}}|�+|�dtj	�|�dtj	�|�dtj	�|�d	�|�|�d�|�Wd�n1shwYWd�dSWd�dS1s�wYdS)
N�@ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad�hash�sha256sabcr+�a�b�cr�)
rQ�fromhexrhr�rr�r�r�r�MSG_MORE�rHr_�algo�opr�rrr�test_sha256zs$

�
��"�z LinuxKernelCryptoAPI.test_sha256c	Cs�t�d�}|�dd��@}|�tjtjd�|��\}}|�|�d�|�	|�
d�|�Wd�n1s6wYWd�dSWd�dS1sNwYdS)N�(effcdf6ae5eb2fa2d27416d5f184df9c259a7c79rjz
hmac(sha1)sJefeswhat do ya want for nothing?r+)rQrorhr>r�SOL_ALG�ALG_SET_KEYr�rr�r�rqrrr�test_hmac_sha1�s

��"�z#LinuxKernelCryptoAPI.test_hmac_sha1r�c
	Cs"t�d�}t�d�}d}t�d�}t|�}|�dd���}|�tjtj|�|��\}}|� |j	tj
|tjd�|�|�|�
|�|�|�Wd�n1sPwY|��\}}|�|j	|gtj|d�|�
|�|�|�Wd�n1s{wYd	}	|g|	}
|��\}}|�|j	|
tj
|d�|�||	�}Wd�n1s�wY|�
t|�||	�|�
|d|�|�|��\}}|�|j	|gtj|d�|�||	�}Wd�n1s�wY|�
t|�||	�|�
|||	�Wd�dS1�s
wYdS)
N� 06a9214036b8a15b512e03d534120006� 3dafba429d9eb430b422da802c9fac41sSingle block msg� e353779c1079aeb82708942dbe77181a�skcipherzcbc(aes))rs�ivr^)rsr}r�)rQrorbrhr>rrvrwr��
sendmsg_afalg�ALG_OP_ENCRYPTrprr�r��ALG_OP_DECRYPT)
rH�keyr}r��
ciphertext�msglenrrrsr��
multiplier�longmsg�enc�decrrr�test_aes_cbc�sV



�
���
����$�z!LinuxKernelCryptoAPI.test_aes_cbcr�cCs.t�d�}t�d�}t�d�}t�d�}t�d�}t�d�}t|�}t|�}|�dd���_}	|	�tjtj|�|	�tjtjd|�|	�	�\}
}|
�@|
j
tj||tjd	�|
�
|tj�|
�
|�|
�|t|�|�}|�||||��|�|||d��Wd�n1s�wY|	�	�\}
}|
�8||}
|
j
|
gtj||d
�|
�|t|�|�}|�||||��|�|||d��Wd�n1s�wYt�d�j}|	�	�\}
}|
�O||}
|
�|
gtjtj|tj�gtjtj|t|��|gtjtj||�gf�|
�t|
�|�}|�||||��|�|||d��Wd�n	1�s:wY|	�	�\}
}|
�,|||}
|
j
|
gtj||d
�|
�t|
�|�}|�|||d��Wd�n1�swwYWd�dSWd�dS1�s�wYdS)N� c939cc13397c1d37de6ae0e1cb7c423c�b3d8cc017cbb89b39e0f67e2� c3b3c41f113a31b73d9a5cd432103069� 24825602bd12a984e0092d3e448eda5f� 93fe7d9e9bfd10348a5606e5cafa7354� 0032a1dc85f1c9786925a2e71d8272dd�aeadzgcm(aes))rsr}�assoclenr^)rsr}r�r)rQrorbrhr>rrvrw�ALG_SET_AEAD_AUTHSIZEr�r~rrprr�r�r�Structr,r��
ALG_SET_OP�
ALG_SET_IV�ALG_SET_AEAD_ASSOCLENr�)rHr�r}�plain�assoc�expected_ct�expected_tag�taglenr�rrrsr��resr��pack_uint32rrr�test_aead_aes_gcm�sz





�
�
�
��	���� ��,$�z&LinuxKernelCryptoAPI.test_aead_aes_gcmc	Cs�|�dd��D}t�d�}|�tjtj|�|��\}}|�|�d�}|�	t
|�d�Wd�n1s5wYWd�dSWd�dS1sMwYdS)N�rng�drbg_pr_sha256r�)rhr�urandomr>rrvrwr�r�r�rb)rHrr�
extra_seedrsr��rnrrr�test_drbg_pr_sha256�s

��"�z(LinuxKernelCryptoAPI.test_drbg_pr_sha256c	Cs\t�tjtjd�}|��|�t��|��Wd�n1s wY|�t��|jdd�Wd�n1s;wY|�t��
|�d�Wd�n1sUwY|�t��|jtjdd�Wd�n1srwY|�t��|jtjdd�Wd�n1s�wYWd�dSWd�dS1s�wYdS)Nr)rsr�)rsr�r�)rr.r+rgr�r~rrrrr�test_sendmsg_afalg_args
s(
������
"�z,LinuxKernelCryptoAPI.test_sendmsg_afalg_argscCs�t�tjtjd�}|�|j�|�t��
|�d�Wd�n1s$wY|�t	d��
|�d�Wd�n1s?wY|�t��
|�d�Wd�n1sYwY|�t	d��|�d�Wd�dS1suwYdS)Nr)�
tttttttttttttr9z
type too long)�ttttttttttttttr9)r,�?nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnz
name too long)r,�@nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn)
rr.r+rdrrgr�rpr�r	rrrr�test_length_restrictions���"�z,LinuxKernelCryptoAPI.test_length_restrictionN)
rOrPrQrhrr�rtrxr�r�r�r�r�rrrrrejs




(

>

rer�r�c@rT)�TestMacOSTCPFlagscCs|�tj�dSr8)rOr�
TCP_KEEPALIVErGrrr�test_tcp_keepalive0rz$TestMacOSTCPFlags.test_tcp_keepaliveN)rOrPrQr�rrrrr�.rVr��winzrequires Windowsc@seZdZhd�Zdd�ZdS)�TestMSWindowsTCPFlags>�
TCP_MAXSEG�TCP_KEEPCNT�TCP_NODELAY�TCP_FASTOPEN�TCP_KEEPIDLE�
TCP_KEEPINTVLcs6dd�tt�D�}�fdd�|D�}��g|d�dS)NcSsg|]	}|�d�r|�qS)�TCP)r��r8r!rrrr:Dr;z<TestMSWindowsTCPFlags.test_new_tcp_flags.<locals>.<listcomp>csg|]	}|�jvr|�qSr)�
knownTCPFlagsr�rGrrr:Er;zANew TCP flags were discovered. See bpo-32394 for more information)rrr�)rH�provided�unknownrrGr�test_new_tcp_flagsCs
�z(TestMSWindowsTCPFlags.test_new_tcp_flagsN)rOrPrQr�r�rrrrr�4r�r�c@s�eZdZdd�Zdd�Zdd�Ze�ee	d�pee	d�d	�e�
ejd
�dd���Z
e�e��d
�e�
ejd
�dd���ZdS)�CreateServerTestcCs�t��}t�d|f��}|�|��dd�|�|��d|�Wd�n1s*wYtjrctjd|ftjd��}|�|��dd�|�|��d|�Wd�dS1s\wYdSdS)NrUrr�rr\)rr5r�
create_serverr�r�rcr#�rHrErrrr�test_addressMs�
�"��zCreateServerTest.test_addresscCs�t�d��}|�|jtj�|�|jtj�Wd�n1s wYtjrStjdtj	d��}|�|jtj	�|�|jtj�Wd�dS1sLwYdSdS)NrT�rrr\)
rr�r�r]rBr,r5rrcr#)rHrr!rrr�test_family_and_typeXs�"��z%CreateServerTest.test_family_and_typecCs�ttd�s$|�t��tjddd�Wd�dS1swYdSt�d��}|�tjtj�}|�|d�Wd�n1sBwYtjddd��}|�tjtj�}|�	|d�Wd�dS1shwYdS)N�SO_REUSEPORT)rWrT)�
reuse_portr)
rrrgr	r�r9rvr�r�r�)rHrr�rrr�test_reuse_portas
"��"�z CreateServerTest.test_reuse_portr{�IPV6_V6ONLYz IPV6_V6ONLY option not supportedr�cCsJtjdtjd��}|�tjtj�sJ�Wd�dS1swYdS)Nr�r\)rr�r#r9r{r�rrrr�test_ipv6_only_defaultms"�z'CreateServerTest.test_ipv6_only_default�dualstack_ipv6 not supportedcCsHtjdtjdd��}|�|jtj�Wd�dS1swYdS)Nr�T�r]�dualstack_ipv6)rr�r#r�r]rrrr�test_dualstack_ipv6_familyus
�"�z+CreateServerTest.test_dualstack_ipv6_familyN)rOrPrQr�r�r�r�r�rrNr�rrcr�r�has_dualstack_ipv6r�rrrrr�Ks	
��r�c@s�eZdZejZdd�Zdd�Zdd�Ze	�
ejd�dd	��Z
e	�e��d
�e	�
ejd�dd���Ze	�e��d
�e	�
ejd�d
d���ZdS)�CreateServerFunctionalTestcsV��fdd�}t���|��j�tj||fd�}|����|j�j����dS)Nc	s�|�J|��\}}|�)���j�|�d�}|s(	Wd�Wd�dS|�|�Wd�n1s7wYWd�dSWd�dS1sOwYdSr�)r�r�r;r�r)rr�r�r��r�rHrr�run�s
����"�z3CreateServerFunctionalTest.echo_server.<locals>.runr)	rZr�rAr;r�r�rdrAr)rHrr�r�rr�r�echo_server�s
z&CreateServerFunctionalTest.echo_servercCsdtj|d��"}|�|j�|�|�|�d�|�|�d�d�Wd�dS1s+wYdS)Nr\rlr�)rrAr;r�rr�r�)rHr�r]rrrr�echo_client�s

"�z&CreateServerFunctionalTest.echo_clientcCsXt��}t�d|f��}|�|�|�d|ftj�Wd�dS1s%wYdS)NrkrU)rr5rr�r�r�rBr�rrr�	test_tcp4�s

"�z$CreateServerFunctionalTest.test_tcp4r�cCs^t��}tjd|ftjd��}|�|�|�d|ftj�Wd�dS1s(wYdS)Nrkr\r�rr5rr�r#r�r�r�rrr�	test_tcp6�s
�
"�z$CreateServerFunctionalTest.test_tcp6r�cCs`t��}tjd|ftjdd��}|�|�|�d|ftj�Wd�dS1s)wYdS)NrkTr�rU)rr5rr�r#r�r�rBr�rrr�test_dual_stack_client_v4���
"�z4CreateServerFunctionalTest.test_dual_stack_client_v4cCs`t��}tjd|ftjdd��}|�|�|�d|ftj�Wd�dS1s)wYdS)NrkTr�rr�r�rrr�test_dual_stack_client_v6�r�z4CreateServerFunctionalTest.test_dual_stack_client_v6N)rOrPrQrrr;r�r�r�r�r�rrcr�r�rr�r�r�rrrrr�~s"
	��r��send_fds�recv_fdsc@rT)�SendRecvFdsTestsc	Csjdd�}dd�}dd�td�D�}|�||�dd�|D�}t�tjtj�\}}|�;|�)t�|tg|�t�|t	t�d	t	|�d	�\}}}	}
|�||�Wd�n1sYwYWd�n1shwY|�
|t�|�
t	|�t	|��|�
|	d
�t|�D]\}}|\}}
t�
|
t|����q�t|�D]\}}t�|d�}|�
|t|����q�dS)NcSs&|D]\}}t�|�t�|�qdSr8�rr)�pipesr��fd2rrr�close_pipes�s
�z8SendRecvFdsTests.testSendAndRecvFds.<locals>.close_pipescSs|D]}t�|�qdSr8r�)r�r�rrr�	close_fds�s�z6SendRecvFdsTests.testSendAndRecvFds.<locals>.close_fdscSr�r)r�pipe)r8r�rrrr:��z7SendRecvFdsTests.testSendAndRecvFds.<locals>.<listcomp>rcSsg|]\}}|�qSrr)r8�rfd�wfdrrrr:�r�r�rrQ)r�rdrr�rr5r�r�r�rbr�r�rr�rEr�r�)rHr�r�r�r��sock1�sock2r��fds2r^r�r�r�r�r5rrr�testSendAndRecvFds�s.&���z#SendRecvFdsTests.testSendAndRecvFdsN)rOrPrQr�rrrrr��rtr�cCs t��}tjtjg|�R�dSr8)r�threading_setupr��addModuleCleanup�threading_cleanup)�thread_inforrr�setUpModule�sr��__main__)�r��testr�test.supportrrrr�r<r3rr�rr�rr�r�rr�rGrT�weakrefrr|rur�rrr�r �_threadr�rZrr)r
r�r�r�r��systemr	rNrr"r&r(r,r/r1r3r7rUr=�HAVE_SOCKET_CAN�HAVE_SOCKET_CAN_ISOTP�HAVE_SOCKET_CAN_J1939�HAVE_SOCKET_RDS�HAVE_SOCKET_ALG�HAVE_SOCKET_QIPCRTR�HAVE_SOCKET_VSOCKr�HAVE_SOCKET_UDPLITE�HAVE_SOCKET_BLUETOOTHr�r�r�rArRrUrWrirxr{r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrrr r"r$r6rDrLrMr�r1r_rhr�r�r�r�r�r�r�r�r�r!r(r.r0r3r6r9rdrvryr�r�r�r�r�r#rirlrnrorprcrurwrxryr{r|r}r~rr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r(r=r@rArDrErSrFrHrIrVrirqr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r9rrrdrer�r�r�r�r�r�r�rO�mainrrrr�<module>sf��
�







	

3q���!��$	

r
S
Z
*
=
>��.�%{�7ww=#P;k7�


�
	


�
����
�
�
��
	�
�
�
��
���

�
��






�



��

�
��
 �)��7#!$l


	?G9�7JS��',C�<e
�D3
@
'�

Youez - 2016 - github.com/yon3zu
LinuXploit