B
    u9a} ã            
   @   s(  d dl Z d dlmZ d dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZd dlZd dlZd dlZd dlmZ d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZyd dlZW n ek
rô   dZY nX yd dlZW n ek
r   dZY nX ejZd  d¡Z!dZ"dZ#yd dl$Z$W n ek
r\   dZ$Y nX d	d
„ Z%dd„ Z&dd„ Z'dd„ Z(dd„ Z)dd„ Z*dd„ Z+e&ƒ Z,e'ƒ Z-e(ƒ Z.e)ƒ Z/e*ƒ Z0e d¡j1Z2G dd„ de j3ƒZ4G dd„ de j3ƒZ5G dd„ de j3ƒZ6G dd„ de j3ƒZ7G d d!„ d!e j3ƒZ8G d"d#„ d#ƒZ9G d$d%„ d%e4e9ƒZ:G d&d'„ d'e5e9ƒZ;G d(d)„ d)e7e9ƒZ<G d*d+„ d+e8e9ƒZ=e  >edkd,¡e  ?e0d-¡e  ?e%ƒ d.kd/¡G d0d1„ d1e j3e9ƒƒƒƒZ@G d2d3„ d3e:ƒZAG d4d5„ d5e j3e9ƒZBG d6d7„ d7e j3ƒZCG d8d9„ d9eCƒZDG d:d;„ d;e6eCe9ƒZEG d<d=„ d=eDeEƒZFG d>d?„ d?eCƒZGG d@dA„ dAeGƒZHG dBdC„ dCeCƒZIG dDdE„ dEeIƒZJG dFdG„ dGeIƒZKG dHdI„ dIeIƒZLG dJdK„ dKeIƒZMG dLdM„ dMeMƒZNdNdO„ ZOdPdQ„ ZPdRdS„ ZQG dTdU„ dUe j3ƒZRe  ?e,dV¡G dWdX„ dXe j3ƒƒZSe  ?e,dV¡G dYdZ„ dZe<ƒƒZTe  ?e-d[¡G d\d]„ d]e j3ƒƒZUe  ?e.d^¡G d_d`„ d`e j3ƒƒZVe  ?e.d^¡G dadb„ dbe=ƒƒZWe  >edkd,¡e  ?e0d-¡G dcdd„ dde j3ƒƒƒZXG dedf„ dfeAƒZYG dgdh„ dhe;ƒZZG didj„ dje6ƒZ[G dkdl„ dle[ƒZ\G dmdn„ dne[ƒZ]G dodp„ dpe[ƒZ^G dqdr„ dre[ƒZ_G dsdt„ dte[ƒZ`G dudv„ dve[ƒZaG dwdx„ dxeaƒZbG dydz„ dzebƒZcG d{d|„ d|ebƒZdG d}d~„ d~e[ƒZeG dd€„ d€eeƒZfG dd‚„ d‚eeƒZgG dƒd„„ d„e\eeƒZhG d…d†„ d†e j3ƒZiG d‡dˆ„ dˆeaƒZjG d‰dŠ„ dŠeaƒZkG d‹dŒ„ dŒe]e_eEeKƒZlePejdƒG dŽd„ dedelƒƒZmePejdƒG d‘d’„ d’egelƒƒZnePejd“ƒG d”d•„ d•ehelƒƒZoG d–d—„ d—e]e_eEeNƒZpePejdƒe  ?ejqd˜¡eQd™dšƒG d›dœ„ dœedepƒƒƒƒZrePejdƒe  ?ejqd˜¡eQd™dšƒG ddž„ džegepƒƒƒƒZsePejd“ƒe  ?ejqd˜¡eQd™dšƒG dŸd „ d ehepƒƒƒƒZtePejdƒe  ?ejqd˜¡ePed¡ƒeQd™dšƒG d¢d£„ d£ekepƒƒƒƒƒZuePejd“ƒe  ?ejqd˜¡ePed¡ƒeQd™dšƒG d¤d¥„ d¥e\ekepƒƒƒƒƒZvG d¦d§„ d§e`eFeJƒZwePejdƒG d¨d©„ d©ecewƒƒZxePejdƒG dªd«„ d«egefewƒƒZyePejd“ƒG d¬d­„ d­ehefewƒƒZzG d®d¯„ d¯e^e`eFeLƒZ{ePejdƒeQd°d±d²ƒG d³d´„ d´ece{ƒƒƒZ|ePejdƒeQd°d±d²ƒG dµd¶„ d¶egefe{ƒƒƒZ}ePejd“ƒeQd°d±d²ƒG d·d¸„ d¸ehefe{ƒƒƒZ~G d¹dº„ dºe`eFeHƒZePejdƒePed»ƒG d¼d½„ d½eceƒƒƒZ€ePejdƒePed»ƒG d¾d¿„ d¿egefeƒƒƒZePejd“ƒePed»ƒG dÀdÁ„ dÁehefeƒƒƒZ‚ePejddƒePed»dÂdÃƒG dÄdÅ„ dÅejeƒƒƒZƒePejdd“ƒePed»dÂdÃƒG dÆdÇ„ dÇe\ejeƒƒƒZ„G dÈdÉ„ dÉe j3ƒZ…ePedÊƒe  ?e†edËƒ	pe†edÌƒdÍ¡G dÎdÏ„ dÏe…eKƒƒƒZ‡ePedÊƒe  ?e†edËƒ	pÊe†edÌƒdÍ¡G dÐdÑ„ dÑe…e6eDeJƒƒƒZˆG dÒdÓ„ dÓe:ƒZ‰G dÔdÕ„ dÕeBƒZŠG dÖd×„ d×e:ƒZ‹G dØdÙ„ dÙeAƒZŒG dÚdÛ„ dÛeŒƒZG dÜdÝ„ dÝeŒƒZŽG dÞdß„ dßeŒƒZG dàdá„ dáeŒƒZG dâdã„ dãeŒƒZ‘G dädå„ dåeŒƒZ’G dædç„ dçe“ƒZ”G dèdé„ dée”eYƒZ•G dêdë„ dëe j3ƒZ–G dìdí„ díe4e9ƒZ—G dîdï„ dïe4e9ƒZ˜G dðdñ„ dñe4ƒZ™G dòdó„ dóe5ƒZšG dôdõ„ dõe j3ƒZ›e  ?ejœdökd÷¡G dødù„ dùe j3ƒƒZe  ?e†ed»ƒdú¡G dûdü„ düe j3ƒƒZžG dýdþ„ dþeAƒZŸdÿZ d Z¡dZ¢dd„ Z£e  ?e£ƒ d¡G dd„ de j3ƒƒZ¤e  ?e£ƒ d¡G dd„ de j3e9ƒƒZ¥G d	d
„ d
e:ƒZ¦G dd„ de j3ƒZ§e  ?e†edƒd¡G dd„ de j3ƒƒZ¨e  ?ej©dkd¡e  ?ed¡G dd„ de4ƒƒƒZªG dd„ de:ƒZ«e  ?e†edƒd¡G dd„ de«ƒƒZ¬e  ?e/d¡G dd„ de j3ƒƒZ­e  ?ejœ ®d¡d ¡G d!d"„ d"e j3ƒƒZ¯d#d$„ Z°e±d%kr$e°ƒ  dS (&  é    N)Úsupport)ÚproxyFu   Michael Gilfix was hereáˆ´
zutf-8g      N@iÒ  c           	   C   s`   t d krd S y*tddƒ} t  | tjd¡}W d Q R X W n tk
rJ   d S X t d|¡d S d S )Nz
/dev/vsockÚrbz    ÚIr   )ÚfcntlÚopenÚioctlÚsocketÚIOCTL_VM_SOCKETS_GET_LOCAL_CIDÚOSErrorÚstructÚunpack)ÚfÚr© r   ú!/usr/lib/python3.7/test_socket.pyÚget_cid/   s    r   c           	   C   s>   yt   t jt jt j¡} W n ttfk
r0   dS X |  ¡  dS )z5Check whether CAN sockets are supported on this host.FT)r	   ÚPF_CANÚSOCK_RAWÚCAN_RAWÚAttributeErrorr   Úclose)Úsr   r   r   Ú_have_socket_can:   s    r   c           	   C   s>   yt   t jt jt j¡} W n ttfk
r0   dS X |  ¡  dS )z;Check whether CAN ISOTP sockets are supported on this host.FT)r	   r   Ú
SOCK_DGRAMÚ	CAN_ISOTPr   r   r   )r   r   r   r   Ú_have_socket_can_isotpD   s    r   c           	   C   s<   yt   t jt jd¡} W n ttfk
r.   dS X |  ¡  dS )z5Check whether RDS sockets are supported on this host.r   FT)r	   ÚPF_RDSÚSOCK_SEQPACKETr   r   r   )r   r   r   r   Ú_have_socket_rdsN   s    r   c           	   C   s<   yt   t jt jd¡} W n ttfk
r.   dS X |  ¡  dS )z8Check whether AF_ALG sockets are supported on this host.r   FT)r	   ÚAF_ALGr   r   r   r   )r   r   r   r   Ú_have_socket_algX   s    r!   c              C   s   t ƒ dk	} | S )z:Check whether AF_VSOCK sockets are supported on this host.N)r   )Úretr   r   r   Ú_have_socket_vsockb   s    
r#   c             C   s   t t | tjtj¡tj@ ƒ S )N)Úboolr   ÚF_GETFLÚosÚ
O_NONBLOCK)Úsockr   r   r   Ú_is_fd_in_blocking_modeh   s    r)   Úic               @   s   e Zd Zdd„ Zdd„ ZdS )ÚSocketTCPTestc             C   s.   t   t jt j¡| _t | j¡| _| j ¡  d S )N)r	   ÚAF_INETÚSOCK_STREAMÚservr   Ú	bind_portÚportÚlisten)Úselfr   r   r   ÚsetUp|   s    zSocketTCPTest.setUpc             C   s   | j  ¡  d | _ d S )N)r.   r   )r2   r   r   r   ÚtearDown   s    
zSocketTCPTest.tearDownN)Ú__name__Ú
__module__Ú__qualname__r3   r4   r   r   r   r   r+   z   s   r+   c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚSocketUDPTestc             C   s$   t   t jt j¡| _t | j¡| _d S )N)r	   r,   r   r.   r   r/   r0   )r2   r   r   r   r3   ‡   s    zSocketUDPTest.setUpc             C   s   | j  ¡  d | _ d S )N)r.   r   )r2   r   r   r   r4   ‹   s    
zSocketUDPTest.tearDownN)r5   r6   r7   r3   r4   r   r   r   r   r8   …   s   r8   c                   s8   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚThreadSafeCleanupTestCasez¥Subclass of unittest.TestCase with thread-safe cleanup methods.

    This subclass protects the addCleanup() and doCleanups() methods
    with a recursive lock.
    c                s   t ƒ j||Ž t ¡ | _d S )N)ÚsuperÚ__init__Ú	threadingÚRLockÚ_cleanup_lock)r2   ÚargsÚkwargs)Ú	__class__r   r   r;   –   s    z"ThreadSafeCleanupTestCase.__init__c          	      s    | j  tƒ j||ŽS Q R X d S )N)r>   r:   Ú
addCleanup)r2   r?   r@   )rA   r   r   rB   š   s    z$ThreadSafeCleanupTestCase.addCleanupc          	      s    | j  tƒ j||ŽS Q R X d S )N)r>   r:   Ú
doCleanups)r2   r?   r@   )rA   r   r   rC   ž   s    z$ThreadSafeCleanupTestCase.doCleanups)r5   r6   r7   Ú__doc__r;   rB   rC   Ú__classcell__r   r   )rA   r   r9      s   r9   c               @   sH   e Zd ZdZdZdZdZe e¡Z	dZ
e
de e
¡d  7 Z
dd	„ Zd
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
    # ifconfig vcan0 up
    Úvcan0é€   z=IB3x8sz@3I4l2IÚxé   c             C   sb   t   t jt jt j¡| _|  | jj¡ y| j | jf¡ W n$ t	k
r\   |  
d| j ¡ Y nX d S )Nz%network interface `%s` does not exist)r	   r   r   r   r   rB   r   ÚbindÚ	interfacer   ÚskipTest)r2   r   r   r   r3   Ë   s    zSocketCANTest.setUpN)r5   r6   r7   rD   rL   ÚbufsizeÚcan_frame_fmtr   ÚcalcsizeZcan_frame_sizeÚbcm_cmd_msg_fmtr3   r   r   r   r   rF   ¢   s   

rF   c               @   s   e Zd ZdZdZdd„ ZdS )ÚSocketRDSTestz\To be able to run this test, the `rds` kernel module must be loaded:
    # modprobe rds
    i    c             C   sX   t   t jt jd¡| _|  | jj¡ yt | j¡| _W n t	k
rR   |  
d¡ Y nX d S )Nr   zunable to bind RDS socket)r	   r   r   r.   rB   r   r   r/   r0   r   rM   )r2   r   r   r   r3   Ü   s    zSocketRDSTest.setUpN)r5   r6   r7   rD   rN   r3   r   r   r   r   rR   Õ   s   rR   c               @   sH   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dd„ Z
dS )Ú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().
    c             C   s$   | j | _| j| _| j| _ | j| _d S )N)r3   Ú_ThreadableTest__setUpr4   Ú_ThreadableTest__tearDownÚ_setUpÚ	_tearDown)r2   r   r   r   r;     s    zThreadableTest.__init__c             C   s   | j  ¡  dS )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Úset)r2   r   r   r   ÚserverExplicitReady  s    z"ThreadableTest.serverExplicitReadyc             C   sÈ   t  ¡ | _| j ¡  t ¡ | _t ¡ | _t ¡ | _t	 
d¡| _	d| _|  ¡ }| d¡}||d d … }t| d| ƒ}t | j|f¡| _z&y|  ¡  W n   d| _‚ Y nX W d | j ¡  X | j ¡  d S )Né   FÚ.Ú_T)r   Zwait_threads_exitÚwait_threadsÚ	__enter__r<   ÚEventrX   Úclient_readyÚdoneÚqueueÚQueueÚserver_crashedÚidÚrfindÚgetattrÚthreadÚstart_new_threadÚ	clientRunZclient_threadrT   rY   Úwait)r2   Z
methodnamer*   Ztest_methodr   r   r   rV     s(    





zThreadableTest._setUpc             C   s>   |   ¡  | j ¡  | j d d d ¡ | j ¡ r:| j ¡ }|‚d S )N)rU   rb   rl   r^   Ú__exit__rc   ZqsizeÚget)r2   Úexcr   r   r   rW   4  s    


zThreadableTest._tearDownc          
   C   sÒ   | j  ¡  zHy|  ¡  W n6 tk
rN } z| j |¡ |  ¡  d S d }~X Y nX W d | j ¡  X | j	rr|  ¡  d S t
|dƒs„tdƒ‚z>y
|ƒ  W n. tk
r¾ } z| j |¡ W d d }~X Y nX W d |  ¡  X d S )NÚ__call__z%test_func must be a callable function)rX   rl   ÚclientSetUpÚBaseExceptionrc   ÚputÚclientTearDownra   rY   re   ÚhasattrÚ	TypeError)r2   Z	test_funcÚer   r   r   rk   =  s$    


"zThreadableTest.clientRunc             C   s   t dƒ‚d S )Nz clientSetUp must be implemented.)ÚNotImplementedError)r2   r   r   r   rq   S  s    zThreadableTest.clientSetUpc             C   s   | j  ¡  t ¡  d S )N)rb   rY   ri   Úexit)r2   r   r   r   rt   V  s    
zThreadableTest.clientTearDownN)r5   r6   r7   rD   r;   rZ   rV   rW   rk   rq   rt   r   r   r   r   rS   å   s   $	rS   c               @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
ÚThreadedTCPSocketTestÚrunTestc             C   s   t j| |d t | ¡ d S )N)Ú
methodName)r+   r;   rS   )r2   r|   r   r   r   r;   \  s    zThreadedTCPSocketTest.__init__c             C   s   t   t jt j¡| _d S )N)r	   r,   r-   Úcli)r2   r   r   r   rq   `  s    z!ThreadedTCPSocketTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r}   r   rS   rt   )r2   r   r   r   rt   c  s    
z$ThreadedTCPSocketTest.clientTearDownN)r{   )r5   r6   r7   r;   rq   rt   r   r   r   r   rz   Z  s   
rz   c               @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
ÚThreadedUDPSocketTestr{   c             C   s   t j| |d t | ¡ d S )N)r|   )r8   r;   rS   )r2   r|   r   r   r   r;   j  s    zThreadedUDPSocketTest.__init__c             C   s   t   t jt j¡| _d S )N)r	   r,   r   r}   )r2   r   r   r   rq   n  s    z!ThreadedUDPSocketTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r}   r   rS   rt   )r2   r   r   r   rt   q  s    
z$ThreadedUDPSocketTest.clientTearDownN)r{   )r5   r6   r7   r;   rq   rt   r   r   r   r   r~   h  s   
r~   c               @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
ÚThreadedCANSocketTestr{   c             C   s   t j| |d t | ¡ d S )N)r|   )rF   r;   rS   )r2   r|   r   r   r   r;   x  s    zThreadedCANSocketTest.__init__c             C   sD   t   t jt jt j¡| _y| j | jf¡ W n tk
r>   Y nX d S )N)r	   r   r   r   r}   rK   rL   r   )r2   r   r   r   rq   |  s
    z!ThreadedCANSocketTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r}   r   rS   rt   )r2   r   r   r   rt   …  s    
z$ThreadedCANSocketTest.clientTearDownN)r{   )r5   r6   r7   r;   rq   rt   r   r   r   r   r   v  s   
	r   c               @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
ÚThreadedRDSSocketTestr{   c             C   s   t j| |d t | ¡ d S )N)r|   )rR   r;   rS   )r2   r|   r   r   r   r;   Œ  s    zThreadedRDSSocketTest.__init__c             C   sN   t   t jt jd¡| _y | j tdf¡ | j ¡ | _W n tk
rH   Y nX d S )Nr   )	r	   r   r   r}   rK   ÚHOSTÚgetsocknameÚcli_addrr   )r2   r   r   r   rq     s    z!ThreadedRDSSocketTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r}   r   rS   rt   )r2   r   r   r   rt   ›  s    
z$ThreadedRDSSocketTest.clientTearDownN)r{   )r5   r6   r7   r;   rq   rt   r   r   r   r   r€   Š  s   
r€   z
need fcntlz%VSOCK sockets required for this test.é   z-This test can only be run on a virtual guest.c               @   s6   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚThreadedVSOCKSocketStreamTestr{   c             C   s   t jj| |d t | ¡ d S )N)r|   )ÚunittestÚTestCaser;   rS   )r2   r|   r   r   r   r;   §  s    z&ThreadedVSOCKSocketStreamTest.__init__c             C   sh   t   t jt j¡| _|  | jj¡ | j t jtf¡ | j 	¡  |  
¡  | j ¡ \| _| _|  | jj¡ d S )N)r	   ÚAF_VSOCKr-   r.   rB   r   rK   ÚVMADDR_CID_ANYÚ	VSOCKPORTr1   rZ   ÚacceptÚconnÚconnaddr)r2   r   r   r   r3   «  s    
z#ThreadedVSOCKSocketStreamTest.setUpc             C   sD   t  d¡ t tjtj¡| _|  | jj¡ tƒ }| j 	|t
f¡ d S )Ngš™™™™™¹?)ÚtimeÚsleepr	   rˆ   r-   r}   rB   r   r   ÚconnectrŠ   )r2   Zcidr   r   r   rq   ´  s
    
z)ThreadedVSOCKSocketStreamTest.clientSetUpc             C   s   | j  d¡}|  |t¡ d S )Ni   )rŒ   ÚrecvÚassertEqualÚMSG)r2   Úmsgr   r   r   Ú
testStream»  s    z(ThreadedVSOCKSocketStreamTest.testStreamc             C   s   | j  t¡ | j  ¡  d S )N)r}   Úsendr“   r   )r2   r   r   r   Ú_testStream¿  s    z)ThreadedVSOCKSocketStreamTest._testStreamN)r{   )r5   r6   r7   r;   r3   rq   r•   r—   r   r   r   r   r…      s
   
	r…   c               @   s:   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ Zdd„ Zd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{   c             C   s   t j| |d d S )N)r|   )rz   r;   )r2   r|   r   r   r   r;   Ê  s    zSocketConnectedTest.__init__c             C   s*   t  | ¡ |  ¡  | j ¡ \}}|| _d S )N)rz   r3   rZ   r.   r‹   Úcli_conn)r2   rŒ   Úaddrr   r   r   r3   Í  s    
zSocketConnectedTest.setUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r™   r   rz   r4   )r2   r   r   r   r4   Õ  s    
zSocketConnectedTest.tearDownc             C   s(   t  | ¡ | j t| jf¡ | j| _d S )N)rz   rq   r}   r   r   r0   Ú	serv_conn)r2   r   r   r   rq   Ú  s    
zSocketConnectedTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r›   r   rz   rt   )r2   r   r   r   rt   ß  s    
z"SocketConnectedTest.clientTearDownN)r{   )	r5   r6   r7   rD   r;   r3   r4   rq   rt   r   r   r   r   r˜   Ã  s   
r˜   c               @   s6   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚSocketPairTestr{   c             C   s   t jj| |d t | ¡ d S )N)r|   )r†   r‡   r;   rS   )r2   r|   r   r   r   r;   æ  s    zSocketPairTest.__init__c             C   s   t  ¡ \| _| _d S )N)r	   Ú
socketpairr.   r}   )r2   r   r   r   r3   ê  s    zSocketPairTest.setUpc             C   s   | j  ¡  d | _ d S )N)r.   r   )r2   r   r   r   r4   í  s    
zSocketPairTest.tearDownc             C   s   d S )Nr   )r2   r   r   r   rq   ñ  s    zSocketPairTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r}   r   rS   rt   )r2   r   r   r   rt   ô  s    
zSocketPairTest.clientTearDownN)r{   )r5   r6   r7   r;   r3   r4   rq   rt   r   r   r   r   rœ   ä  s
   
rœ   c               @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	Ú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.
    c             C   s   |   ¡ | _|  ¡  d S )N)Ú	newSocketr.   Ú
bindServer)r2   r   r   r   r3   	  s    
zSocketTestBase.setUpc             C   s   |   | j¡ | j ¡ | _dS )z9Bind server socket and set self.serv_addr to its address.N)ÚbindSockr.   r‚   Ú	serv_addr)r2   r   r   r   r      s    zSocketTestBase.bindServerc             C   s   | j  ¡  d | _ d S )N)r.   r   )r2   r   r   r   r4     s    
zSocketTestBase.tearDownN)r5   r6   r7   rD   r3   r    r4   r   r   r   r   rž      s   rž   c                   s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚSocketListeningTestMixinz%Mixin to listen on the server socket.c                s   t ƒ  ¡  | j ¡  d S )N)r:   r3   r.   r1   )r2   )rA   r   r   r3     s    
zSocketListeningTestMixin.setUp)r5   r6   r7   rD   r3   rE   r   r   )rA   r   r£     s   r£   c                   s@   e Zd ZdZ‡ fdd„Zdd„ Zdd„ Zdd	„ Zd
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.
    c                s   t ƒ j||Ž t | ¡ d S )N)r:   r;   rS   )r2   r?   r@   )rA   r   r   r;   '  s    z ThreadedSocketTestMixin.__init__c             C   s   |   ¡ | _|  ¡  d S )N)ÚnewClientSocketr}   Ú
bindClient)r2   r   r   r   rq   +  s    
z#ThreadedSocketTestMixin.clientSetUpc             C   s   |   ¡ S )z&Return a new socket for use as client.)rŸ   )r2   r   r   r   r¥   /  s    z'ThreadedSocketTestMixin.newClientSocketc             C   s   |   | j¡ | j ¡ | _dS )z8Bind client socket and set self.cli_addr to its address.N)r¡   r}   r‚   rƒ   )r2   r   r   r   r¦   3  s    z"ThreadedSocketTestMixin.bindClientc             C   s   | j  ¡  d | _ t | ¡ d S )N)r}   r   rS   rt   )r2   r   r   r   rt   8  s    
z&ThreadedSocketTestMixin.clientTearDown)
r5   r6   r7   rD   r;   rq   r¥   r¦   rt   rE   r   r   )rA   r   r¤     s   r¤   c                   sD   e Zd ZdZ‡ fdd„Z‡ fdd„Z‡ fdd„Z‡ fdd	„Z‡  ZS )
Ú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.)
    c                s*   t ƒ  ¡  |  ¡  | j ¡ \}}|| _d S )N)r:   r3   rZ   r.   r‹   r™   )r2   rŒ   rš   )rA   r   r   r3   G  s    
zConnectedStreamTestMixin.setUpc                s   | j  ¡  d | _ tƒ  ¡  d S )N)r™   r   r:   r4   )r2   )rA   r   r   r4   O  s    
z!ConnectedStreamTestMixin.tearDownc                s$   t ƒ  ¡  | j | j¡ | j| _d S )N)r:   rq   r}   r   r¢   r›   )r2   )rA   r   r   rq   T  s    
z$ConnectedStreamTestMixin.clientSetUpc                s8   y| j  ¡  d | _ W n tk
r(   Y nX tƒ  ¡  d S )N)r›   r   r   r:   rt   )r2   )rA   r   r   rt   Y  s    

z'ConnectedStreamTestMixin.clientTearDown)	r5   r6   r7   rD   r3   r4   rq   rt   rE   r   r   )rA   r   r§   >  s
   r§   c                   s(   e Zd ZdZ‡ fdd„Zdd„ Z‡  ZS )ÚUnixSocketTestBasez(Base class for Unix-domain socket tests.c                s(   t  ¡ | _|  tj| j¡ tƒ  ¡  d S )N)ÚtempfileÚmkdtempÚdir_pathrB   r&   Úrmdirr:   r3   )r2   )rA   r   r   r3   j  s    
zUnixSocketTestBase.setUpc             C   s,   t j| jd}t ||¡ |  tj|¡ d S )N)Údir)r©   Zmktempr«   r   Úbind_unix_socketrB   Úunlink)r2   r(   Úpathr   r   r   r¡   o  s    zUnixSocketTestBase.bindSock)r5   r6   r7   rD   r3   r¡   rE   r   r   )rA   r   r¨   b  s   r¨   c               @   s   e Zd ZdZdd„ ZdS )ÚUnixStreamBasez-Base class for Unix-domain SOCK_STREAM tests.c             C   s   t   t jt j¡S )N)r	   ÚAF_UNIXr-   )r2   r   r   r   rŸ   w  s    zUnixStreamBase.newSocketN)r5   r6   r7   rD   rŸ   r   r   r   r   r±   t  s   r±   c                   s,   e Zd ZdZeZ‡ fdd„Zdd„ Z‡  ZS )ÚInetTestBasez!Base class for IPv4 socket tests.c                s   t ƒ  ¡  | jd | _d S )Nr[   )r:   r3   r¢   r0   )r2   )rA   r   r   r3   €  s    
zInetTestBase.setUpc             C   s   t j|| jd d S )N)Úhost)r   r/   r´   )r2   r(   r   r   r   r¡   „  s    zInetTestBase.bindSock)	r5   r6   r7   rD   r   r´   r3   r¡   rE   r   r   )rA   r   r³   {  s   r³   c               @   s   e Zd ZdZdd„ ZdS )ÚTCPTestBasez#Base class for TCP-over-IPv4 tests.c             C   s   t   t jt j¡S )N)r	   r,   r-   )r2   r   r   r   rŸ   Š  s    zTCPTestBase.newSocketN)r5   r6   r7   rD   rŸ   r   r   r   r   rµ   ‡  s   rµ   c               @   s   e Zd ZdZdd„ ZdS )ÚUDPTestBasez#Base class for UDP-over-IPv4 tests.c             C   s   t   t jt j¡S )N)r	   r,   r   )r2   r   r   r   rŸ     s    zUDPTestBase.newSocketN)r5   r6   r7   rD   rŸ   r   r   r   r   r¶     s   r¶   c               @   s   e Zd ZdZdd„ ZdS )ÚSCTPStreamBasez;Base class for SCTP tests in one-to-one (SOCK_STREAM) mode.c             C   s   t   t jt jt j¡S )N)r	   r,   r-   ÚIPPROTO_SCTP)r2   r   r   r   rŸ   –  s    zSCTPStreamBase.newSocketN)r5   r6   r7   rD   rŸ   r   r   r   r   r·   “  s   r·   c               @   s   e Zd ZdZejZdS )ÚInet6TestBasez!Base class for IPv6 socket tests.N)r5   r6   r7   rD   r   ÚHOSTv6r´   r   r   r   r   r¹   ›  s   r¹   c               @   s   e Zd ZdZdd„ ZdS )ÚUDP6TestBasez#Base class for UDP-over-IPv6 tests.c             C   s   t   t jt j¡S )N)r	   ÚAF_INET6r   )r2   r   r   r   rŸ   £  s    zUDP6TestBase.newSocketN)r5   r6   r7   rD   rŸ   r   r   r   r   r»      s   r»   c                s*   dd„ ‰ ‡ ‡fdd„}dd„ }| r&|S |S )a  Skip 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              _   s   d S )Nr   )r?   r@   r   r   r   Úclient_pass²  s    z%skipWithClientIf.<locals>.client_passc                s*   t  ˆ¡| ƒ}t| tƒs&‡ fdd„|_|S )Nc                s   ˆ S )Nr   )r   )r½   r   r   Ú<lambda>·  ó    z3skipWithClientIf.<locals>.skipdec.<locals>.<lambda>)r†   ÚskipÚ
isinstanceÚtypeÚclient_skip)ÚobjZretval)r½   Úreasonr   r   Úskipdec´  s    
z!skipWithClientIf.<locals>.skipdecc             S   s"   t | tƒst| dƒsdd„ | _| S )NrÃ   c             S   s   | S )Nr   )r   r   r   r   r¾   »  r¿   z5skipWithClientIf.<locals>.noskipdec.<locals>.<lambda>)rÁ   rÂ   ru   rÃ   )rÄ   r   r   r   Ú	noskipdec¹  s    
z#skipWithClientIf.<locals>.noskipdecr   )Z	conditionrÅ   rÆ   rÇ   r   )r½   rÅ   r   ÚskipWithClientIf©  s    	rÈ   c                s0   ‡ fdd„|D ƒ}t |dd dd„ |D ƒ¡ ƒS )zƒSkip decorated test if obj is missing any of the given attributes.

    Sets client_skip attribute as skipWithClientIf() does.
    c                s   g | ]}t ˆ |ƒs|‘qS r   )ru   )Ú.0Úname)rÄ   r   r   ú
<listcomp>Å  s    z requireAttrs.<locals>.<listcomp>zdon't have z, c             s   s   | ]
}|V  qd S )Nr   )rÉ   rÊ   r   r   r   ú	<genexpr>Ç  s    zrequireAttrs.<locals>.<genexpr>)rÈ   Újoin)rÄ   Z
attributesÚmissingr   )rÄ   r   ÚrequireAttrsÀ  s    rÏ   c           
   G   s¦   d}dd„ | D ƒ}|r0dd  dd„ |D ƒ¡ }nPdd„ | D ƒ}ytj|Ž }W n* tk
rv } zt|ƒ}W dd}~X Y n
X | ¡  t|dk	d	 d  d
d„ | D ƒ¡|¡ƒS )a  Skip 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.
    Nc             S   s$   g | ]}t |tƒrtt|ƒs|‘qS r   )rÁ   Ústrru   r	   )rÉ   rÄ   r   r   r   rË   Ò  s    z!requireSocket.<locals>.<listcomp>zdon't have z, c             s   s   | ]
}|V  qd S )Nr   )rÉ   rÊ   r   r   r   rÌ   Õ  s    z requireSocket.<locals>.<genexpr>c             S   s$   g | ]}t |tƒrtt|ƒn|‘qS r   )rÁ   rÐ   rh   r	   )rÉ   rÄ   r   r   r   rË   ×  s   zcan't create socket({0}): {1}c             s   s   | ]}t |ƒV  qd S )N)rÐ   )rÉ   Úor   r   r   rÌ   ã  s    )rÍ   r	   r   rÐ   r   rÈ   Úformat)r?   ÚerrrÎ   Zcallargsr   rw   r   r   r   ÚrequireSocketÊ  s    rÔ   c               @   sÄ  e Zd Zdd„ Zdd„ Ze edk	d¡dd„ ƒZd	d
„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Ze eedƒd¡e eedƒd¡dd„ ƒƒZe eedƒd¡dd „ ƒZe eedƒd¡d!d"„ ƒZe eed#ƒd$¡d%d&„ ƒZd'd(„ Zd)d*„ Zejd+d,„ ƒZd-d.„ Zd/d0„ Ze eed1ƒd2¡d3d4„ ƒZe eed5ƒd6¡d7d8„ ƒZe eed5ƒd6¡d9d:„ ƒZ e eed;ƒd<¡d=d>„ ƒZ!e eed;ƒd<¡d?d@„ ƒZ"dAdB„ Z#dCdD„ Z$dEdF„ Z%dGdH„ Z&dIdJ„ Z'dKdL„ Z(dMdN„ Z)e e*j+dOkdP¡dQdR„ ƒZ,e e*j+dOkdP¡e eedSƒdT¡dUdV„ ƒƒZ-dWdX„ Z.dYdZ„ Z/e e 0d[¡d\¡d]d^„ ƒZ1d_d`„ Z2dadb„ Z3dcdd„ Z4dedf„ Z5dgdh„ Z6didj„ Z7dkdl„ Z8dmdn„ Z9dodp„ Z:dqdr„ Z;dsdt„ Z<ejdudv„ ƒZ=e ej>dw¡dxdy„ ƒZ?e ej>dw¡dzd{„ ƒZ@e ej>dw¡e eedƒd|¡d}d~„ ƒƒZAe ej>dw¡e ejBdkd€¡dd‚„ ƒƒZCe ej>dw¡e eedƒd|¡dƒd„„ ƒƒZDe ej>dw¡e ejBdkd€¡d…d†„ ƒƒZEd‡dˆ„ ZFd‰dŠ„ ZGe He*j+dOkd‹¡dŒd„ ƒZIe ee*dŽƒd¡dd‘„ ƒZJd’d“„ ZKd”d•„ ZLdS )–ÚGeneralModuleTestsc             C   s<   dd l }|  tj|jk¡ t ¡ }|  |tj¡ | ¡  d S )Nr   )Ú_socketÚ
assertTruer	   Z
SocketTypeÚassertIsInstancer   )r2   rÖ   r   r   r   r   Útest_SocketType_is_socketobjectë  s
    z2GeneralModuleTests.test_SocketType_is_socketobjectc          	   C   sÚ   t   t jt j¡}|œ |  d| ¡  t|ƒ¡ |  dt j t|ƒ¡ |  dt j t|ƒ¡ |  dt|ƒ¡ |  dt|ƒ¡ | d¡ |  dt|ƒ¡ |  t| 	¡ ƒt|ƒ¡ W d Q R X |  dt|ƒ¡ |  dt|ƒ¡ d S )	Nzfd=%iz	family=%sztype=%szproto=0Zraddr)z	127.0.0.1r   Zladdrz[closed])
r	   r,   r-   ÚassertInÚfilenoÚreprÚassertNotInrK   rÐ   r‚   )r2   r   r   r   r   Ú	test_reprò  s    
"zGeneralModuleTests.test_reprNzneed _socket modulec             C   sr   t  t jt j¡}z.d| ¡ |j|j|jf }|  t	|ƒ|¡ W d | 
¡  X d|j|j|jf }|  t	|ƒ|¡ d S )Nz4<socket object, fd=%s, family=%s, type=%s, proto=%s>z4<socket object, fd=-1, family=%s, type=%s, proto=%s>)rÖ   r	   r,   r-   rÛ   ÚfamilyrÂ   Úprotor’   rÜ   r   )r2   r   Úexpectedr   r   r   Útest_csocket_repr   s    
z$GeneralModuleTests.test_csocket_reprc             C   sh   t   t jt j¡}t|ƒ}|  | ¡ | ¡ ¡ | ¡  d }y| ¡  W n tk
rX   Y nX |  d¡ d S )NzSocket proxy still exists)	r	   r,   r-   r   r’   rÛ   r   ÚReferenceErrorÚfail)r2   r   Úpr   r   r   Útest_weakref  s    zGeneralModuleTests.test_weakrefc          	   C   sr   d}| j t|d d
 t‚W d Q R X | j t|d d tj‚W d Q R X | j t|d d tj‚W d Q R X d S )Nz$Error raising socket exception (%s).r   )r”   zsocket.herrorzsocket.gaierror)ÚassertRaisesr   r	   ÚherrorÚgaierror)r2   r”   r   r   r   ÚtestSocketError  s    z"GeneralModuleTests.testSocketErrorc          	   C   sF  t   t jt j¡}|  |j¡ | d¡ | ¡ }|  t¡}| 	d|¡ W d Q R X |  
t|jƒd¡ |  t¡}| 	d|¡ W d Q R X |  
t|jƒd¡ |  t¡}| 	dd ¡ W d Q R X |  dt|jƒ¡ |  t¡}| 	dd|¡ W d Q R X |  
t|jƒd¡ |  t¡}| 	dd|¡ W d Q R X |  
t|jƒd¡ |  t¡}| 	ddd ¡ W d Q R X |  dt|jƒ¡ |  t¡}| 	dd	|¡ W d Q R X |  d
t|jƒ¡ |  t¡}| 	dd d ¡ W d Q R X |  d
t|jƒ¡ |  t¡}| 	d¡ W d Q R X |  dt|jƒ¡ |  t¡}| 	dd|d¡ W d Q R X |  dt|jƒ¡ d S )N)Ú r   u   â˜ z*a bytes-like object is required, not 'str'y              @z.a bytes-like object is required, not 'complex's   fooznot NoneTyper   Úbarzan integer is requiredz	(1 given)é   z	(4 given))r	   r,   r   rB   r   rK   r‚   rç   rv   Úsendtor’   rÐ   Ú	exceptionrÚ   )r2   r   ZsocknameÚcmr   r   r   ÚtestSendtoErrors$  sL    
z#GeneralModuleTests.testSendtoErrorsc             C   s4   t j t j t j t j t j t j t j t j d S )N)	r	   r,   r-   r   r   ÚSOCK_RDMr   Ú
SOL_SOCKETÚSO_REUSEADDR)r2   r   r   r   ÚtestCrucialConstantsP  s    z'GeneralModuleTests.testCrucialConstantsc             C   s¸   t  ¡ }yt  |¡}W n tk
r4   |  d¡ Y nX |  | d¡dkd¡ yt  |¡\}}}W n tk
r~   |  d¡ Y nX ||g| }t  |¡}||kr´|  	d|t
|ƒf ¡ d S )Nzname lookup failurer\   r   zError resolving host to ip.z=Error testing host resolution mechanisms. (fqdn: %s, all: %s))r	   ÚgethostnameÚgethostbynamer   rM   r×   ÚfindÚgethostbyaddrZgetfqdnrä   rÜ   )r2   ZhostnameZipZhnameÚaliasesZipaddrsZall_host_namesZfqhnr   r   r   ÚtestHostnameRes[  s    
z"GeneralModuleTests.testHostnameResc             C   sT   x&t jddgD ]}|  t |¡|¡ qW x&t jgD ]}|  |t |¡d ¡ q2W d S )Nz10.0.0.1z255.255.255.255r„   )r   ZHOSTv4r’   r	   r÷   rÚ   rù   )r2   rš   r´   r   r   r   Útest_host_resolutionn  s    z'GeneralModuleTests.test_host_resolutionc          
   C   s^   d}xTdD ]L}| j t|d t |¡ W d Q R X | j t|d t |¡ W d Q R X q
W d S )Nz[resolving an invalid IP address did not raise OSError; can be caused by a broken DNS server)z0.1.1.~1z1+.1.1.1z::1qz::1::2z1:1:1:1:1:1:1:1:1)r”   )rç   r   r	   r÷   rù   )r2   Zexplanationrš   r   r   r   Ú test_host_resolution_bad_addressw  s    
z3GeneralModuleTests.test_host_resolution_bad_addressÚsethostnameztest needs socket.sethostname()rö   ztest needs socket.gethostname()c          
   C   s”   t  ¡ }yt  d¡ W n< tk
rR } z|jtjkr@|  d¡ n‚ W d d }~X Y nX z.|  t  ¡ d¡ t  d¡ |  t  ¡ d¡ W d t  |¡ X d S )NÚnewztest should be run as roots   barrì   )r	   rö   rþ   r   ÚerrnoZEPERMrM   r’   )r2   Zoldhnrw   r   r   r   Útest_sethostname†  s    
z#GeneralModuleTests.test_sethostnameÚif_nameindexz$socket.if_nameindex() not available.c             C   s†   t  ¡ }xx|D ]p\}}|  |t¡ |  |t¡ |  |d¡ t  |¡}|  |t¡ |  ||¡ t  |¡}|  |t¡ |  ||¡ qW d S )Nr   )	r	   r  rØ   ÚintrÐ   ÚassertGreaterÚif_nametoindexr’   Úif_indextoname)r2   Z
interfacesÚindexrÊ   Z_indexÚ_namer   r   r   ÚtestInterfaceNameIndexš  s    

z)GeneralModuleTests.testInterfaceNameIndexc             C   sD   |   ttjd¡ |   ttjd¡ |   ttjd¡ |   ttjd¡ d S )Nr   Z	_DEADBEEF)rç   r   r	   r  r  rv   )r2   r   r   r   ÚtestInvalidInterfaceNameIndexª  s    z0GeneralModuleTests.testInvalidInterfaceNameIndexÚgetrefcountztest needs sys.getrefcount()c             C   sL   yt  t¡}t td¡ W n, tk
rF   t  t¡|krB|  d¡ Y nX d S )Nr   z$socket.getnameinfo loses a reference)Úsysr  r5   r	   Úgetnameinforv   rä   )r2   Úorigr   r   r   ÚtestRefCountGetNameInfo´  s    
z*GeneralModuleTests.testRefCountGetNameInfoc             C   s*   yt  dd¡ W n tk
r$   Y nX d S )N)rI   r   r   r   r   )r	   r  r   )r2   r   r   r   ÚtestInterpreterCrashÀ  s    z'GeneralModuleTests.testInterpreterCrashc          	   C   s–   t jdt jdt jdt jdi}xt| ¡ D ]h\}}d|> d }x,dD ]$}|  ||@ ||||@ ƒƒ|@ ¡ q@W ||ƒ}|  ||@ |¡ |  t|d¡ q&W d S )Né    é   r[   )r   r[   iÿÿ  i  ÿÿr„   igE#i2Tvl        )	r	   ÚhtonlÚntohlÚhtonsÚntohsÚitemsr’   rç   ÚOverflowError)r2   ZsizesÚfuncÚsizeÚmaskr*   Zswappedr   r   r   ÚtestNtoHÈ  s    
$zGeneralModuleTests.testNtoHc             C   s"  dd l }ddddg}|dg }ddddd	> g}||jd |jd g }d
|jg}x |D ]}t |¡ t |¡ qVW x |D ]}t |¡ t |¡ qxW x,|D ]$}|  t	tj|¡ |  t	tj|¡ qšW x,|D ]$}|  t	tj|¡ |  t	tj|¡ qÈW x,|D ]$}|  
ttj|¡ |  
ttj|¡ qöW d S )Nr   r[   r„   iÿÿ  l   ÿÿ éÿÿÿÿéþÿÿÿl        iè  i   )Ú	_testcapiZINT_MINÚINT_MAXr	   r  r  r  r  rç   r  ÚassertWarnsÚDeprecationWarning)r2   r  Zs_good_valuesZl_good_valuesZl_bad_valuesZs_bad_valuesZs_deprecated_valuesÚkr   r   r   ÚtestNtoHErrorsÖ  s,    









z!GeneralModuleTests.testNtoHErrorsc          	   C   s&  | j }tj d¡stjdkr"d}nd}x8|D ],}yt |d¡}P W q, tk
rV   Y q,X q,W t‚ttdƒrvt ¡ dkrŠt |¡}|||ƒ yt |d¡}W n tk
r²   d }Y nX |||ƒ t	j
sÔ|t |¡|ƒ |t |d¡|ƒ |d k	r|t |d¡|ƒ |  ttjd	¡ |  ttjd
¡ d S )N)ZfreebsdZnetbsdZgnukfreebsd)ÚlinuxÚdarwin)ÚdaytimeZqotdÚdomain)Zechor'  r(  ZtcpÚgetandroidapilevelé   Zudpr  i   )r’   r  ÚplatformÚ
startswithr	   Zgetservbynamer   ru   r)  r   Z
is_androidZgetservbyportrç   r  )r2   ÚeqZservicesZservicer0   Zport2Zudpportr   r   r   ÚtestGetServByï  s8    








z GeneralModuleTests.testGetServByc             C   sÈ   |   t ¡ d ¡ t ¡ }|   | ¡ d ¡ | ¡  t d¡ |   t ¡ d¡ t ¡ }|   | ¡ d¡ | ¡  t d ¡ |   t ¡ d ¡ t ¡ }|   | ¡ d ¡ | ¡  |  ttjd¡ |  ttjd¡ d S )Né
   r  Zspam)	r’   r	   ÚgetdefaulttimeoutÚ
gettimeoutr   Úsetdefaulttimeoutrç   Ú
ValueErrorrv   )r2   r   r   r   r   ÚtestDefaultTimeout  s     

z%GeneralModuleTests.testDefaultTimeoutÚ	inet_atonztest needs socket.inet_aton()c             C   s(   |   dt d¡¡ |   dt d¡¡ d S )Ns       z0.0.0.0s   ÿÿÿÿz255.255.255.255)r’   r	   r5  )r2   r   r   r   ÚtestIPv4_inet_aton_fourbytes7  s    z/GeneralModuleTests.testIPv4_inet_aton_fourbytesÚ	inet_ptonztest needs socket.inet_pton()c                s2  ddl m}m‰m‰  ‡ ‡fdd„}‡fdd„}ˆ d|dƒ¡ ˆ d|d	ƒ¡ ˆ d
|dƒ¡ ˆ d|dƒ¡ ˆ d|dƒ¡ tj d¡s”||dƒ ||dƒ ||dƒ ||dƒ ||dƒ ˆ d|dƒ¡ ˆ d|d	ƒ¡ ˆ d
|dƒ¡ ˆ d|dƒ¡ ||dƒ ||dƒ ||dƒ ||dƒ ||dƒ d S )Nr   )r5  r7  r,   c                s
   ˆˆ | ƒS )Nr   )Úa)r,   r7  r   r   r¾   C  r¿   z5GeneralModuleTests.testIPv4toString.<locals>.<lambda>c                s   ˆ   ttf| |¡S )N)rç   r   r3  )r  r8  )r2   r   r   r¾   E  s   s       z0.0.0.0s   ÿ ÿ z255.0.255.0s   ªªªªz170.170.170.170s   z1.2.3.4s   ÿÿÿÿz255.255.255.255Úaixz0.0.0.z	300.0.0.0za.0.0.0z	1.2.3.4.5z::1)r	   r5  r7  r,   r’   r  r+  r,  )r2   r   ÚgÚassertInvalidr   )r,   r7  r2   r   ÚtestIPv4toString?  s.    








z#GeneralModuleTests.testIPv4toStringc          
      sÌ  y&ddl m‰m‰ m} |s$ˆ d¡ W n tk
rD   ˆ d¡ Y nX tjdkr–yˆˆ dƒ W n6 tk
r” } z|j	dkr„ˆ d¡ W d d }~X Y nX ‡ ‡fd	d
„‰‡‡fdd
„}ˆ 
dˆdƒ¡ ˆ 
dˆdƒ¡ ˆ 
dˆdƒ¡ ˆ 
dˆdƒ¡ ˆ 
dˆdƒ¡ ˆ 
dˆdƒ¡ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ |dƒ tj d¡sh|dƒ |dƒ ˆ 
d ˆd!ƒ¡ ˆ 
d"ˆd#ƒ¡ ˆ 
d$ˆd%ƒ¡ |d&ƒ |d'ƒ |d(ƒ |d)ƒ |d*ƒ |d+ƒ d S ),Nr   )r7  r¼   Úhas_ipv6zIPv6 not availablez+could not import needed symbols from socketÚwin32z::i&'  zIPv6 might not be supportedc                s
   ˆˆ | ƒS )Nr   )r8  )r¼   r7  r   r   r¾   q  r¿   z5GeneralModuleTests.testIPv6toString.<locals>.<lambda>c                s   ˆ  ttfˆ | ¡S )N)rç   r   r3  )r8  )r   r2   r   r   r¾   r  s   s                   z0::0s                  z1::s   EïvË Vï¯ë¬$®®z$45ef:76cb:1a:56ef:afeb:bac:1924:aeaes   ­B
¼    '  T zad42:abc::127:0:254:2s     
            z12:a::z0x20::z:::z::0::z1::abc::z1::abc::defz1:2:3:4:5:6z1:2:3:4:5:6:7:8:0r9  z1:2:3:4:5:6:z1:2:3:4:5:6:7:8:s               þ*@z::254.42.23.64s    B        ¢›þ*@z42::a29b:254.42.23.64s    B¨¹   ÿÿ¢›þ*@z"42:a8b9:0:2:ffff:a29b:254.42.23.64z255.254.253.252z1::260.2.3.0z1::0.be.e.0z1:2:3:4:5:6:7:1.2.3.4z::1.2.3.4:0z0.100.200.0:3:4:5:6:7:8)r	   r7  r¼   r=  rM   ÚImportErrorr  r+  r   Úwinerrorr’   r,  )r2   r=  rw   r;  r   )r¼   r   r7  r2   r   ÚtestIPv6toString`  s`    






z#GeneralModuleTests.testIPv6toStringÚ	inet_ntopztest needs socket.inet_ntop()c                s  ddl m}m‰m‰  ‡ ‡fdd„}‡fdd„}ˆ d|dƒ¡ ˆ d|d	ƒ¡ ˆ d
|dƒ¡ ˆ d|dƒ¡ ||dƒ ||dƒ ||dƒ ˆ d|td	ƒƒ¡ ˆ d|dƒ¡ ˆ d|d	ƒ¡ ˆ d
|dƒ¡ ||dƒ ||dƒ ||dƒ ˆ d|td	ƒƒ¡ d S )Nr   )Ú	inet_ntoarB  r,   c                s
   ˆˆ | ƒS )Nr   )r8  )r,   rB  r   r   r¾   ¤  r¿   z5GeneralModuleTests.testStringToIPv4.<locals>.<lambda>c                s   ˆ   ttf| |¡S )N)rç   r   r3  )r  r8  )r2   r   r   r¾   ¥  s   z1.0.1.0s     z170.85.170.85s   ªUªUz255.255.255.255s   ÿÿÿÿz1.2.3.4s   s      s        s                   )r	   rC  rB  r,   r’   Ú	bytearray)r2   r   r:  r;  r   )r,   rB  r2   r   ÚtestStringToIPv4   s$    





z#GeneralModuleTests.testStringToIPv4c          
      s  y&ddl m‰m‰ m} |s$ˆ d¡ W n tk
rD   ˆ d¡ Y nX tjdkr–yˆˆ dƒ W n6 tk
r” } z|j	dkr„ˆ d¡ W d d }~X Y nX ‡ ‡fd	d
„‰‡‡fdd
„}ˆ 
dˆdƒ¡ ˆ 
dˆdƒ¡ ˆ 
dˆdƒ¡ ˆ 
dˆtdƒƒ¡ |dƒ |dƒ |dƒ d S )Nr   )rB  r¼   r=  zIPv6 not availablez+could not import needed symbols from socketr>  s                   i&'  zIPv6 might not be supportedc                s
   ˆˆ | ƒS )Nr   )r8  )r¼   rB  r   r   r¾   Ë  r¿   z5GeneralModuleTests.testStringToIPv6.<locals>.<lambda>c                s   ˆ  ttfˆ | ¡S )N)rç   r   r3  )r8  )r   r2   r   r   r¾   Ì  s   z::z::1s                  z!aef:b01:506:1001:ffff:9997:55:170s   
ïÿÿ™— Ups   s   s   )r	   rB  r¼   r=  rM   r?  r  r+  r   r@  r’   rD  )r2   r=  rw   r;  r   )r¼   r   rB  r2   r   ÚtestStringToIPv6º  s.    


z#GeneralModuleTests.testStringToIPv6c             C   sž   t  ¡ }t tjtj¡}|  |j¡ | d|f¡ | ¡ }yt 	t 
¡ ¡}W n tk
rj   |  d¡ Y nX |  |d d|fd|d  ¡ |  |d |¡ d S )Nz0.0.0.0zname lookup failurer   z
%s invalidr[   )r   Úfind_unused_portr	   r,   r-   rB   r   rK   r‚   r÷   rö   r   rM   rÚ   r’   )r2   r0   r(   rÊ   Z
my_ip_addrr   r   r   ÚtestSockNameÞ  s    zGeneralModuleTests.testSockNamec             C   s@   t   t jt j¡}|  |j¡ | t jt j¡}|  |dkd¡ d S )Nr   zinitial mode is reuse)	r	   r,   r-   rB   r   Ú
getsockoptró   rô   ÚassertFalse)r2   r(   Úreuser   r   r   ÚtestGetSockOptð  s    z!GeneralModuleTests.testGetSockOptc             C   sR   t   t jt j¡}|  |j¡ | t jt jd¡ | t jt j¡}|  	|dkd¡ d S )Nr[   r   zfailed to set reuse mode)
r	   r,   r-   rB   r   Ú
setsockoptró   rô   rI  rJ  )r2   r(   rK  r   r   r   ÚtestSetSockOptø  s
    z!GeneralModuleTests.testSetSockOptc             C   s6   t   t jt j¡}| d¡ | ¡  |  t|jd¡ d S )Nr[   s   spam)r	   r,   r-   Ú
settimeoutr   rç   r   r–   )r2   r(   r   r   r   ÚtestSendAfterClose   s    
z%GeneralModuleTests.testSendAfterClosec          
   C   s€   t   ¡ }| t jdf¡ t j | ¡ d ¡  y| ¡  W n8 tk
rp } z|  |jtjtj	f¡ W d d }~X Y nX |  
d¡ d S )Nr   )rÛ   z#close() should raise EBADF/ENOTSOCK)r	   rK   Z
_LOCALHOSTrÛ   r   r   rÚ   r   ZEBADFZENOTSOCKrä   )r2   r(   rÓ   r   r   r   ÚtestCloseException  s    (z%GeneralModuleTests.testCloseExceptionc             C   sr   t   t jt j¡}|  |jt j¡ tt dƒrH|  |jt jt jB t jf¡ n|  |jt j¡ |  |j	d¡ | 
¡  d S )NÚSOCK_CLOEXECr   )r	   r,   r-   r’   rß   ru   rÚ   rÂ   rR  rà   r   )r2   r(   r   r   r   ÚtestNewAttributes  s    

z$GeneralModuleTests.testNewAttributesc             C   sÀ   t   ¡ }|  |j¡ t ¡ }|d }|d }|  t|jt|f¡ |  t|jt|f¡ xft	 
¡ D ]Z}t ¡ }y| t|f¡ W n8 tk
r´ } z|jtjks¢|dkr¤‚ W d d }~X Y q^X P q^W d S )Ni   é   )r	   rB   r   r   rG  rç   r  rK   r   Ú	itertoolsÚcountr   r   Z
EADDRINUSE)r2   r(   r0   Zbig_portZneg_portr*   rw   r   r   r   Útest_getsockaddrarg!  s    z&GeneralModuleTests.test_getsockaddrargÚntzWindows specificc             C   sŠ   |   ttjdƒ¡ |   ttdƒ¡ |   ttdƒ¡ |   ttdƒ¡ |   ttdƒ¡ t ¡ }|  |j¡ |  t|jdd ¡ | tjd¡ d S )Nr   Z
SIO_RCVALLZ	RCVALL_ONZ
RCVALL_OFFÚSIO_KEEPALIVE_VALSr  )r[   éd   rZ  )	r×   ru   r	   rB   r   rç   r3  r   rY  )r2   r   r   r   r   Útest_sock_ioctl5  s    z"GeneralModuleTests.test_sock_ioctlÚSIO_LOOPBACK_FAST_PATHz1Loopback fast path support required for this testc          
   C   s|   t   ¡ }|  |j¡ y| t jd¡ W n< tk
rb } zd}|j|krP|  d¡ ‚ W d d }~X Y nX |  t	|jt jd ¡ d S )NTi='  zQSIO_LOOPBACK_FAST_PATH is defined but doesn't implemented in this Windows version)
r	   rB   r   r   r\  r   r@  rM   rç   rv   )r2   r   ro   ZWSAEOPNOTSUPPr   r   r   Útest_sio_loopback_fast_pathA  s    

z.GeneralModuleTests.test_sio_loopback_fast_pathc       
   
   C   sL  yt  dd¡ W n< t jk
rL } z|jt jkr:|  d¡ ‚ W d d }~X Y nX x$t  td ¡D ]}|  t|ƒd¡ q\W t  dd¡ t  dd¡ t  d d¡ t	j
rªt  dd¡ ttdƒrÀt ¡ dkrÌt  td	¡ t  td¡ t  td ¡ t  tdt jt j¡}xR|D ]J\}}}}}|  |t j¡ |  t|ƒd
¡ |  |t j¡ |  t|ƒd¡ qþW t  td dt j¡}x&|D ]\}}}}}|  |t j¡ qdW t  td ddt j¡ t  td dddt j¡ t  d dt jt jdt j¡ t  td ¡}t jtd d}	|  ||	¡ t  td t j¡}t jtd t jd}	|  ||	¡ t  td dt j¡}t jtd t jd}	|  ||	¡ t  td ddt j¡}t jtd t jd}	|  ||	¡ t  td dddt j¡}t jtd t jd}	|  ||	¡ t  d dt jt jdt j¡}t jd dt jt jdt jd}	|  ||	¡ |  tt jdd¡ tt dƒrHyt  dd dddt j¡ W n t jk
rF   Y nX d S )NZ	localhostéP   zbuggy libc versionrT  z	127.0.0.1z::1r)  r*  ZhttpzAddressFamily.AF_INETzSocketKind.SOCK_STREAMr   )r´   r0   )rß   )rÂ   )rà   )Úflags)r´   r0   rß   rÂ   rà   r_  u   í €ÚAI_NUMERICSERV)r	   Úgetaddrinforé   r   ZEAI_SERVICErM   r   r’   Úlenr   ÚIPV6_ENABLEDru   r  r)  r,   r-   rÐ   ZSOL_TCPZ
AI_PASSIVEÚ	AF_UNSPECrç   ÚUnicodeEncodeErrorr`  )
r2   rÓ   ÚinfoZinfosrß   rÂ   r]   Zsocktyper8  Úbr   r   r   ÚtestGetaddrinfoQ  sv    


z"GeneralModuleTests.testGetaddrinfoc             C   s   |   ttjdd¡ d S )N)zmail.python.orgr   r   )rç   r   r	   r  )r2   r   r   r   Útest_getnameinfoŸ  s    z#GeneralModuleTests.test_getnameinfoZnetworkznetwork is not enabledc          	   C   sP   t  d¡ t d¡ W d Q R X d}t |¡ t |¡ t |dtjtj¡ d S )Nz
python.orgu!   Ð¸ÑÐ¿Ñ‹Ñ‚Ð°Ð½Ð¸Ðµ.pythontest.netr   )r   Ztransient_internetr	   r÷   Zgethostbyname_exra  rd  r-   )r2   r(  r   r   r   Ú	test_idna£  s    

zGeneralModuleTests.test_idnac          
      sö   t tdƒrt tdƒsˆ  d¡ ‡ fdd„}‡ fdd„}t ¡ \}}t tj|¡}zv|r`| d¡ ˆ  t¡  t 	d	¡ | 
d
tj ¡ W d Q R X |rÄt tj|¡ t 	d	¡ ˆ  tj|j
d
tj ¡ W d t 	d¡ t tj|¡ | ¡  | ¡  X d S )NÚalarmr   z9signal.alarm and socket.socketpair required for this testc                 s   ˆ   ttjd¡ d S )Nr   )rç   r3  ÚmathÚacosh)r?   )r2   r   r   Ú
ok_handlerº  s    z@GeneralModuleTests.check_sendall_interrupted.<locals>.ok_handlerc                 s   ˆ   ttjd¡ dd  d S )Nr   r[   )rç   r3  rl  rm  )r?   )r2   r   r   Úraising_handler¼  s    zEGeneralModuleTests.check_sendall_interrupted.<locals>.raising_handlerg      ø?r[   ó   xr   )ru   Úsignalr	   rM   r   ÚSIGALRMrO  rç   ÚZeroDivisionErrorrk  Úsendallr   ÚSOCK_MAX_SIZEÚtimeoutr   )r2   Zwith_timeoutrn  ro  Úcr   Ú	old_alarmr   )r2   r   Úcheck_sendall_interrupted´  s*    




z,GeneralModuleTests.check_sendall_interruptedc             C   s   |   d¡ d S )NF)ry  )r2   r   r   r   Útest_sendall_interruptedÓ  s    z+GeneralModuleTests.test_sendall_interruptedc             C   s   |   d¡ d S )NT)ry  )r2   r   r   r   Ú%test_sendall_interrupted_with_timeoutÖ  s    z8GeneralModuleTests.test_sendall_interrupted_with_timeoutc          	   C   s¦   t   t jt j¡}t|ƒ}|  t¡}d }t ¡  W d Q R X |  |t	|j
jd ƒ¡ t   t jt j¡}| d¡}t|ƒ}d }t ¡  |  t¡ d }t ¡  W d Q R X d S )Nr   r   )r	   r,   r-   rÜ   r!  ÚResourceWarningr   Z
gc_collectrÚ   rÐ   Zwarningr?   Úmakefile)r2   r(   r   rð   r   r   r   r   Útest_dealloc_warnÙ  s    
z$GeneralModuleTests.test_dealloc_warnc          	   C   sB   t   t jt j¡(}| d¡}| ¡  |  t|ƒd¡ W d Q R X d S )Nr   z<_io.BufferedReader name=-1>)r	   r,   r-   r}  r   r’   rÜ   )r2   r(   Úfpr   r   r   Útest_name_closed_socketioê  s    
z,GeneralModuleTests.test_name_closed_socketioc          	   C   s‚   t   ¡ p}|jddd}|  | ¡ ¡ |  | ¡ ¡ |  | ¡ ¡ | ¡  |  t	|j¡ |  t	|j¡ |  t	|j¡ W d Q R X d S )Nr   r   )Ú	buffering)
r	   r}  r×   ÚreadablerJ  ÚwritableÚseekabler   rç   r3  )r2   r(   r  r   r   r   Útest_unusable_closed_socketioð  s    
z0GeneralModuleTests.test_unusable_closed_socketioc             C   s®   t   ¡ }z@| tdf¡ t  | ¡ ¡ |  t¡ | d¡ W d Q R X W d |  t¡ | ¡  W d Q R X X |  t¡ t  d ¡ W d Q R X |  t¡ t  d¡ W d Q R X d S )Nr   r[   r  )	r	   rK   r   r   rÛ   rç   r   r1   rv   )r2   r(   r   r   r   Útest_socket_closeû  s    z$GeneralModuleTests.test_socket_closec             C   sb   x\dD ]T}| j |d> t ¡ *}| |¡}|  |j|¡ W d Q R X W d Q R X W d Q R X qW d S )N)r   r   ÚrwÚwÚwb)Úmode)ÚsubTestr	   r}  r’   rŠ  )r2   rŠ  r(   r  r   r   r   Útest_makefile_mode  s
    

z%GeneralModuleTests.test_makefile_modec             C   s`   xZdD ]R}| j |d< t ¡ (}|  td¡ | |¡ W d Q R X W d Q R X W d Q R X qW d S )N)ÚrtrI   ú+r8  )rŠ  zinvalid mode)r‹  r	   ÚassertRaisesRegexr3  r}  )r2   rŠ  r(   r   r   r   Útest_makefile_invalid_mode  s
    

z-GeneralModuleTests.test_makefile_invalid_modec          	   C   s¢   t   ¡ }|0 x(ttjd ƒD ]}|  ttj||¡ qW W d Q R X xZttjd ƒD ]H}t t t j|¡¡}|  	|t j¡ t t t j
|¡¡}|  	|t j
¡ qRW d S )Nr[   )r	   ÚrangeÚpickleZHIGHEST_PROTOCOLrç   rv   ÚdumpsÚloadsr,   r’   r-   )r2   r(   Zprotocolrß   rÂ   r   r   r   Útest_pickle  s     zGeneralModuleTests.test_picklec          
   C   sx   x@dD ]8}t   t jt j¡}| tdf¡ | |¡ W d Q R X qW t   t jt j¡}| tdf¡ | ¡  W d Q R X d S )N)r   r  r   )r	   r,   r-   rK   r   r1   )r2   ZbacklogÚsrvr   r   r   Útest_listen_backlog$  s    
z&GeneralModuleTests.test_listen_backlogc             C   sH   dd l }t tjtj¡}| tdf¡ |  t|j|j	d ¡ | 
¡  d S )Nr   r[   )r  r	   r,   r-   rK   r   rç   r  r1   r   r   )r2   r  r–  r   r   r   Útest_listen_backlog_overflow.  s
    z/GeneralModuleTests.test_listen_backlog_overflowzIPv6 required for this test.c          	   C   sR   |   ttjtjddfd¡ t tjtj¡}|   t|jtjddf¡ W d Q R X d S )Nr   l   ÿÿ iöÿÿÿ)	rç   r  r	   r  r   rº   r¼   r-   rK   )r2   r   r   r   r   Útest_flowinfo7  s    
z GeneralModuleTests.test_flowinfoc             C   s0   t  ddt jt jt j¡\^ }}|  |d¡ d S )Nzff02::1de:c0:face:8DiÒ  )zff02::1de:c0:face:8diÒ  r   r   )r	   ra  r¼   r   ÚIPPROTO_UDPr’   )r2   r]   Úsockaddrr   r   r   Útest_getaddrinfo_ipv6_basic>  s    z.GeneralModuleTests.test_getaddrinfo_ipv6_basiczif_nameindex is not supportedc             C   sL   t  ¡ d \}}t  d| dt jt jt j¡\^ }}|  |ddd|f¡ d S )Nr   zff02::1de:c0:face:8D%iÒ  zff02::1de:c0:face:8d)r	   r  ra  r¼   r   rš  r’   )r2   ÚifindexÚtest_interfacer]   r›  r   r   r   Ú&test_getaddrinfo_ipv6_scopeid_symbolicH  s    z9GeneralModuleTests.test_getaddrinfo_ipv6_scopeid_symbolicr>  z.Numeric scope id does not work or undocumentedc             C   sD   d}t  dt|ƒ dt jt jt j¡\^ }}|  |ddd|f¡ d S )Né*   zff02::1de:c0:face:8D%iÒ  zff02::1de:c0:face:8dr   )r	   ra  rÐ   r¼   r   rš  r’   )r2   r  r]   r›  r   r   r   Ú%test_getaddrinfo_ipv6_scopeid_numericX  s    
z8GeneralModuleTests.test_getaddrinfo_ipv6_scopeid_numericc             C   sH   t  ¡ d \}}ddd|f}t  |t jt jB ¡}|  |d| df¡ d S )Nr   zff02::1de:c0:face:8DiÒ  zff02::1de:c0:face:8d%Ú1234)r	   r  r  ÚNI_NUMERICHOSTÚNI_NUMERICSERVr’   )r2   r  rž  r›  Únameinfor   r   r   Ú&test_getnameinfo_ipv6_scopeid_symbolici  s    z9GeneralModuleTests.test_getnameinfo_ipv6_scopeid_symbolicc             C   s@   d}ddd|f}t  |t jt jB ¡}|  |dt|ƒ df¡ d S )Nr   zff02::1de:c0:face:8DiÒ  r   zff02::1de:c0:face:8d%r¢  )r	   r  r£  r¤  r’   rÐ   )r2   r  r›  r¥  r   r   r   Ú%test_getnameinfo_ipv6_scopeid_numerict  s    z8GeneralModuleTests.test_getnameinfo_ipv6_scopeid_numericc          	   C   sD   t   t jt j¡*}|  t|jƒd¡ |  t|jƒd¡ W d Q R X d S )NzAddressFamily.AF_INETzSocketKind.SOCK_STREAM)r	   r,   r-   r’   rÐ   rß   rÂ   )r2   r   r   r   r   Útest_str_for_enums€  s    z%GeneralModuleTests.test_str_for_enumsc          	   C   s¼   t tddƒ}t tddƒ}tj|B |B }t tj|¡~}|  |jtj¡ | d¡ |  |jtj¡ | d¡ |  |jtj¡ | d¡ |  |jtj¡ | d¡ |  |jtj¡ W d Q R X d S )NÚSOCK_NONBLOCKr   rR  r[   TF)rh   r	   r-   r,   r’   rÂ   rO  Úsetblocking)r2   r©  rR  Z	sock_typer   r   r   r   Ú test_socket_consistent_sock_type‡  s    



z3GeneralModuleTests.test_socket_consistent_sock_typezWill not work on Windowsc          	   C   sœ   t  ¡ \}}|  tj|¡ ttjj 	¡ ƒd }tdd„ tj
j ¡ D ƒƒd }tj||d|d4}|  |j|¡ |  |j|¡ |  |jddh¡ W d Q R X d S )Nr[   c             s   s   | ]\}}|d kr|V  qdS )>   r©  rR  Nr   )rÉ   rÊ   Úkindr   r   r   rÌ   ¦  s   zEGeneralModuleTests.test_unknown_socket_family_repr.<locals>.<genexpr>r*  )rß   rÂ   rà   rÛ   r   )r©   ÚmkstemprB   r&   r¯   Úmaxr	   ZAddressFamilyÚ__members__ÚvaluesZ
SocketKindr  r’   rß   rÂ   rÚ   rà   )r2   Úfdr°   Zunknown_familyZunknown_typer   r   r   r   Útest_unknown_socket_family_repr—  s    

z2GeneralModuleTests.test_unknown_socket_family_reprÚsendfileztest needs os.sendfile()c          
   C   s²   G dd„ dƒ}t   ¡ ’}t tjtj¡}t |¡ |  t j¡ | ||ƒ¡ W d Q R X |  t	¡ | |dd ƒ¡ W d Q R X |  t
¡ | |d ƒ¡ W d Q R X W d Q R X d S )Nc               @   s   e Zd Zdd„ Zdd„ ZdS )z<GeneralModuleTests.test__sendfile_use_sendfile.<locals>.Filec             S   s
   || _ d S )N)r±  )r2   r±  r   r   r   r;   ¶  s    zEGeneralModuleTests.test__sendfile_use_sendfile.<locals>.File.__init__c             S   s   | j S )N)r±  )r2   r   r   r   rÛ   ¹  s    zCGeneralModuleTests.test__sendfile_use_sendfile.<locals>.File.filenoN)r5   r6   r7   r;   rÛ   r   r   r   r   ÚFileµ  s   r´  r„   iè  )r	   r&   r   ÚcurdirÚO_RDONLYr   rç   Ú_GiveupOnSendfileÚ_sendfile_use_sendfiler  rv   )r2   r´  r(   r±  r   r   r   Útest__sendfile_use_sendfile³  s    

z.GeneralModuleTests.test__sendfile_use_sendfilec             C   st   |   |j|¡ |   |j|¡ | ¡ }tj|d}|  |j¡ | ¡  |   |j|¡ |   |j|¡ |   | ¡ |¡ d S )N)rÛ   )r’   rß   rÂ   rÛ   r	   rB   r   Údetach)r2   r   rß   Ústyper±  Ús2r   r   r   Ú_test_socket_filenoÅ  s    z&GeneralModuleTests._test_socket_filenoc             C   s6  t   t jt j¡}|  |j¡ | tjdf¡ |  |t jt j¡ t	t dƒr†t   t jt j
¡}|  |j¡ | tjdf¡ |  |t jt j
¡ tjrÎt   t jt j¡}|  |j¡ | tjdddf¡ |  |t jt j¡ t	t dƒr2t ¡ }|  tj|¡ t   t jt j¡}|  |j¡ | tj |d¡¡ |  |t jt j¡ d S )Nr   r   r²   r	   )r	   r,   r-   rB   r   rK   r   r   r½  ru   r   rc  r¼   rº   r©   rª   ÚshutilZrmtreer²   r&   r°   rÍ   )r2   r   Ztmpdirr   r   r   Útest_socket_filenoÒ  s*    
z%GeneralModuleTests.test_socket_fileno)Mr5   r6   r7   rÙ   rÞ   r†   Ú
skipUnlessrÖ   râ   ræ   rê   rñ   rõ   rû   rü   rý   ru   r	   r  r	  r
  r  r  r  r  r   Úcpython_onlyr$  r.  r4  r6  r<  rA  rE  rF  rH  rL  rN  rP  rQ  rS  rW  r&   rÊ   r[  r]  rh  ri  Zis_resource_enabledrj  ry  rz  r{  r~  r€  r…  r†  rŒ  r  r•  r—  r˜  rc  r™  rœ  rŸ  r+  r¡  r¦  r§  r¨  r«  ÚskipIfr²  r¹  r½  r¿  r   r   r   r   rÕ   é  s¨   
,		, ?#N
	
	rÕ   z!SocketCan required for this test.c               @   s”   e Zd Zdd„ Ze eedƒd¡dd„ ƒZdd„ Z	e eedƒd¡d	d
„ ƒZ
dd„ Zdd„ Ze eedƒd¡dd„ ƒZe eedƒd¡dd„ ƒZdS )ÚBasicCANTestc             C   s   t j t j t j d S )N)r	   ÚAF_CANr   r   )r2   r   r   r   rõ   ð  s    z!BasicCANTest.testCrucialConstantsÚCAN_BCMz&socket.CAN_BCM required for this test.c             C   sR   t j t j t j t j t j t j t j t j t j	 t j
 t j t j t j d S )N)r	   rÅ  ZCAN_BCM_TX_SETUPZCAN_BCM_TX_DELETEZCAN_BCM_TX_READÚCAN_BCM_TX_SENDZCAN_BCM_RX_SETUPZCAN_BCM_RX_DELETEZCAN_BCM_RX_READZCAN_BCM_TX_STATUSZCAN_BCM_TX_EXPIREDZCAN_BCM_RX_STATUSZCAN_BCM_RX_TIMEOUTZCAN_BCM_RX_CHANGED)r2   r   r   r   ÚtestBCMConstantsõ  s    zBasicCANTest.testBCMConstantsc          	   C   s$   t   t jt jt j¡}W d Q R X d S )N)r	   r   r   r   )r2   r   r   r   r   ÚtestCreateSocket  s    zBasicCANTest.testCreateSocketc          	   C   s$   t   t jt jt j¡}W d Q R X d S )N)r	   r   r   rÅ  )r2   r   r   r   r   ÚtestCreateBCMSocket  s    z BasicCANTest.testCreateBCMSocketc          	   C   s.   t   t jt jt j¡}| d¡ W d Q R X d S )N)rë   )r	   r   r   r   rK   )r2   r   r   r   r   ÚtestBindAny  s    zBasicCANTest.testBindAnyc          	   C   s6   t   t jt jt j¡}|  td|jd¡ W d Q R X d S )Nzinterface name too long)Á   xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx)r	   r   r   r   r  r   rK   )r2   r   r   r   r   ÚtestTooLongInterfaceName  s    z%BasicCANTest.testTooLongInterfaceNameÚCAN_RAW_LOOPBACKz/socket.CAN_RAW_LOOPBACK required for this test.c          	   C   s\   t   t jt jt j¡>}x6dD ].}| t jt j|¡ |  || t jt j¡¡ qW W d Q R X d S )N)r   r[   )	r	   r   r   r   rM  ÚSOL_CAN_RAWrÍ  r’   rI  )r2   r   Zloopbackr   r   r   ÚtestLoopback  s    
zBasicCANTest.testLoopbackÚCAN_RAW_FILTERz-socket.CAN_RAW_FILTER required for this test.c          	   C   s|   d\}}t  d||¡}t tjtjtj¡H}| tjtj|¡ |  	|| 
tjtjd¡¡ | tjtjt|ƒ¡ W d Q R X d S )N)i   i   z=IIrJ   )r   Úpackr	   r   r   r   rM  rÎ  rÐ  r’   rI  rD  )r2   Úcan_idZcan_maskZ
can_filterr   r   r   r   Ú
testFilter&  s    zBasicCANTest.testFilterN)r5   r6   r7   rõ   r†   rÀ  ru   r	   rÇ  rÈ  rÉ  rÊ  rÌ  rÏ  rÓ  r   r   r   r   rÃ  í  s   	rÃ  c               @   s’   e Zd Zddd„Zedd„ ƒZedd„ ƒZdd	„ Zd
d„ Zdd„ Z	dd„ Z
dd„ Zdd„ Ze eedƒd¡dd„ ƒZe eedƒd¡dd„ ƒZdS )ÚCANTestr{   c             C   s   t j| |d d S )N)r|   )r   r;   )r2   r|   r   r   r   r;   5  s    zCANTest.__init__c             C   s&   t |ƒ}| dd¡}t | j|||¡S )zBuild a CAN frame.rJ   ó    )rb  Úljustr   rÑ  rO   )ÚclsrÒ  ÚdataÚcan_dlcr   r   r   Úbuild_can_frame8  s    zCANTest.build_can_framec             C   s&   t  | j|¡\}}}|||d|… fS )zDissect a CAN frame.N)r   r   rO   )r×  ÚframerÒ  rÙ  rØ  r   r   r   Údissect_can_frame?  s    zCANTest.dissect_can_framec             C   sH   | j  | j¡\}}|  | j|¡ |  |d | j¡ |  |d tj¡ d S )Nr   r[   )r   ÚrecvfromrN   r’   ÚcfrL   r	   rÄ  )r2   rÞ  rš   r   r   r   ÚtestSendFrameE  s    zCANTest.testSendFramec             C   s    |   dd¡| _| j | j¡ d S )Nr   s   )rÚ  rÞ  r}   r–   )r2   r   r   r   Ú_testSendFrameK  s    zCANTest._testSendFramec             C   s$   | j  | j¡\}}|  | j|¡ d S )N)r   rÝ  rN   r’   rÞ  )r2   rÞ  rš   r   r   r   ÚtestSendMaxFrameO  s    zCANTest.testSendMaxFramec             C   s    |   dd¡| _| j | j¡ d S )Nr   s   )rÚ  rÞ  r}   r–   )r2   r   r   r   Ú_testSendMaxFrameS  s    zCANTest._testSendMaxFramec             C   sD   | j  | j¡\}}|  | j|¡ | j  | j¡\}}|  | j|¡ d S )N)r   rÝ  rN   r’   Úcf1Úcf2)r2   rÞ  rš   r   r   r   ÚtestSendMultiFramesW  s    zCANTest.testSendMultiFramesc             C   s<   |   dd¡| _| j | j¡ |   dd¡| _| j | j¡ d S )Né   s   D3"é   s   ™"3)rÚ  rã  r}   r–   rä  )r2   r   r   r   Ú_testSendMultiFrames^  s    zCANTest._testSendMultiFramesrÅ  z&socket.CAN_BCM required for this test.c             C   sP   | j  | j¡\}}|  | j|¡ |  |¡\}}}|  | j|¡ |  | j|¡ d S )N)r}   rÝ  rN   r’   rÞ  rÜ  rÒ  rØ  )r2   rÞ  rš   rÒ  rÙ  rØ  r   r   r   Ú_testBCMe  s
    zCANTest._testBCMc             C   sÔ   t   t jt jt j¡}|  |j¡ | | jf¡ d| _t	dddgƒ| _
|  | j| j
¡| _t j}d}d}d } } }}d}	d}
t| jƒdksŽt‚t | j||||||||	|
¡
}|| j }| |¡}|  |t|ƒ¡ d S )	Ni#  éÀ   éÿ   éî   r   i"  r[   r  )r	   r   r   rÅ  rB   r   r   rL   rÒ  ÚbytesrØ  rÚ  rÞ  rÆ  rb  ÚAssertionErrorr   rÑ  rQ   r–   r’   )r2   ZbcmZopcoder_  rV  Zival1_secondsZ
ival1_usecZival2_secondsZ
ival2_usecZ
bcm_can_idZnframesÚheaderZheader_plus_frameZ
bytes_sentr   r   r   ÚtestBCMn  s4    

zCANTest.testBCMN)r{   )r5   r6   r7   r;   ÚclassmethodrÚ  rÜ  rß  rà  rá  râ  rå  rè  r†   rÀ  ru   r	   ré  rð  r   r   r   r   rÔ  2  s   
rÔ  z!CAN ISOTP required for this test.c                   sV   e Zd Z‡ fdd„Zdd„ Zdd„ Ze ee	dƒd¡d	d
„ ƒZ
dd„ Zdd„ Z‡  ZS )Ú	ISOTPTestc                s   t ƒ j||Ž d| _d S )NrG   )r:   r;   rL   )r2   r?   r@   )rA   r   r   r;   ‘  s    zISOTPTest.__init__c             C   s   t j t j t j t j d S )N)r	   rÄ  r   r   r   )r2   r   r   r   rõ   •  s    zISOTPTest.testCrucialConstantsc          	   C   s$   t   t jt jt j¡}W d Q R X d S )N)r	   r   r   r   )r2   r   r   r   r   rÈ  ›  s    zISOTPTest.testCreateSocketr   z(socket.CAN_ISOTP required for this test.c          	   C   s$   t   t jt jt j¡}W d Q R X d S )N)r	   r   r   r   )r2   r   r   r   r   ÚtestCreateISOTPSocketŸ  s    zISOTPTest.testCreateISOTPSocketc          
   C   sF   t   t jt jt j¡(}|  td¡ | d¡ W d Q R X W d Q R X d S )Nzinterface name too long)rË  r[   r„   )r	   r   r   r   r  r   rK   )r2   r   r   r   r   rÌ  ¥  s    z"ISOTPTest.testTooLongInterfaceNamec          
   C   s’   yJt   t jt jt j¡,}| jddf}| |¡ |  | ¡ |¡ W d Q R X W nB tk
rŒ } z$|j	t	j
krz|  d| j ¡ n‚ W d d }~X Y nX d S )Ni#  iV  z%network interface `%s` does not exist)r	   r   r   r   rL   rK   r’   r‚   r   r   ZENODEVrM   )r2   r   rš   rw   r   r   r   ÚtestBind«  s    
zISOTPTest.testBind)r5   r6   r7   r;   rõ   rÈ  r†   rÀ  ru   r	   ró  rÌ  rô  rE   r   r   )rA   r   rò  Ž  s   rò  z#RDS sockets required for this test.c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚBasicRDSTestc             C   s   t j t j d S )N)r	   ZAF_RDSr   )r2   r   r   r   rõ   ¼  s    z!BasicRDSTest.testCrucialConstantsc          	   C   s"   t   t jt jd¡}W d Q R X d S )Nr   )r	   r   r   )r2   r   r   r   r   rÈ  À  s    zBasicRDSTest.testCreateSocketc          	   C   sJ   d}t   t jt jd¡*}| t jt j|¡ | t jt j|¡ W d Q R X d S )Ni @  r   )r	   r   r   rM  ró   Z	SO_RCVBUFZ	SO_SNDBUF)r2   rN   r   r   r   r   ÚtestSocketBufferSizeÄ  s    z!BasicRDSTest.testSocketBufferSizeN)r5   r6   r7   rõ   rÈ  rö  r   r   r   r   rõ  ¹  s   rõ  c                   sŽ   e Zd Zddd„Z‡ fdd„Zdd„ Zdd	„ Zd
d„ Zdd„ Ze	e
j
dƒdd„ ƒZe	e
j
dƒdd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Z‡  ZS )ÚRDSTestr{   c             C   s   t j| |d d S )N)r|   )r€   r;   )r2   r|   r   r   r   r;   Î  s    zRDSTest.__init__c                s   t ƒ  ¡  t ¡ | _d S )N)r:   r3   r<   r`   Zevt)r2   )rA   r   r   r3   Ñ  s    
zRDSTest.setUpc             C   s2   | j  | j¡\}}|  | j|¡ |  | j|¡ d S )N)r.   rÝ  rN   r’   rØ  rƒ   )r2   rØ  rš   r   r   r   ÚtestSendAndRecvÕ  s    zRDSTest.testSendAndRecvc             C   s"   d| _ | j | j dt| jf¡ d S )Ns   spamr   )rØ  r}   rî   r   r0   )r2   r   r   r   Ú_testSendAndRecvÚ  s    zRDSTest._testSendAndRecvc             C   sH   | j  | jtj¡\}}|  | j|¡ | j  | j¡\}}|  | j|¡ d S )N)r.   rÝ  rN   r	   ÚMSG_PEEKr’   rØ  )r2   rØ  rš   r   r   r   ÚtestPeekÞ  s    zRDSTest.testPeekc             C   s"   d| _ | j | j dt| jf¡ d S )Ns   spamr   )rØ  r}   rî   r   r0   )r2   r   r   r   Ú	_testPeekä  s    zRDSTest._testPeekÚrecvmsgc             C   s(   | j  | j¡\}}}}|  | j|¡ d S )N)r.   rý  rN   r’   rØ  )r2   rØ  ÚancdataZ	msg_flagsrš   r   r   r   ÚtestSendAndRecvMsgè  s    zRDSTest.testSendAndRecvMsgÚsendmsgc             C   s&   d| _ | j | j gddt| jf¡ d S )Ns<   hello hello hello hello hello hello hello hello hello hello r   r   )rØ  r}   r   r   r0   )r2   r   r   r   Ú_testSendAndRecvMsgí  s    zRDSTest._testSendAndRecvMsgc             C   sD   | j  | j¡\}}|  | j|¡ | j  | j¡\}}|  | j|¡ d S )N)r.   rÝ  rN   r’   Údata1Údata2)r2   rØ  rš   r   r   r   ÚtestSendAndRecvMultiò  s    zRDSTest.testSendAndRecvMultic             C   s@   d| _ | j | j dt| jf¡ d| _| j | jdt| jf¡ d S )Ns   baconr   s   egg)r  r}   rî   r   r0   r  )r2   r   r   r   Ú_testSendAndRecvMultiù  s    zRDSTest._testSendAndRecvMultic             C   sL   t   | jgg g d¡\}}}|  | j|¡ | j | j¡\}}|  | j|¡ d S )Ng      @)Úselectr.   rÚ   rÝ  rN   r’   rØ  )r2   r   rˆ  rI   rØ  rš   r   r   r   Ú
testSelect   s    zRDSTest.testSelectc             C   s"   d| _ | j | j dt| jf¡ d S )Ns   selectr   )rØ  r}   rî   r   r0   )r2   r   r   r   Ú_testSelect  s    zRDSTest._testSelect)r{   )r5   r6   r7   r;   r3   rø  rù  rû  rü  rÏ   r	   rÿ  r  r  r  r  r  rE   r   r   )rA   r   r÷  Ë  s   
r÷  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚBasicVSOCKTestc             C   s
   t j d S )N)r	   rˆ   )r2   r   r   r   rõ     s    z#BasicVSOCKTest.testCrucialConstantsc             C   s4   t j t j t j t j t j t j t j t j d S )N)	r	   ÚSO_VM_SOCKETS_BUFFER_SIZEÚSO_VM_SOCKETS_BUFFER_MIN_SIZEÚSO_VM_SOCKETS_BUFFER_MAX_SIZEr‰   ZVMADDR_PORT_ANYZVMADDR_CID_HOSTZVM_SOCKETS_INVALID_VERSIONr
   )r2   r   r   r   ÚtestVSOCKConstants  s    z!BasicVSOCKTest.testVSOCKConstantsc          	   C   s    t   t jt j¡}W d Q R X d S )N)r	   rˆ   r-   )r2   r   r   r   r   rÈ    s    zBasicVSOCKTest.testCreateSocketc          	   C   sæ   t   t jt j¡Ì}| t jt j¡}| t jt j¡}| t jt j¡}| t jt j|d ¡ | t jt j|d ¡ | t jt j|d ¡ |  |d | t jt j¡¡ |  |d | t jt j¡¡ |  |d | t jt j¡¡ W d Q R X d S )Nr„   )	r	   rˆ   r-   rI  r  r
  r  rM  r’   )r2   r   Zorig_maxr  Zorig_minr   r   r   rö  !  s,    




z#BasicVSOCKTest.testSocketBufferSizeN)r5   r6   r7   rõ   r  rÈ  rö  r   r   r   r   r	    s   
r	  c               @   s¾   e Zd Zd+dd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Ze e¡Zejd$d%„ ƒZd&d'„ Zd(d)„ Zd*S ),ÚBasicTCPTestr{   c             C   s   t j| |d d S )N)r|   )r˜   r;   )r2   r|   r   r   r   r;   >  s    zBasicTCPTest.__init__c             C   s   | j  d¡}|  |t¡ d S )Ni   )r™   r‘   r’   r“   )r2   r”   r   r   r   ÚtestRecvA  s    zBasicTCPTest.testRecvc             C   s   | j  t¡ d S )N)r›   r–   r“   )r2   r   r   r   Ú	_testRecvF  s    zBasicTCPTest._testRecvc             C   s8   | j  ttƒd ¡}| j  d¡}|| }|  |t¡ d S )Né   i   )r™   r‘   rb  r“   r’   )r2   Úseg1Úseg2r”   r   r   r   ÚtestOverFlowRecvI  s    zBasicTCPTest.testOverFlowRecvc             C   s   | j  t¡ d S )N)r›   r–   r“   )r2   r   r   r   Ú_testOverFlowRecvP  s    zBasicTCPTest._testOverFlowRecvc             C   s    | j  d¡\}}|  |t¡ d S )Ni   )r™   rÝ  r’   r“   )r2   r”   rš   r   r   r   ÚtestRecvFromS  s    zBasicTCPTest.testRecvFromc             C   s   | j  t¡ d S )N)r›   r–   r“   )r2   r   r   r   Ú_testRecvFromX  s    zBasicTCPTest._testRecvFromc             C   s@   | j  ttƒd ¡\}}| j  d¡\}}|| }|  |t¡ d S )Nr  i   )r™   rÝ  rb  r“   r’   )r2   r  rš   r  r”   r   r   r   ÚtestOverFlowRecvFrom[  s    z!BasicTCPTest.testOverFlowRecvFromc             C   s   | j  t¡ d S )N)r›   r–   r“   )r2   r   r   r   Ú_testOverFlowRecvFromb  s    z"BasicTCPTest._testOverFlowRecvFromc             C   s4   d}x| j  d¡}|sP ||7 }qW |  |d¡ d S )Nr¿   i   s   ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)r™   r‘   r’   )r2   r”   Úreadr   r   r   ÚtestSendAlle  s    zBasicTCPTest.testSendAllc             C   s   d}| j  |¡ d S )Ns   ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff)r›   rt  )r2   Z	big_chunkr   r   r   Ú_testSendAllo  s    zBasicTCPTest._testSendAllc             C   sP   | j  ¡ }t |tjtj¡}|  |j¡ |  |tj¡ | 	d¡}|  
|t¡ d S )Ni   )r™   rÛ   r	   Zfromfdr,   r-   rB   r   rØ   r‘   r’   r“   )r2   r±  r(   r”   r   r   r   Ú
testFromFds  s    

zBasicTCPTest.testFromFdc             C   s   | j  t¡ d S )N)r›   r–   r“   )r2   r   r   r   Ú_testFromFd|  s    zBasicTCPTest._testFromFdc             C   s0   | j  ¡ }|  |j¡ | d¡}|  |t¡ d S )Ni   )r™   ÚduprB   r   r‘   r’   r“   )r2   r(   r”   r   r   r   ÚtestDup  s    

zBasicTCPTest.testDupc             C   s   | j  t¡ d S )N)r›   r–   r“   )r2   r   r   r   Ú_testDup†  s    zBasicTCPTest._testDupc             C   s&   | j  d¡}|  |t¡ | j ¡  d S )Ni   )r™   r‘   r’   r“   rb   rl   )r2   r”   r   r   r   ÚtestShutdown‰  s    zBasicTCPTest.testShutdownc             C   s   | j  t¡ | j  d¡ d S )Nr„   )r›   r–   r“   Úshutdown)r2   r   r   r   Ú_testShutdown’  s    zBasicTCPTest._testShutdownc             C   sX   dd l }| j t¡ |  t| jj|jd ¡ |  t| jjd|jd  ¡ | j d¡ d S )Nr   r[   r„   )	r  r›   r–   r“   rç   r  r#  r   ÚUINT_MAX)r2   r  r   r   r   Ú_testShutdown_overflow˜  s    z#BasicTCPTest._testShutdown_overflowc             C   s„   | j  ¡ }| j  ¡ }|  ||¡ |  | j j¡ |  t| j jd¡ | j  	¡  t
j
t
jt
j|d}|  |j	¡ | d¡}|  |t¡ d S )Ni   )rÛ   )r™   rÛ   rº  r’   r×   Ú_closedrç   r   r‘   r   r	   r,   r-   rB   r“   )r2   rÛ   r   r(   r”   r   r   r   Ú
testDetach£  s    



zBasicTCPTest.testDetachc             C   s   | j  t¡ d S )N)r›   r–   r“   )r2   r   r   r   Ú_testDetach³  s    zBasicTCPTest._testDetachN)r{   )r5   r6   r7   r;   r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r$  r   rÁ  ZtestShutdown_overflowr&  r(  r)  r   r   r   r   r  <  s*   

		
r  c               @   sF   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dS )ÚBasicUDPTestr{   c             C   s   t j| |d d S )N)r|   )r~   r;   )r2   r|   r   r   r   r;   ¹  s    zBasicUDPTest.__init__c             C   s    | j  ttƒ¡}|  |t¡ d S )N)r.   r‘   rb  r“   r’   )r2   r”   r   r   r   ÚtestSendtoAndRecv¼  s    zBasicUDPTest.testSendtoAndRecvc             C   s   | j  tdt| jf¡ d S )Nr   )r}   rî   r“   r   r0   )r2   r   r   r   Ú_testSendtoAndRecvÁ  s    zBasicUDPTest._testSendtoAndRecvc             C   s$   | j  ttƒ¡\}}|  |t¡ d S )N)r.   rÝ  rb  r“   r’   )r2   r”   rš   r   r   r   r  Ä  s    zBasicUDPTest.testRecvFromc             C   s   | j  tdt| jf¡ d S )Nr   )r}   rî   r“   r   r0   )r2   r   r   r   r  É  s    zBasicUDPTest._testRecvFromc             C   s   |   t| jjd¡ d S )Nr  )rç   r3  r.   rÝ  )r2   r   r   r   ÚtestRecvFromNegativeÌ  s    z!BasicUDPTest.testRecvFromNegativec             C   s   | j  tdt| jf¡ d S )Nr   )r}   rî   r“   r   r0   )r2   r   r   r   Ú_testRecvFromNegativeÐ  s    z"BasicUDPTest._testRecvFromNegativeN)r{   )
r5   r6   r7   r;   r+  r,  r  r  r-  r.  r   r   r   r   r*  ·  s   
r*  c                   s„   e Zd ZdZ‡ fdd„Zdd„ ZdZdd„ Zd	d
„ Zdd„ Z	dd„ Z
dZxdD ]ZeeeedƒO ZqNW dZdZdZddd„Z‡  ZS )ÚSendrecvmsgBaseg      @c                s   t  ¡ | _tƒ  ¡  d S )N)r<   r`   Ú
misc_eventr:   r3   )r2   )rA   r   r   r3   õ  s    
zSendrecvmsgBase.setUpc             C   s   | j  |¡S )N)Úcli_sockr–   )r2   r”   r   r   r   ÚsendToServerù  s    zSendrecvmsgBase.sendToServerr   c             G   s   | j j|| jt|ƒd …  Ž S )N)r1  r   Úsendmsg_to_server_defaultsrb  )r2   r?   r   r   r   ÚsendmsgToServer	  s    zSendrecvmsgBase.sendmsgToServerc             G   s   |j |f|žŽ }|  |¡ |S )N)rý  ÚregisterRecvmsgResult)r2   r(   rN   r?   Úresultr   r   r   Ú	doRecvmsg		  s    
zSendrecvmsgBase.doRecvmsgc             C   s   d S )Nr   )r2   r6  r   r   r   r5  	  s    z%SendrecvmsgBase.registerRecvmsgResultc             C   s   |   ||¡ d S )N)r’   )r2   Úaddr1Úaddr2r   r   r   ÚcheckRecvmsgAddress	  s    z#SendrecvmsgBase.checkRecvmsgAddressr   )Ú
MSG_CTRUNCZMSG_OOBNc       
      C   s¬   | j }| j}|r&|| jO }|| jO }n|d k	rB|| jO }|| jO }|| M }|| M }||O }||O }||@ | @ }|r†td |¡ƒ‚||B | @ }	|  ||	@ ||	@ ¡ d S )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Ú	ExceptionrÒ   r’   )
r2   r_  ÚeorÚchecksetÚ
checkunsetÚignoreZ
defaultsetZdefaultunsetZinbothr  r   r   r   Ú
checkFlags.	  s$    




zSendrecvmsgBase.checkFlags)Nr   r   r   )r5   r6   r7   Úfail_timeoutr3   r2  r3  r4  r7  r5  r:  r=  rÊ   rh   r	   r<  r>  r?  rE  rE   r   r   )rA   r   r/  î  s   

r/  c               @   s   e Zd Zdd„ ZdS )ÚRecvmsgIntoMixinc             G   sf   t |ƒ}|j|gf|žŽ }|  |¡ |  |d d¡ |  |d |¡ t|d |d … ƒf|dd …  S )Nr   r[   )rD  Úrecvmsg_intor5  ÚassertGreaterEqualÚassertLessEqualrí  )r2   r(   rN   r?   Úbufr6  r   r   r   r7  h	  s    
zRecvmsgIntoMixin.doRecvmsgN)r5   r6   r7   r7  r   r   r   r   rG  e	  s   rG  c                   s    e Zd Ze‡ fdd„ƒZ‡  ZS )ÚSendrecvmsgDgramFlagsBasec                s   t ƒ jtjB S )N)r:   r?  r	   Ú	MSG_TRUNC)r2   )rA   r   r   r?  t	  s    z5SendrecvmsgDgramFlagsBase.msg_flags_non_eor_indicator)r5   r6   r7   Úpropertyr?  rE   r   r   )rA   r   rL  q	  s   rL  c                   s    e Zd Ze‡ fdd„ƒZ‡  ZS )ÚSendrecvmsgSCTPFlagsBasec                s   t ƒ jtjB S )N)r:   r>  r	   ZMSG_EOR)r2   )rA   r   r   r>  |	  s    z0SendrecvmsgSCTPFlagsBase.msg_flags_eor_indicator)r5   r6   r7   rN  r>  rE   r   r   )rA   r   rO  y	  s   rO  c               @   s8   e Zd Zedd„ ƒZedd„ ƒZedd„ ƒZdd„ Zd	S )
ÚSendrecvmsgConnectionlessBasec             C   s   | j S )N)r.   )r2   r   r   r   Ú	serv_sock†	  s    z'SendrecvmsgConnectionlessBase.serv_sockc             C   s   | j S )N)r}   )r2   r   r   r   r1  Š	  s    z&SendrecvmsgConnectionlessBase.cli_sockc             C   s   g g d| j fS )Nr   )r¢   )r2   r   r   r   r3  Ž	  s    z8SendrecvmsgConnectionlessBase.sendmsg_to_server_defaultsc             C   s   | j  || j¡S )N)r1  rî   r¢   )r2   r”   r   r   r   r2  ’	  s    z*SendrecvmsgConnectionlessBase.sendToServerN)r5   r6   r7   rN  rQ  r1  r3  r2  r   r   r   r   rP  	  s   rP  c               @   s,   e Zd Zedd„ ƒZedd„ ƒZdd„ ZdS )ÚSendrecvmsgConnectedBasec             C   s   | j S )N)r™   )r2   r   r   r   rQ  œ	  s    z"SendrecvmsgConnectedBase.serv_sockc             C   s   | j S )N)r›   )r2   r   r   r   r1   	  s    z!SendrecvmsgConnectedBase.cli_sockc             C   s   d S )Nr   )r2   r8  r9  r   r   r   r:  ¤	  s    z,SendrecvmsgConnectedBase.checkRecvmsgAddressN)r5   r6   r7   rN  rQ  r1  r:  r   r   r   r   rR  –	  s   rR  c                   s   e Zd Z‡ fdd„Z‡  ZS )ÚSendrecvmsgServerTimeoutBasec                s   t ƒ  ¡  | j | j¡ d S )N)r:   r3   rQ  rO  rF  )r2   )rA   r   r   r3   ­	  s    
z"SendrecvmsgServerTimeoutBase.setUp)r5   r6   r7   r3   rE   r   r   )rA   r   rS  ª	  s   rS  c               @   s¼   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zeedƒdd„ ƒZejd d!„ ƒZd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*S )+ÚSendmsgTestsc             C   s   |   | j ttƒ¡t¡ d S )N)r’   rQ  r‘   rb  r“   )r2   r   r   r   ÚtestSendmsg¶	  s    zSendmsgTests.testSendmsgc             C   s   |   |  tg¡ttƒ¡ d S )N)r’   r4  r“   rb  )r2   r   r   r   Ú_testSendmsgº	  s    zSendmsgTests._testSendmsgc             C   s   |   | j ttƒ¡t¡ d S )N)r’   rQ  r‘   rb  r“   )r2   r   r   r   ÚtestSendmsgDataGenerator½	  s    z%SendmsgTests.testSendmsgDataGeneratorc             C   s&   |   |  dd„ tgD ƒ¡ttƒ¡ d S )Nc             s   s   | ]
}|V  qd S )Nr   )rÉ   rÑ   r   r   r   rÌ   Â	  s    z9SendmsgTests._testSendmsgDataGenerator.<locals>.<genexpr>)r’   r4  r“   rb  )r2   r   r   r   Ú_testSendmsgDataGeneratorÁ	  s    z&SendmsgTests._testSendmsgDataGeneratorc             C   s   |   | j ttƒ¡t¡ d S )N)r’   rQ  r‘   rb  r“   )r2   r   r   r   ÚtestSendmsgAncillaryGeneratorÅ	  s    z*SendmsgTests.testSendmsgAncillaryGeneratorc             C   s(   |   |  tgdd„ dD ƒ¡ttƒ¡ d S )Nc             s   s   | ]
}|V  qd S )Nr   )rÉ   rÑ   r   r   r   rÌ   Ê	  s    z>SendmsgTests._testSendmsgAncillaryGenerator.<locals>.<genexpr>r   )r’   r4  r“   rb  )r2   r   r   r   Ú_testSendmsgAncillaryGeneratorÉ	  s    z+SendmsgTests._testSendmsgAncillaryGeneratorc             C   s   |   | j ttƒ¡t¡ d S )N)r’   rQ  r‘   rb  r“   )r2   r   r   r   ÚtestSendmsgArrayÍ	  s    zSendmsgTests.testSendmsgArrayc             C   s$   |   |  t dt¡g¡ttƒ¡ d S )NÚB)r’   r4  Úarrayr“   rb  )r2   r   r   r   Ú_testSendmsgArrayÑ	  s    zSendmsgTests._testSendmsgArrayc             C   s   |   | j ttƒ¡t¡ d S )N)r’   rQ  r‘   rb  r“   )r2   r   r   r   ÚtestSendmsgGatherÕ	  s    zSendmsgTests.testSendmsgGatherc             C   s.   |   |  td d… tdd … g¡ttƒ¡ d S )Nr  )r’   r4  r“   rb  )r2   r   r   r   Ú_testSendmsgGatherÙ	  s    zSendmsgTests._testSendmsgGatherc             C   s   |   | j d¡d¡ d S )Niè  s   done)r’   rQ  r‘   )r2   r   r   r   ÚtestSendmsgBadArgsÜ	  s    zSendmsgTests.testSendmsgBadArgsc             C   s²   |   t| jj¡ |   t| jd¡ |   t| jtƒ ¡ |   t| jtƒ g¡ |   t| jttƒ g¡ |   t| jtgtƒ ¡ |   t| jtgg tƒ ¡ |   t| jtgg dtƒ ¡ |  d¡ d S )Ns   not in an iterabler   s   done)rç   rv   r1  r   r4  Úobjectr“   r2  )r2   r   r   r   Ú_testSendmsgBadArgsà	  s     







z SendmsgTests._testSendmsgBadArgsc             C   s   |   | j d¡d¡ d S )Niè  s   done)r’   rQ  r‘   )r2   r   r   r   ÚtestSendmsgBadCmsgò	  s    zSendmsgTests.testSendmsgBadCmsgc             C   s¬   |   t| jtgtƒ g¡ |   t| jtgtƒ ddfg¡ |   t| jtgdtƒ dfg¡ |   t| jtgddtƒ fg¡ |   t| jtgdg¡ |   t| jtgdg¡ |  d¡ d S )Nr   s   data)r   r   )r   r   s   datar   s   done)rç   rv   r4  r“   rb  r2  )r2   r   r   r   Ú_testSendmsgBadCmsgö	  s    





z SendmsgTests._testSendmsgBadCmsgÚ
CMSG_SPACEc             C   s   |   | j d¡d¡ d S )Niè  s   done)r’   rQ  r‘   )r2   r   r   r   ÚtestSendmsgBadMultiCmsg
  s    z$SendmsgTests.testSendmsgBadMultiCmsgc             C   sB   |   t| jtgdddg¡ |   t| jtgdtƒ g¡ |  d¡ d S )Nr   r¿   )r   r   r¿   s   done)rç   rv   r4  r“   rb  r2  )r2   r   r   r   Ú_testSendmsgBadMultiCmsg
  s
    

z%SendmsgTests._testSendmsgBadMultiCmsgc             C   s   |   | j d¡d¡ d S )Niè  s   done)r’   rQ  r‘   )r2   r   r   r   ÚtestSendmsgExcessCmsgReject
  s    z(SendmsgTests.testSendmsgExcessCmsgRejectc          	   C   sN   t tdƒs@|  t¡}|  tgddg¡ W d Q R X |  |jj¡ |  	d¡ d S )Nrf  )r   r   r¿   s   done)
ru   r	   rç   r   r4  r“   ÚassertIsNonerï   r   r2  )r2   rð   r   r   r   Ú_testSendmsgExcessCmsgReject
  s
    
z)SendmsgTests._testSendmsgExcessCmsgRejectc             C   s   d S )Nr   )r2   r   r   r   ÚtestSendmsgAfterClose 
  s    z"SendmsgTests.testSendmsgAfterClosec             C   s    | j  ¡  |  t| jtg¡ d S )N)r1  r   rç   r   r4  r“   )r2   r   r   r   Ú_testSendmsgAfterClose$
  s    
z#SendmsgTests._testSendmsgAfterCloseN)r5   r6   r7   rU  rV  rW  rX  rY  rZ  r[  r^  r_  r`  ra  rc  rd  re  rÏ   r	   rg  rÃ   rh  ri  rk  rl  rm  r   r   r   r   rT  ²	  s(   rT  c               @   sR   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zeej	d	kd
ƒdd„ ƒZ
e
jdd„ ƒZdS )ÚSendmsgStreamTestsc             C   s   |   | j ttƒ¡t¡ d S )N)r’   rQ  r‘   rb  r“   )r2   r   r   r   ÚtestSendmsgExplicitNoneAddr-
  s    z.SendmsgStreamTests.testSendmsgExplicitNoneAddrc             C   s"   |   |  tgg dd ¡ttƒ¡ d S )Nr   )r’   r4  r“   rb  )r2   r   r   r   Ú_testSendmsgExplicitNoneAddr1
  s    z/SendmsgStreamTests._testSendmsgExplicitNoneAddrc             C   s.   |   | j d¡d¡ |  | jj| jd¡ d S )Ni   s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rv  )r’   rQ  r‘   r×   r0  rl   rF  )r2   r   r   r   ÚtestSendmsgTimeout4
  s    z%SendmsgStreamTests.testSendmsgTimeoutc          
   C   sˆ   zv| j  d¡ yx|  dg¡ qW W nD tjk
r:   Y n: tk
rh } z|jtjkrX‚ W d d }~X Y nX |  d¡ W d | j	 
¡  X d S )Ng¸…ëQ¸ž?s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaazsocket.timeout not raised)r1  rO  r4  r	   rv  r   r   ÚENOMEMrä   r0  rY   )r2   ro   r   r   r   Ú_testSendmsgTimeout9
  s    z&SendmsgStreamTests._testSendmsgTimeout>   r%  z<MSG_DONTWAIT not known to work on this platform when sendingc             C   s.   |   | j d¡d¡ |  | jj| jd¡ d S )Ni   s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rv  )r’   rQ  r‘   r×   r0  rl   rF  )r2   r   r   r   ÚtestSendmsgDontWaitP
  s    z&SendmsgStreamTests.testSendmsgDontWaitc          	   C   s`   zN|   t¡}x|  dgg tj¡ qW W d Q R X |  |jjtjtj	tj
f¡ W d | j ¡  X d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rç   r   r4  r	   ZMSG_DONTWAITrÚ   rï   r   ZEAGAINZEWOULDBLOCKrr  r0  rY   )r2   rð   r   r   r   Ú_testSendmsgDontWaitX
  s     
z'SendmsgStreamTests._testSendmsgDontWaitN)r5   r6   r7   ro  rp  rq  rs  rÈ   r  r+  rt  rÃ   ru  r   r   r   r   rn  )
  s   
rn  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚSendmsgConnectionlessTestsc             C   s   d S )Nr   )r2   r   r   r   ÚtestSendmsgNoDestAddrk
  s    z0SendmsgConnectionlessTests.testSendmsgNoDestAddrc             C   s2   |   t| jjtg¡ |   t| jjtgg dd ¡ d S )Nr   )rç   r   r1  r   r“   )r2   r   r   r   Ú_testSendmsgNoDestAddrp
  s    z1SendmsgConnectionlessTests._testSendmsgNoDestAddrN)r5   r6   r7   rw  rx  r   r   r   r   rv  f
  s   rv  c               @   sÎ   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zeed!ƒd"d#„ ƒZejd$d%„ ƒZeejd&ƒd'd(„ ƒZejd)d*„ ƒZd+S ),ÚRecvmsgGenericTestsc             C   sR   |   | jttƒ¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j|dd d S )NT)rA  )r7  rQ  rb  r“   r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsg{
  s
    zRecvmsgGenericTests.testRecvmsgc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgƒ
  s    z RecvmsgGenericTests._testRecvmsgc             C   sV   |   | jttƒdd¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j|dd d S )Nr   T)rA  )r7  rQ  rb  r“   r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgExplicitDefaults†
  s    z/RecvmsgGenericTests.testRecvmsgExplicitDefaultsc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgExplicitDefaults
  s    z0RecvmsgGenericTests._testRecvmsgExplicitDefaultsc             C   sV   |   | jttƒd ¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j|dd d S )Nr   T)rA  )r7  rQ  rb  r“   r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgShorter’
  s    z&RecvmsgGenericTests.testRecvmsgShorterc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgShorter›
  s    z'RecvmsgGenericTests._testRecvmsgShorterc             C   s^   |   | jttƒd ¡\}}}}|  |td d… ¡ |  || j¡ |  |g ¡ | j|dd d S )Nr  éýÿÿÿF)rA  )r7  rQ  rb  r“   r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgTruncž
  s    z$RecvmsgGenericTests.testRecvmsgTruncc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgTrunc§
  s    z%RecvmsgGenericTests._testRecvmsgTruncc             C   sT   |   | jttƒd¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j|dd d S )Nr[   T)rA  )r7  rQ  rb  r“   r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgShortAncillaryBufª
  s    z0RecvmsgGenericTests.testRecvmsgShortAncillaryBufc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgShortAncillaryBuf³
  s    z1RecvmsgGenericTests._testRecvmsgShortAncillaryBufc             C   sT   |   | jttƒd¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j|dd d S )Ni (  T)rA  )r7  rQ  rb  r“   r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgLongAncillaryBuf¶
  s    z/RecvmsgGenericTests.testRecvmsgLongAncillaryBufc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgLongAncillaryBuf¿
  s    z0RecvmsgGenericTests._testRecvmsgLongAncillaryBufc             C   s"   | j  ¡  |  t| j| j d¡ d S )Ni   )rQ  r   rç   r   r7  )r2   r   r   r   ÚtestRecvmsgAfterCloseÂ
  s    
z)RecvmsgGenericTests.testRecvmsgAfterClosec             C   s   d S )Nr   )r2   r   r   r   Ú_testRecvmsgAfterCloseÇ
  s    z*RecvmsgGenericTests._testRecvmsgAfterClosec             C   s<   z*| j  d¡ |  tj| j| j ttƒ¡ W d | j 	¡  X d S )Ng¸…ëQ¸ž?)
rQ  rO  rç   r	   rv  r7  rb  r“   r0  rY   )r2   r   r   r   ÚtestRecvmsgTimeoutÊ
  s
    z&RecvmsgGenericTests.testRecvmsgTimeoutc             C   s   |   | jj| jd¡ d S )N)rv  )r×   r0  rl   rF  )r2   r   r   r   Ú_testRecvmsgTimeoutÓ
  s    z'RecvmsgGenericTests._testRecvmsgTimeoutrú  c             C   s  |   | jttƒd dtj¡\}}}}|  |td d… ¡ |  || j¡ |  |g ¡ | j	|dt
tddƒd |   | jttƒdtj¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j	|dd |   | jttƒ¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j	|dd d S )	Nr  r   r€  FrM  )rA  rD  T)rA  )r7  rQ  rb  r“   r	   rú  r’   r:  rƒ   rE  rh   )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgPeekÖ
  s(    z#RecvmsgGenericTests.testRecvmsgPeekc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgPeekù
  s    z$RecvmsgGenericTests._testRecvmsgPeekr   c             C   s`   | j  | j¡ |  | j ttƒ¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j	|dd d S )NT)rA  )
rQ  rO  rF  r7  rb  r“   r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgFromSendmsgý
  s    z*RecvmsgGenericTests.testRecvmsgFromSendmsgc             C   s.   |   |  td d… tdd … g¡ttƒ¡ d S )Nr  )r’   r4  r“   rb  )r2   r   r   r   Ú_testRecvmsgFromSendmsg  s    z+RecvmsgGenericTests._testRecvmsgFromSendmsgN)r5   r6   r7   rz  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   ry  w
  s(   						#ry  c               @   s,   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	S )
ÚRecvmsgGenericStreamTestsc             C   sN   |   | jd¡\}}}}|  |d¡ |  || j¡ |  |g ¡ | j|d d d S )Ni   r¿   )rA  )r7  rQ  r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgEOF  s
    z(RecvmsgGenericStreamTests.testRecvmsgEOFc             C   s   | j  ¡  d S )N)r1  r   )r2   r   r   r   Ú_testRecvmsgEOF  s    z)RecvmsgGenericStreamTests._testRecvmsgEOFc             C   sœ   |   | jttƒd ¡\}}}}|  || j¡ |  |g ¡ | j|dd |   | jd¡\}}}}|  || j¡ |  |g ¡ | j|dd || }|  |t¡ d S )Nr  F)rA  i   T)r7  rQ  rb  r“   r:  rƒ   r’   rE  )r2   r  rþ  r_  rš   r  r”   r   r   r   ÚtestRecvmsgOverflow  s    z-RecvmsgGenericStreamTests.testRecvmsgOverflowc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgOverflow,  s    z.RecvmsgGenericStreamTests._testRecvmsgOverflowN)r5   r6   r7   r  r‘  r’  r“  r   r   r   r   r    s   r  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚRecvmsgTestsc             C   s   |   t| jj¡ |   t| jjddd¡ |   t| jjttƒdd¡ |   t| jjtdƒgdd¡ |   t| jjtƒ dd¡ |   t| jjttƒtƒ d¡ |   t| jjttƒdtƒ ¡ | j ttƒdd¡\}}}}|  	|t¡ |  
|| j¡ |  	|g ¡ | j|dd d S )Nr  r   r/  T)rA  )rç   rv   rQ  rý  r3  rb  r“   rD  rb  r’   r:  rƒ   rE  )r2   r”   rþ  r_  rš   r   r   r   ÚtestRecvmsgBadArgs3  s$    
zRecvmsgTests.testRecvmsgBadArgsc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgBadArgsI  s    z RecvmsgTests._testRecvmsgBadArgsN)r5   r6   r7   r•  r–  r   r   r   r   r”  0  s   r”  c               @   sL   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚRecvmsgIntoTestsc             C   sL  t ttƒƒ}|  t| jj¡ |  t| jjttƒdd¡ |  t| jj|dd¡ |  t| jjtƒ gdd¡ |  t| jjdgdd¡ |  t| jj|tƒ gdd¡ |  t| jj|gdd¡ |  t| jj|gtƒ d¡ |  t| jj|gdtƒ ¡ | j |gdd¡\}}}}|  	|ttƒ¡ |  	|t tƒ¡ |  
|| j¡ |  	|g ¡ | j|dd d S )Nr   s   I'm not writabler  T)rA  )rD  rb  r“   rç   rv   rQ  rH  rb  r3  r’   r:  rƒ   rE  )r2   rK  Únbytesrþ  r_  rš   r   r   r   ÚtestRecvmsgIntoBadArgsP  s0    
z'RecvmsgIntoTests.testRecvmsgIntoBadArgsc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgIntoBadArgsl  s    z(RecvmsgIntoTests._testRecvmsgIntoBadArgsc             C   sx   t ttƒƒ}| j dd„ |gD ƒ¡\}}}}|  |ttƒ¡ |  |t tƒ¡ |  || j¡ |  |g ¡ | j|dd d S )Nc             s   s   | ]
}|V  qd S )Nr   )rÉ   rÑ   r   r   r   rÌ   s  s    z<RecvmsgIntoTests.testRecvmsgIntoGenerator.<locals>.<genexpr>T)rA  )	rD  rb  r“   rQ  rH  r’   r:  rƒ   rE  )r2   rK  r˜  rþ  r_  rš   r   r   r   ÚtestRecvmsgIntoGeneratoro  s    z)RecvmsgIntoTests.testRecvmsgIntoGeneratorc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgIntoGeneratorz  s    z*RecvmsgIntoTests._testRecvmsgIntoGeneratorc             C   sx   t   ddgttƒ ¡}| j |g¡\}}}}|  |ttƒ¡ |  | ¡ t¡ |  || j¡ |  |g ¡ | j	|dd d S )Nr\  r   T)rA  )
r]  rb  r“   rQ  rH  r’   Útobytesr:  rƒ   rE  )r2   rK  r˜  rþ  r_  rš   r   r   r   ÚtestRecvmsgIntoArray}  s    z%RecvmsgIntoTests.testRecvmsgIntoArrayc             C   s   |   t¡ d S )N)r2  r“   )r2   r   r   r   Ú_testRecvmsgIntoArray‡  s    z&RecvmsgIntoTests._testRecvmsgIntoArrayc             C   sª   t dƒ}t dƒ}t dƒ}| j |t|ƒdd… |g¡\}}}}|  |tdƒ¡ |  |t dƒ¡ |  |t dƒ¡ |  |t d	ƒ¡ |  || j¡ |  |g ¡ | j|d
d d S )Ns   ----s
   0123456789s   --------------r„   é	   s   Mary had a little lambs   Marys
   01 had a 9s   little lamb---T)rA  )	rD  rQ  rH  Ú
memoryviewr’   rb  r:  rƒ   rE  )r2   Zb1Zb2Zb3r˜  rþ  r_  rš   r   r   r   ÚtestRecvmsgIntoScatterŠ  s     z'RecvmsgIntoTests.testRecvmsgIntoScatterc             C   s   |   d¡ d S )Ns   Mary had a little lamb)r2  )r2   r   r   r   Ú_testRecvmsgIntoScatter™  s    z(RecvmsgIntoTests._testRecvmsgIntoScatterN)r5   r6   r7   r™  rš  r›  rœ  rž  rŸ  r¢  r£  r   r   r   r   r—  M  s   
r—  c               @   sb   e Zd ZyddlZW n ek
r,   dZY nX edejƒZee	dƒdd„ ƒZ
ee	dƒdd	„ ƒZdS )
ÚCmsgMacroTestsr   NiÿÿÿÚCMSG_LENc             C   sÂ   | j t d¡ d }ttdƒƒtt|d |ƒƒ }|  t d¡t d¡jd ¡ x:|D ]2}t |¡}|  |t d¡ |¡ |  	|| j ¡ qVW |  
ttjd¡ |  
ttj|¡ |  
ttjtj¡ d S )Nr   r[   i  r*   r„   r  )Úsocklen_t_limitr	   r¥  Úlistr‘  r  r]  Úitemsizer’   rJ  rç   r  r  Úmaxsize)r2   Útoobigr°  Únr"   r   r   r   ÚtestCMSG_LENª  s    

zCmsgMacroTests.testCMSG_LENrf  c             C   sè   | j t d¡ d }ttdƒƒtt|d |ƒƒ }t d¡}|  |t d¡jd ¡ x\|D ]T}t |¡}|  ||¡ |  |t 	|¡¡ |  ||t 	d¡ ¡ |  
|| j ¡ |}qZW |  ttjd¡ |  ttj|¡ |  ttjtj¡ d S )Nr[   i  r   r*   r„   r  )r¦  r	   rf  r§  r‘  r  r]  r¨  rI  r¥  rJ  rç   r  r  r©  )r2   rª  r°  Zlastr«  r"   r   r   r   ÚtestCMSG_SPACE¿  s    


zCmsgMacroTests.testCMSG_SPACE)r5   r6   r7   r  r?  r¦  Úminr   rÏ   r	   r¬  r­  r   r   r   r   r¤    s   
r¤  c               @   sh  e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdedd„Z	dd„ Z
dd„ Zdd„ Zdd„ Zeedƒdd„ ƒZejdd„ ƒZdd„ Zdd „ Ze ejd!kd"¡e ej d#¡d$¡eedƒd%d&„ ƒƒƒZeje ejd!kd"¡e ej d#¡d$¡d'd(„ ƒƒƒZe ejd!kd"¡e ej d#¡d$¡eedƒd)d*„ ƒƒƒZeje ejd!kd"¡e ej d#¡d$¡d+d,„ ƒƒƒZd-d.„ Ze ejd!kd/¡d0d1„ ƒZd2d3„ Z d4d5„ Z!d6d7„ Z"eedƒd8d9„ ƒZ#e#jd:d;„ ƒZ$dfd<d=„Z%d>d?„ Z&d@dA„ Z'dBdC„ Z(dDdE„ Z)dFdG„ Z*dHdI„ Z+dJdK„ Z,dLdM„ Z-dNdO„ Z.dPdQ„ Z/dgdRdS„Z0dTdU„ Z1dVdW„ Z2dXdY„ Z3dZd[„ Z4d\d]„ Z5d^d_„ Z6d`da„ Z7dbdc„ Z8ddS )hÚSCMRightsTesti«ªÿÿc             C   s`   g }xVt |ƒD ]J}t ¡ \}}|  tj|¡ |  tj|¡ t |t|ƒ 	¡ ¡ | 
|¡ qW |S )N)r‘  r©   r­  rB   r&   r¯   r   ÚwriterÐ   ÚencodeÚappend)r2   r«  Úfdsr*   r±  r°   r   r   r   ÚnewFDsà  s    zSCMRightsTest.newFDsc             C   sF   x@t |ƒD ]4\}}t |dtj¡ |  t |d¡t|ƒ ¡ ¡ q
W d S )Nr   i   )Ú	enumerater&   ÚlseekÚSEEK_SETr’   r  rÐ   r±  )r2   r³  r«  r±  r   r   r   ÚcheckFDsì  s    zSCMRightsTest.checkFDsc             C   s   |   | j|¡ d S )N)rB   ÚcloseRecvmsgFDs)r2   r6  r   r   r   r5  ó  s    z#SCMRightsTest.registerRecvmsgResultc             C   sv   xp|d D ]d\}}}|t jkr
|t jkr
t d¡}| |d t|ƒt|ƒ|j  … ¡ x|D ]}t |¡ q\W q
W d S )Nr[   r*   )	r	   ró   Ú
SCM_RIGHTSr]  Ú	frombytesrb  r¨  r&   r   )r2   Zrecvmsg_resultÚ
cmsg_levelÚ	cmsg_typeÚ	cmsg_datar³  r±  r   r   r   r¹  ö  s    



zSCMRightsTest.closeRecvmsgFDsc             C   s8   |   |  tgtjtjt d|  |¡¡fg¡ttƒ¡ d S )Nr*   )	r’   r4  r“   r	   ró   rº  r]  r´  rb  )r2   r«  r   r   r   ÚcreateAndSendFDs  s    zSCMRightsTest.createAndSendFDsr[   r   c             C   sè   |\}}}}|   |t¡ |  || j¡ | j|dtj|d |  |t¡ |  	t
|ƒ|¡ t d¡}	xh|D ]`}
|  |
t¡ |
\}}}|   |tj¡ |   |tj¡ |  |t¡ |   t
|ƒt d¡ |	 |¡ qfW |   t
|	ƒ|¡ |  |	¡ d S )NT)rA  rC  rD  r*   r   )r’   r“   r:  rƒ   rE  r	   r;  rØ   r§  rJ  rb  r]  Útupleró   rº  rí  Ú
SIZEOF_INTr»  r¸  )r2   Znumfdsr6  ÚmaxcmsgsÚignoreflagsr”   rþ  r_  rš   r³  Úitemr¼  r½  r¾  r   r   r   ÚcheckRecvmsgFDs  s$    


zSCMRightsTest.checkRecvmsgFDsc             C   s    |   d|  | jttƒd¡¡ d S )Nr[   i (  )rÅ  r7  rQ  rb  r“   )r2   r   r   r   ÚtestFDPassSimple'  s    zSCMRightsTest.testFDPassSimplec             C   s<   |   |  tgtjtjt d|  d¡¡ ¡ fg¡t	tƒ¡ d S )Nr*   r[   )
r’   r4  r“   r	   ró   rº  r]  r´  r  rb  )r2   r   r   r   Ú_testFDPassSimple,  s    zSCMRightsTest._testFDPassSimplec             C   s    |   d|  | jttƒd¡¡ d S )Nrí   i (  )rÅ  r7  rQ  rb  r“   )r2   r   r   r   ÚtestMultipleFDPass5  s    z SCMRightsTest.testMultipleFDPassc             C   s   |   d¡ d S )Nrí   )r¿  )r2   r   r   r   Ú_testMultipleFDPass:  s    z!SCMRightsTest._testMultipleFDPassrf  c             C   s*   |   d|  | jttƒt dt ¡¡¡ d S )Nrí   )rÅ  r7  rQ  rb  r“   r	   rf  rÁ  )r2   r   r   r   ÚtestFDPassCMSG_SPACE=  s    z"SCMRightsTest.testFDPassCMSG_SPACEc             C   s   |   d¡ d S )Nrí   )r¿  )r2   r   r   r   Ú_testFDPassCMSG_SPACED  s    z#SCMRightsTest._testFDPassCMSG_SPACEc          
   C   s0   | j d|  | jttƒt dt ¡¡tjd d S )Nr[   rí   )rÃ  )	rÅ  r7  rQ  rb  r“   r	   r¥  rÁ  r;  )r2   r   r   r   ÚtestFDPassCMSG_LENH  s    z SCMRightsTest.testFDPassCMSG_LENc             C   s   |   d¡ d S )Nr[   )r¿  )r2   r   r   r   Ú_testFDPassCMSG_LENR  s    z!SCMRightsTest._testFDPassCMSG_LENr&  zskipping, see issue #12958r9  zskipping, see issue #22397c             C   s$   | j d|  | jttƒd¡dd d S )Nr„   i (  )rÂ  )rÅ  r7  rQ  rb  r“   )r2   r   r   r   ÚtestFDPassSeparateU  s    z SCMRightsTest.testFDPassSeparatec             C   sX   |   d¡\}}|  |  tgtjtjt d|g¡ftjtjt d|g¡fg¡ttƒ¡ d S )Nr„   r*   )	r´  r’   r4  r“   r	   ró   rº  r]  rb  )r2   Úfd0Úfd1r   r   r   Ú_testFDPassSeparate_  s    z!SCMRightsTest._testFDPassSeparatec             C   s@   d}| j ||  | jttƒt t¡t t| ¡ ¡dtj	d d S )Nr„   )rÂ  rÃ  )
rÅ  r7  rQ  rb  r“   r	   rf  rÁ  r¥  r;  )r2   Znum_fdsr   r   r   ÚtestFDPassSeparateMinSpacem  s    z(SCMRightsTest.testFDPassSeparateMinSpacec             C   sX   |   d¡\}}|  |  tgtjtjt d|g¡ftjtjt d|g¡fg¡ttƒ¡ d S )Nr„   r*   )	r´  r’   r4  r“   r	   ró   rº  r]  rb  )r2   rÏ  rÐ  r   r   r   Ú_testFDPassSeparateMinSpacez  s    z)SCMRightsTest._testFDPassSeparateMinSpacec          
   C   sd   y|   |g|¡}W n< tk
rN } z|  |jt¡ |   |g¡}W d d }~X Y nX |  |t|ƒ¡ d S )N)r4  r   rØ   r   r  r’   rb  )r2   r”   rþ  r˜  rw   r   r   r   ÚsendAncillaryIfPossibleˆ  s    z%SCMRightsTest.sendAncillaryIfPossiblezsee issue #24725c             C   s&   | j d|  | jttƒd¡tjd d S )Nr   i (  )rÃ  )rÅ  r7  rQ  rb  r“   r	   r;  )r2   r   r   r   ÚtestFDPassEmpty“  s    
zSCMRightsTest.testFDPassEmptyc             C   s   |   ttjtjdfg¡ d S )Nr¿   )rÔ  r“   r	   ró   rº  )r2   r   r   r   Ú_testFDPassEmpty›  s    
zSCMRightsTest._testFDPassEmptyc             C   sœ   |   | jttƒd¡\}}}}|  |t¡ |  || j¡ | j|dtj	d |  
t|ƒd¡ x>|D ]6\}}}|  |tj¡ |  |tj¡ |  t|ƒt¡ q^W d S )Ni (  T)rA  rD  r[   )r7  rQ  rb  r“   r’   r:  rƒ   rE  r	   r;  rJ  ró   rº  Ú
assertLessrÁ  )r2   r”   rþ  r_  rš   r¼  r½  r¾  r   r   r   ÚtestFDPassPartialInt   s    z"SCMRightsTest.testFDPassPartialIntc          	   C   s4   |   ttjtjt d| jg¡ ¡ d d… fg¡ d S )Nr*   r  )rÔ  r“   r	   ró   rº  r]  Úbadfdr  )r2   r   r   r   Ú_testFDPassPartialInt­  s
    z#SCMRightsTest._testFDPassPartialIntc       	      C   sÔ   |   | jttƒd¡\}}}}|  |t¡ |  || j¡ | j|dtj	d |  
t|ƒd¡ t d¡}xR|D ]J\}}}|  |tj¡ |  |tj¡ | |d t|ƒt|ƒ|j  … ¡ qhW |  
t|ƒd¡ |  |¡ d S )Ni (  T)rA  rD  r„   r*   )r7  rQ  rb  r“   r’   r:  rƒ   rE  r	   r;  rJ  r]  ró   rº  r»  r¨  r¸  )	r2   r”   rþ  r_  rš   r³  r¼  r½  r¾  r   r   r   ÚtestFDPassPartialIntInMiddle´  s    
 z*SCMRightsTest.testFDPassPartialIntInMiddlec          
   C   sZ   |   d¡\}}|  ttjtjt d|| jg¡ ¡ d d… ftjtjt d|g¡fg¡ d S )Nr„   r*   r  )	r´  rÔ  r“   r	   ró   rº  r]  rÙ  r  )r2   rÏ  rÐ  r   r   r   Ú_testFDPassPartialIntInMiddleÇ  s    z+SCMRightsTest._testFDPassPartialIntInMiddlec             C   sJ   |\}}}}|   |t¡ |  || j¡ |   |g ¡ | j|dtj|d d S )NT)rA  rB  rD  )r’   r“   r:  rƒ   rE  r	   r;  )r2   r6  rÃ  r”   rþ  r_  rš   r   r   r   ÚcheckTruncatedHeaderÓ  s    z"SCMRightsTest.checkTruncatedHeaderc             C   s"   | j |  | jttƒ¡tjd d S )N)rÃ  )rÝ  r7  rQ  rb  r“   r	   r;  )r2   r   r   r   ÚtestCmsgTruncNoBufSizeÝ  s    z$SCMRightsTest.testCmsgTruncNoBufSizec             C   s   |   d¡ d S )Nr[   )r¿  )r2   r   r   r   Ú_testCmsgTruncNoBufSizeæ  s    z%SCMRightsTest._testCmsgTruncNoBufSizec             C   s$   | j |  | jttƒd¡tjd d S )Nr   )rÃ  )rÝ  r7  rQ  rb  r“   r	   r;  )r2   r   r   r   ÚtestCmsgTrunc0é  s    zSCMRightsTest.testCmsgTrunc0c             C   s   |   d¡ d S )Nr[   )r¿  )r2   r   r   r   Ú_testCmsgTrunc0î  s    zSCMRightsTest._testCmsgTrunc0c             C   s   |   |  | jttƒd¡¡ d S )Nr[   )rÝ  r7  rQ  rb  r“   )r2   r   r   r   ÚtestCmsgTrunc1ô  s    zSCMRightsTest.testCmsgTrunc1c             C   s   |   d¡ d S )Nr[   )r¿  )r2   r   r   r   Ú_testCmsgTrunc1÷  s    zSCMRightsTest._testCmsgTrunc1c             C   s"   |   |  | jttƒtd ¡¡ d S )Nr„   )rÝ  r7  rQ  rb  r“   rÁ  )r2   r   r   r   ÚtestCmsgTrunc2Intú  s    zSCMRightsTest.testCmsgTrunc2Intc             C   s   |   d¡ d S )Nr[   )r¿  )r2   r   r   r   Ú_testCmsgTrunc2Int  s    z SCMRightsTest._testCmsgTrunc2Intc          	   C   s(   |   |  | jttƒt d¡d ¡¡ d S )Nr   r[   )rÝ  r7  rQ  rb  r“   r	   r¥  )r2   r   r   r   ÚtestCmsgTruncLen0Minus1  s    z%SCMRightsTest.testCmsgTruncLen0Minus1c             C   s   |   d¡ d S )Nr[   )r¿  )r2   r   r   r   Ú_testCmsgTruncLen0Minus1  s    z&SCMRightsTest._testCmsgTruncLen0Minus1c             C   sò   |   | jttƒ|¡\}}}}|  |t¡ |  || j¡ | j|dtj	d |dkr\|g kr\d S |  t|ƒd¡ |d \}}	}
|  |tj
¡ |  |	tj¡ |  t|
ƒ|¡ |  t|
ƒ|¡ t d¡}| |
d t|
ƒt|
ƒ|j  … ¡ |  |¡ d S )NT)rA  rB  r   r[   r*   )r7  rQ  rb  r“   r’   r:  rƒ   rE  r	   r;  ró   rº  rI  rJ  r]  r»  r¨  r¸  )r2   ÚancbufÚmaxdataZmindatar”   rþ  r_  rš   r¼  r½  r¾  r³  r   r   r   ÚcheckTruncatedArray  s"    
z!SCMRightsTest.checkTruncatedArrayc             C   s   | j t d¡dd d S )Nr   )rè  ré  )rê  r	   r¥  )r2   r   r   r   ÚtestCmsgTruncLen0&  s    zSCMRightsTest.testCmsgTruncLen0c             C   s   |   d¡ d S )Nr[   )r¿  )r2   r   r   r   Ú_testCmsgTruncLen0)  s    z SCMRightsTest._testCmsgTruncLen0c             C   s   | j t d¡d dd d S )Nr   r[   )rè  ré  )rê  r	   r¥  )r2   r   r   r   ÚtestCmsgTruncLen0Plus1,  s    z$SCMRightsTest.testCmsgTruncLen0Plus1c             C   s   |   d¡ d S )Nr„   )r¿  )r2   r   r   r   Ú_testCmsgTruncLen0Plus1/  s    z%SCMRightsTest._testCmsgTruncLen0Plus1c             C   s   | j t t¡td d S )N)rè  ré  )rê  r	   r¥  rÁ  )r2   r   r   r   ÚtestCmsgTruncLen12  s    zSCMRightsTest.testCmsgTruncLen1c             C   s   |   d¡ d S )Nr„   )r¿  )r2   r   r   r   Ú_testCmsgTruncLen16  s    z SCMRightsTest._testCmsgTruncLen1c             C   s(   | j t dt ¡d dt d d d S )Nr„   r[   )rè  ré  )rê  r	   r¥  rÁ  )r2   r   r   r   ÚtestCmsgTruncLen2Minus19  s    z%SCMRightsTest.testCmsgTruncLen2Minus1c             C   s   |   d¡ d S )Nr„   )r¿  )r2   r   r   r   Ú_testCmsgTruncLen2Minus1=  s    z&SCMRightsTest._testCmsgTruncLen2Minus1N)r[   r   )r   )r   )9r5   r6   r7   rÙ  r´  r¸  r5  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Û  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¯  Ø  sl   

	
  

	
r¯  c               @   s  e Zd ZdZdZdd„ Zd^dd„Zeed	d
ƒdd„ ƒZ	e	j
dd„ ƒZeedd	d
ƒdd„ ƒZej
dd„ ƒZeejdƒeed	d
ƒdd„ ƒƒZej
dd„ ƒZd_dd„Zeed	d
ddƒdd„ ƒZej
dd „ ƒZeedd	d
ddƒd!d"„ ƒZej
d#d$„ ƒZeejdƒeedd	d
ddƒd%d&„ ƒƒZej
d'd(„ ƒZeejdƒeedd	d
ddƒd)d*„ ƒƒZej
d+d,„ ƒZd`d-d.„Zeed	d
ƒd/d0„ ƒZej
d1d2„ ƒZeed	d
ƒd3d4„ ƒZej
d5d6„ ƒZeed	d
ƒd7d8„ ƒZej
d9d:„ ƒZeed	d
ƒd;d<„ ƒZ e j
d=d>„ ƒZ!eed	d
ƒd?d@„ ƒZ"e"j
dAdB„ ƒZ#eed	d
ƒdCdD„ ƒZ$e$j
dEdF„ ƒZ%dadGdH„Z&eedd	d
ddƒdIdJ„ ƒZ'e'j
dKdL„ ƒZ(eedd	d
ddƒdMdN„ ƒZ)e)j
dOdP„ ƒZ*eedd	d
ddƒdQdR„ ƒZ+e+j
dSdT„ ƒZ,eedd	d
ddƒdUdV„ ƒZ-e-j
dWdX„ ƒZ.eedd	d
ddƒdYdZ„ ƒZ/e/j
d[d\„ ƒZ0d]S )bÚRFC3542AncillaryTestr„   r  c             C   s8   i }x.|D ]&\}}}|   ||f|¡ ||||f< q
W |S )N)rÝ   )r2   rþ  Údr¼  r½  r¾  r   r   r   ÚancillaryMappingR  s
    z%RFC3542AncillaryTest.ancillaryMappingrë  r   c             C   s  | j  tjtjd¡ | j ¡  |  | j tt	ƒ|¡\}}}}|  
|t	¡ |  || j¡ | j|dtj|d |  
t|ƒd¡ |  |d t¡ |d \}}	}
|  
|tj¡ |  
|	tj¡ |  |
t¡ |  
t|
ƒt¡ t d¡}| |
¡ |  |d d¡ |  |d |¡ d S )Nr[   T)rA  rC  rD  r   r*   )rQ  rM  r	   ÚIPPROTO_IPV6ÚIPV6_RECVHOPLIMITr0  rY   r7  rb  r“   r’   r:  rƒ   rE  r;  rØ   rÀ  ÚIPV6_HOPLIMITrí  rÁ  r]  r»  rI  rJ  )r2   Ú
ancbufsizeÚmaxhoprÃ  r”   rþ  r_  rš   r¼  r½  r¾  r8  r   r   r   ÚcheckHopLimit\  s(    




z"RFC3542AncillaryTest.checkHopLimitr÷  rø  c             C   s   | j dd d S )Ni (  )rù  )rû  )r2   r   r   r   ÚtestRecvHopLimitx  s    z%RFC3542AncillaryTest.testRecvHopLimitc             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testRecvHopLimit}  s    z&RFC3542AncillaryTest._testRecvHopLimitrf  c             C   s   | j t t¡d d S )N)rù  )rû  r	   rf  rÁ  )r2   r   r   r   ÚtestRecvHopLimitCMSG_SPACE…  s    z/RFC3542AncillaryTest.testRecvHopLimitCMSG_SPACEc             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testRecvHopLimitCMSG_SPACEŠ  s    z0RFC3542AncillaryTest._testRecvHopLimitCMSG_SPACEr   c             C   s   | j d| jd d S )Ni (  )rù  rú  )rû  Ú	hop_limit)r2   r   r   r   ÚtestSetHopLimit”  s    z$RFC3542AncillaryTest.testSetHopLimitc             C   sL   |   | jj| jd¡ |  |  tgtjtj	t
 
d| jg¡fg¡ttƒ¡ d S )N)rv  r*   )r×   r0  rl   rF  r’   r4  r“   r	   rö  rø  r]  r   rb  )r2   r   r   r   Ú_testSetHopLimit›  s    z%RFC3542AncillaryTest._testSetHopLimitc             C   sB  | j  tjtjd¡ | j  tjtjd¡ | j ¡  |  | j t	t
ƒ|¡\}}}}|  |t
¡ |  || j¡ | j|dtj|d |  t	|ƒd¡ |  |¡}|tjtjf }	|  t	|	ƒt¡ t d¡}
|
 |	¡ |  |
d d¡ |  |
d d¡ |tjtjf }|  t	|ƒt¡ t d¡}
|
 |¡ |  |
d d¡ |  |
d |¡ d S )Nr[   T)rA  rC  rD  r„   r*   r   rë  )rQ  rM  r	   rö  r÷  ÚIPV6_RECVTCLASSr0  rY   r7  rb  r“   r’   r:  rƒ   rE  r;  rõ  ÚIPV6_TCLASSrÁ  r]  r»  rI  rJ  rø  )r2   rù  rú  rÃ  r”   rþ  r_  rš   ZancmapZtcdatar8  Zhldatar   r   r   ÚcheckTrafficClassAndHopLimit¤  s2    









z1RFC3542AncillaryTest.checkTrafficClassAndHopLimitr  r  c             C   s   | j dd d S )Ni (  )rù  )r  )r2   r   r   r   ÚtestRecvTrafficClassAndHopLimitÈ  s    z4RFC3542AncillaryTest.testRecvTrafficClassAndHopLimitc             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú _testRecvTrafficClassAndHopLimitÎ  s    z5RFC3542AncillaryTest._testRecvTrafficClassAndHopLimitc             C   s   | j t t¡d d d S )Nr„   )rù  )r  r	   rf  rÁ  )r2   r   r   r   Ú)testRecvTrafficClassAndHopLimitCMSG_SPACEÓ  s    z>RFC3542AncillaryTest.testRecvTrafficClassAndHopLimitCMSG_SPACEc             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú*_testRecvTrafficClassAndHopLimitCMSG_SPACEÛ  s    z?RFC3542AncillaryTest._testRecvTrafficClassAndHopLimitCMSG_SPACEc             C   s   | j d| jd d S )Ni (  )rù  rú  )r  r   )r2   r   r   r   ÚtestSetTrafficClassAndHopLimità  s    z3RFC3542AncillaryTest.testSetTrafficClassAndHopLimitc             C   sd   |   | jj| jd¡ |  |  tgtjtj	t
 
d| jg¡ftjtjt
 
d| jg¡fg¡ttƒ¡ d S )N)rv  r*   )r×   r0  rl   rF  r’   r4  r“   r	   rö  r  r]  Útraffic_classrø  r   rb  )r2   r   r   r   Ú_testSetTrafficClassAndHopLimité  s    z4RFC3542AncillaryTest._testSetTrafficClassAndHopLimitc             C   s   | j d| jd d S )Ni (  )rù  rú  )r  r   )r2   r   r   r   ÚtestOddCmsgSizeô  s    z$RFC3542AncillaryTest.testOddCmsgSizec             C   sä   |   | jj| jd¡ yJ|  tgtjtjt	 	d| j
g¡ ¡ d ftjtjt	 	d| jg¡fg¡}W n~ tk
rÞ } z`|  |jt¡ |  tgtjtjt	 	d| j
g¡ftjtjt	 	d| jg¡fg¡}|  |ttƒ¡ W d d }~X Y nX d S )N)rv  r*   rÕ  )r×   r0  rl   rF  r4  r“   r	   rö  r  r]  r  r  rø  r   r   rØ   r   r  r’   rb  )r2   r˜  rw   r   r   r   Ú_testOddCmsgSizeþ  s"    z%RFC3542AncillaryTest._testOddCmsgSizec             C   sŽ   | j  tjtjd¡ | j ¡  |d kr*dn|f}| j| j tt	ƒf|žŽ \}}}}|  
|t	¡ |  || j¡ |  
|g ¡ | j|dtj|d d S )Nr[   r   T)rA  rB  rD  )rQ  rM  r	   rö  r÷  r0  rY   r7  rb  r“   r’   r:  rƒ   rE  r;  )r2   rù  rÃ  r?   r”   rþ  r_  rš   r   r   r   ÚcheckHopLimitTruncatedHeader  s    


z1RFC3542AncillaryTest.checkHopLimitTruncatedHeaderc             C   s   | j d tjd d S )N)rù  rÃ  )r  r	   r;  )r2   r   r   r   rÞ  (  s    z+RFC3542AncillaryTest.testCmsgTruncNoBufSizec             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   rß  3  s    z,RFC3542AncillaryTest._testCmsgTruncNoBufSizec             C   s   | j dtjd d S )Nr   )rù  rÃ  )r  r	   r;  )r2   r   r   r   ÚtestSingleCmsgTrunc08  s    z)RFC3542AncillaryTest.testSingleCmsgTrunc0c             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSingleCmsgTrunc0?  s    z*RFC3542AncillaryTest._testSingleCmsgTrunc0c             C   s   | j dd d S )Nr[   )rù  )r  )r2   r   r   r   ÚtestSingleCmsgTrunc1G  s    z)RFC3542AncillaryTest.testSingleCmsgTrunc1c             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSingleCmsgTrunc1K  s    z*RFC3542AncillaryTest._testSingleCmsgTrunc1c             C   s   | j dt d d S )Nr„   )rù  )r  rÁ  )r2   r   r   r   ÚtestSingleCmsgTrunc2IntP  s    z,RFC3542AncillaryTest.testSingleCmsgTrunc2Intc             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSingleCmsgTrunc2IntT  s    z-RFC3542AncillaryTest._testSingleCmsgTrunc2Intc             C   s   | j t d¡d d d S )Nr   r[   )rù  )r  r	   r¥  )r2   r   r   r   ÚtestSingleCmsgTruncLen0Minus1Y  s    z2RFC3542AncillaryTest.testSingleCmsgTruncLen0Minus1c             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSingleCmsgTruncLen0Minus1]  s    z3RFC3542AncillaryTest._testSingleCmsgTruncLen0Minus1c             C   sÂ   | j  tjtjd¡ | j ¡  |  | j tt	ƒt 
t¡d ¡\}}}}|  |t	¡ |  || j¡ | j|dtjd |  t|ƒd¡ |r¾|d \}}}|  |tj¡ |  |tj¡ |  t|ƒt¡ d S )Nr[   T)rA  rB  r   )rQ  rM  r	   rö  r÷  r0  rY   r7  rb  r“   r¥  rÁ  r’   r:  rƒ   rE  r;  rJ  rø  r×  )r2   r”   rþ  r_  rš   r¼  r½  r¾  r   r   r   ÚtestSingleCmsgTruncInDatab  s    


"z.RFC3542AncillaryTest.testSingleCmsgTruncInDatac             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSingleCmsgTruncInDatax  s    z/RFC3542AncillaryTest._testSingleCmsgTruncInDatac             C   s  | j  tjtjd¡ | j  tjtjd¡ | j ¡  |  | j t	t
ƒ|¡\}}}}|  |t
¡ |  || j¡ | j|dtj|d |  t	|ƒd¡ |d \}}}	|  |tj¡ |  |tjtjh¡ |  t	|	ƒt¡ t d¡}
|
 |	¡ |  |
d d¡ |  |
d d¡ d S )Nr[   T)rA  rB  rD  r   r*   rë  )rQ  rM  r	   rö  r÷  r  r0  rY   r7  rb  r“   r’   r:  rƒ   rE  r;  rÚ   r  rø  rÁ  r]  r»  rI  rJ  )r2   rù  rÃ  r”   rþ  r_  rš   r¼  r½  r¾  r8  r   r   r   ÚcheckTruncatedSecondHeader}  s(    






z/RFC3542AncillaryTest.checkTruncatedSecondHeaderc             C   s   | j t t¡tjd d S )N)rÃ  )r  r	   rf  rÁ  r;  )r2   r   r   r   ÚtestSecondCmsgTrunc0  s    z)RFC3542AncillaryTest.testSecondCmsgTrunc0c             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSecondCmsgTrunc0£  s    z*RFC3542AncillaryTest._testSecondCmsgTrunc0c             C   s   |   t t¡d ¡ d S )Nr[   )r  r	   rf  rÁ  )r2   r   r   r   ÚtestSecondCmsgTrunc1¨  s    z)RFC3542AncillaryTest.testSecondCmsgTrunc1c             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSecondCmsgTrunc1­  s    z*RFC3542AncillaryTest._testSecondCmsgTrunc1c             C   s   |   t t¡dt  ¡ d S )Nr„   )r  r	   rf  rÁ  )r2   r   r   r   ÚtestSecondCmsgTrunc2Int²  s    z,RFC3542AncillaryTest.testSecondCmsgTrunc2Intc             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSecondCmsgTrunc2Int¸  s    z-RFC3542AncillaryTest._testSecondCmsgTrunc2Intc             C   s"   |   t t¡t d¡ d ¡ d S )Nr   r[   )r  r	   rf  rÁ  r¥  )r2   r   r   r   ÚtestSecondCmsgTruncLen0Minus1½  s    z2RFC3542AncillaryTest.testSecondCmsgTruncLen0Minus1c             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSecondCmsgTruncLen0Minus1Ã  s    z3RFC3542AncillaryTest._testSecondCmsgTruncLen0Minus1c       
      C   sT  | j  tjtjd¡ | j  tjtjd¡ | j ¡  |  | j t	t
ƒt t¡t t¡ d ¡\}}}}|  |t
¡ |  || j¡ | j|dtjd tjtjh}| d¡\}}}|  |tj¡ | |¡ |  t	|ƒt¡ t d¡}	|	 |¡ |  |	d d¡ |  |	d d¡ |rD| d¡\}}}|  |tj¡ | |¡ |  t	|ƒt¡ |  |g ¡ d S )Nr[   T)rA  rB  r   r*   rë  )rQ  rM  r	   rö  r÷  r  r0  rY   r7  rb  r“   rf  rÁ  r¥  r’   r:  rƒ   rE  r;  r  rø  ÚpopÚremover]  r»  rI  rJ  r×  )
r2   r”   rþ  r_  rš   Z
cmsg_typesr¼  r½  r¾  r8  r   r   r   ÚtestSecomdCmsgTruncInDataÈ  s4    





"



z.RFC3542AncillaryTest.testSecomdCmsgTruncInDatac             C   s$   |   | jj| jd¡ |  t¡ d S )N)rv  )r×   r0  rl   rF  r2  r“   )r2   r   r   r   Ú_testSecomdCmsgTruncInDataí  s    z/RFC3542AncillaryTest._testSecomdCmsgTruncInDataN)rë  r   )rë  r   )r   )r   )1r5   r6   r7   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  r  r  r  r  r  r  r  r  r  r  r  r  r   r!  r"  r%  r&  r   r   r   r   ró  A  sp   



	 
#






 




$ró  c               @   s   e Zd ZdS )ÚSendrecvmsgUDPTestBaseN)r5   r6   r7   r   r   r   r   r'  õ  s   r'  r   c               @   s   e Zd ZdS )ÚSendmsgUDPTestN)r5   r6   r7   r   r   r   r   r(  ú  s   r(  rý  c               @   s   e Zd ZdS )ÚRecvmsgUDPTestN)r5   r6   r7   r   r   r   r   r)  þ  s   r)  rH  c               @   s   e Zd ZdS )ÚRecvmsgIntoUDPTestN)r5   r6   r7   r   r   r   r   r*    s   r*  c               @   s   e Zd Zdd„ ZdS )ÚSendrecvmsgUDP6TestBasec             C   s    |   |d d… |d d… ¡ d S )Nr  )r’   )r2   r8  r9  r   r   r   r:    s    z+SendrecvmsgUDP6TestBase.checkRecvmsgAddressN)r5   r6   r7   r:  r   r   r   r   r+    s   r+  zIPv6 required for this test.r¼   r   c               @   s   e Zd ZdS )ÚSendmsgUDP6TestN)r5   r6   r7   r   r   r   r   r,    s   r,  c               @   s   e Zd ZdS )ÚRecvmsgUDP6TestN)r5   r6   r7   r   r   r   r   r-    s   r-  c               @   s   e Zd ZdS )ÚRecvmsgIntoUDP6TestN)r5   r6   r7   r   r   r   r   r.    s   r.  rö  c               @   s   e Zd ZdS )ÚRecvmsgRFC3542AncillaryUDP6TestN)r5   r6   r7   r   r   r   r   r/  "  s   r/  c               @   s   e Zd ZdS )Ú#RecvmsgIntoRFC3542AncillaryUDP6TestN)r5   r6   r7   r   r   r   r   r0  *  s   r0  c               @   s   e Zd ZdS )ÚSendrecvmsgTCPTestBaseN)r5   r6   r7   r   r   r   r   r1  4  s   r1  c               @   s   e Zd ZdS )ÚSendmsgTCPTestN)r5   r6   r7   r   r   r   r   r2  8  s   r2  c               @   s   e Zd ZdS )ÚRecvmsgTCPTestN)r5   r6   r7   r   r   r   r   r3  <  s   r3  c               @   s   e Zd ZdS )ÚRecvmsgIntoTCPTestN)r5   r6   r7   r   r   r   r   r4  A  s   r4  c               @   s   e Zd ZdS )ÚSendrecvmsgSCTPStreamTestBaseN)r5   r6   r7   r   r   r   r   r5  G  s   r5  r,   r-   r¸   c               @   s   e Zd ZdS )ÚSendmsgSCTPStreamTestN)r5   r6   r7   r   r   r   r   r6  L  s   r6  c                   s   e Zd Z‡ fdd„Z‡  ZS )ÚRecvmsgSCTPStreamTestc          
      sR   yt t| ƒ ¡  W n: tk
rL } z|jtjkr2‚ |  d¡ W d d }~X Y nX d S )Nz4sporadic ENOTCONN (kernel issue?) - see issue #13876)r:   r7  r  r   r   ÚENOTCONNrM   )r2   rw   )rA   r   r   r  V  s    z$RecvmsgSCTPStreamTest.testRecvmsgEOF)r5   r6   r7   r  rE   r   r   )rA   r   r7  Q  s   r7  c                   s   e Zd Z‡ fdd„Z‡  ZS )ÚRecvmsgIntoSCTPStreamTestc          
      sR   yt t| ƒ ¡  W n: tk
rL } z|jtjkr2‚ |  d¡ W d d }~X Y nX d S )Nz4sporadic ENOTCONN (kernel issue?) - see issue #13876)r:   r9  r  r   r   r8  rM   )r2   rw   )rA   r   r   r  c  s    z(RecvmsgIntoSCTPStreamTest.testRecvmsgEOF)r5   r6   r7   r  rE   r   r   )rA   r   r9  ^  s   r9  c               @   s   e Zd ZdS )ÚSendrecvmsgUnixStreamTestBaseN)r5   r6   r7   r   r   r   r   r:  l  s   r:  r²   c               @   s   e Zd ZdS )ÚSendmsgUnixStreamTestN)r5   r6   r7   r   r   r   r   r;  p  s   r;  c               @   s   e Zd ZdS )ÚRecvmsgUnixStreamTestN)r5   r6   r7   r   r   r   r   r<  u  s   r<  c               @   s   e Zd ZdS )ÚRecvmsgIntoUnixStreamTestN)r5   r6   r7   r   r   r   r   r=  {  s   r=  ró   rº  c               @   s   e Zd ZdS )ÚRecvmsgSCMRightsStreamTestN)r5   r6   r7   r   r   r   r   r>    s   r>  c               @   s   e Zd ZdS )ÚRecvmsgIntoSCMRightsStreamTestN)r5   r6   r7   r   r   r   r   r?  †  s   r?  c                   sD   e Zd Z‡ fdd„ZdZeedƒr0dZdd„ ZndZd	d„ Z‡  Z	S )
ÚInterruptedTimeoutBasec                s2   t ƒ  ¡  t tjdd„ ¡}|  tjtj|¡ d S )Nc             S   s   dd S )Nr[   r   r   )ZsignumrÛ  r   r   r   r¾   š  r¿   z.InterruptedTimeoutBase.setUp.<locals>.<lambda>)r:   r3   rq  rr  rB   )r2   Zorig_alrm_handler)rA   r   r   r3   —  s    

zInterruptedTimeoutBase.setUpg      @Ú	setitimergš™™™™™©?c             C   s   t  t j|¡ d S )N)rq  rA  ÚITIMER_REAL)r2   Úsecondsr   r   r   ÚsetAlarm¦  s    zInterruptedTimeoutBase.setAlarmr„   c             C   s   t  |¡ d S )N)rq  rk  )r2   rC  r   r   r   rD  ¬  s    )
r5   r6   r7   r3   rv  ru   rq  Ú
alarm_timerD  rE   r   r   )rA   r   r@  ’  s   

r@  Úsiginterruptrk  rA  z+Don't have signal.alarm or signal.setitimerc                   sl   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Ze	e
j
dƒdd„ ƒZe	e
j
dƒdd„ ƒZ‡  ZS )ÚInterruptedRecvTimeoutTestc                s   t ƒ  ¡  | j | j¡ d S )N)r:   r3   r.   rO  rv  )r2   )rA   r   r   r3   ¹  s    
z InterruptedRecvTimeoutTest.setUpc          	   O   sB   z0|   | j¡ |  t¡}|||Ž W d Q R X W d |   d¡ X d S )Nr   )rD  rE  rç   rs  )r2   r  r?   r@   rð   r   r   r   ÚcheckInterruptedRecv½  s
    z/InterruptedRecvTimeoutTest.checkInterruptedRecvc             C   s   |   | jjd¡ d S )Ni   )rH  r.   r‘   )r2   r   r   r   ÚtestInterruptedRecvTimeoutÇ  s    z5InterruptedRecvTimeoutTest.testInterruptedRecvTimeoutc             C   s   |   | jjtdƒ¡ d S )Ni   )rH  r.   Ú	recv_intorD  )r2   r   r   r   ÚtestInterruptedRecvIntoTimeoutÊ  s    z9InterruptedRecvTimeoutTest.testInterruptedRecvIntoTimeoutc             C   s   |   | jjd¡ d S )Ni   )rH  r.   rÝ  )r2   r   r   r   ÚtestInterruptedRecvfromTimeoutÍ  s    z9InterruptedRecvTimeoutTest.testInterruptedRecvfromTimeoutc             C   s   |   | jjtdƒ¡ d S )Ni   )rH  r.   Úrecvfrom_intorD  )r2   r   r   r   Ú"testInterruptedRecvfromIntoTimeoutÐ  s    z=InterruptedRecvTimeoutTest.testInterruptedRecvfromIntoTimeoutrý  c             C   s   |   | jjd¡ d S )Ni   )rH  r.   rý  )r2   r   r   r   ÚtestInterruptedRecvmsgTimeoutÓ  s    z8InterruptedRecvTimeoutTest.testInterruptedRecvmsgTimeoutrH  c             C   s   |   | jjtdƒg¡ d S )Ni   )rH  r.   rH  rD  )r2   r   r   r   Ú!testInterruptedRecvmsgIntoTimeout×  s    z<InterruptedRecvTimeoutTest.testInterruptedRecvmsgIntoTimeout)r5   r6   r7   r3   rH  rI  rK  rL  rN  rÏ   r	   rO  rP  rE   r   r   )rA   r   rG  ²  s   
rG  c                   st   e Zd Z‡ fdd„Zdd„ Zdd„ Ze dd¡d	d
„ ƒZe dd¡dd„ ƒZ	e dd¡e
ejdƒdd„ ƒƒZ‡  ZS )ÚInterruptedSendTimeoutTestc                sp   t ƒ  ¡  |  ¡ | _|  | jj¡ tj| jd}| 	¡  | j
 ¡ \| _}|  | jj¡ | ¡  | j | j¡ d S )N)Útarget)r:   r3   rŸ   r›   rB   r   r<   ZThreadÚ	doConnectÚstartr.   r‹   r™   rÍ   rO  rv  )r2   Z
cli_threadrš   )rA   r   r   r3   ç  s    

z InterruptedSendTimeoutTest.setUpc             C   s   | j  | j¡ d S )N)r›   r   r¢   )r2   r   r   r   rS  õ  s    z$InterruptedSendTimeoutTest.doConnectc          	   O   sH   z6|   t¡"}x|  | j¡ |||Ž qW W d Q R X W d |  d¡ X d S )Nr   )rç   rs  rD  rE  )r2   r  r?   r@   rð   r   r   r   ÚcheckInterruptedSendø  s    z/InterruptedSendTimeoutTest.checkInterruptedSendr/  ræ  c             C   s   |   | jjd¡ d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rU  r›   r–   )r2   r   r   r   ÚtestInterruptedSendTimeout  s    z5InterruptedSendTimeoutTest.testInterruptedSendTimeoutc             C   s   |   | jjd| j¡ d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rU  r›   rî   r¢   )r2   r   r   r   ÚtestInterruptedSendtoTimeout	  s    z7InterruptedSendTimeoutTest.testInterruptedSendtoTimeoutr   c             C   s   |   | jjdg¡ d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rU  r›   r   )r2   r   r   r   ÚtestInterruptedSendmsgTimeout  s    z8InterruptedSendTimeoutTest.testInterruptedSendmsgTimeout)r5   r6   r7   r3   rS  rU  r   Zrequires_mac_verrV  rW  rÏ   r	   rX  rE   r   r   )rA   r   rQ  Þ  s   		
rQ  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTCPCloserTestc             C   sh   | j  ¡ \}}| ¡  | j}t |gg g d¡\}}}|  ||g¡ |  | d¡d¡ | ¡  | ¡  d S )Ng      ð?r[   r¿   )r.   r‹   r   r}   r  r’   r‘   )r2   rŒ   rš   Úsdr  r°  rÓ   r   r   r   Ú	testClose  s    zTCPCloserTest.testClosec             C   s    | j  t| jf¡ t d¡ d S )Ng      ð?)r}   r   r   r0   rŽ   r   )r2   r   r   r   Ú
_testClose'  s    zTCPCloserTest._testCloseN)r5   r6   r7   r[  r\  r   r   r   r   rY    s   rY  c               @   sN   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Zdd„ Z	dd„ Z
dS )ÚBasicSocketPairTestr{   c             C   s   t j| |d d S )N)r|   )rœ   r;   )r2   r|   r   r   r   r;   .  s    zBasicSocketPairTest.__init__c             C   s\   |   |tj¡ ttdƒr*|  |jtj¡ n|  |jtj¡ |  |jtj¡ |  |j	d¡ d S )Nr²   r   )
rØ   r	   ru   r’   rß   r²   r,   rÂ   r-   rà   )r2   r(   r   r   r   Ú_check_defaults1  s    
z#BasicSocketPairTest._check_defaultsc             C   s   |   | j¡ d S )N)r^  r}   )r2   r   r   r   Ú_testDefaults:  s    z!BasicSocketPairTest._testDefaultsc             C   s   |   | j¡ d S )N)r^  r.   )r2   r   r   r   ÚtestDefaults=  s    z BasicSocketPairTest.testDefaultsc             C   s   | j  d¡}|  |t¡ d S )Ni   )r.   r‘   r’   r“   )r2   r”   r   r   r   r  @  s    zBasicSocketPairTest.testRecvc             C   s   | j  t¡ d S )N)r}   r–   r“   )r2   r   r   r   r  D  s    zBasicSocketPairTest._testRecvc             C   s   | j  t¡ d S )N)r.   r–   r“   )r2   r   r   r   ÚtestSendG  s    zBasicSocketPairTest.testSendc             C   s   | j  d¡}|  |t¡ d S )Ni   )r}   r‘   r’   r“   )r2   r”   r   r   r   Ú	_testSendJ  s    zBasicSocketPairTest._testSendN)r{   )r5   r6   r7   r;   r^  r_  r`  r  r  ra  rb  r   r   r   r   r]  ,  s   
	r]  c               @   s®   e Zd Zd$dd„Zdd„ Zdd„ Zejdd	„ ƒZe e¡Z	e
 eed
ƒd¡e ddd¡dd„ ƒƒZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#S )%ÚNonBlockingTCPTestsr{   c             C   s   t  ¡ | _tj| |d d S )N)r|   )r<   r`   Úeventrz   r;   )r2   r|   r   r   r   r;   Q  s    
zNonBlockingTCPTests.__init__c             C   s¸  | j  d¡ |  | j  ¡ ¡ |  | j  ¡ ¡ tr@|  t| j ƒ¡ | j  d¡ |  | j  ¡ d¡ |  	| j  ¡ ¡ tr‚|  	t| j ƒ¡ | j  
d ¡ |  | j  ¡ ¡ tr²|  t| j ƒ¡ | j  
d¡ |  	| j  ¡ ¡ |  | j  ¡ d¡ trô|  	t| j ƒ¡ | j  
d¡ |  | j  ¡ ¡ |  | j  ¡ d¡ tr8|  	t| j ƒ¡ | j  
d¡ |  	| j  ¡ ¡ trj|  	t| j ƒ¡ t ¡ }y| j  ¡  W n tk
r–   Y nX t ¡ }|  || dk d¡ d S )NTFg        r   r/  g      ð?z Error setting non-blocking mode.)r.   rª  rj  r1  r×   Úgetblockingr   r)   r’   rJ  rO  rŽ   r‹   r   )r2   rT  Úendr   r   r   ÚtestSetBlockingU  sF    z#NonBlockingTCPTests.testSetBlockingc             C   s   d S )Nr   )r2   r   r   r   Ú_testSetBlocking‡  s    z$NonBlockingTCPTests._testSetBlockingc             C   sb   dd l }|j|jkr|  d¡ | j d¡ |  | j ¡ d¡ | j |jd ¡ |  | j ¡ ¡ d S )Nr   zneeds UINT_MAX < ULONG_MAXFg        r[   )	r  r%  Z	ULONG_MAXrM   r.   rª  r’   r1  rj  )r2   r  r   r   r   ÚtestSetBlocking_overflowŠ  s    
z,NonBlockingTCPTests.testSetBlocking_overflowr©  ztest needs socket.SOCK_NONBLOCKr„   é   é   c             C   s¨   | j  ¡  t tjtjtjB ¡| _ |  | j  ¡ ¡ |  | j  	¡ d¡ t
 | j ¡| _| j  ¡  t ¡ }y| j  ¡  W n tk
r†   Y nX t ¡ }|  || dk d¡ d S )Nr   g      ð?z&Error creating with non-blocking mode.)r.   r   r	   r,   r-   r©  rJ  re  r’   r1  r   r/   r0   r1   rŽ   r‹   r   r×   )r2   rT  rf  r   r   r   ÚtestInitNonBlocking—  s    

z'NonBlockingTCPTests.testInitNonBlockingc             C   s   d S )Nr   )r2   r   r   r   Ú_testInitNonBlocking¬  s    z(NonBlockingTCPTests._testInitNonBlockingc          	   C   sH   | j  d¡ z | j  ¡ \}}| ttƒ¡}W d | ¡  | j  d ¡ X d S )Nr/  )r.   rO  r‹   r‘   rb  r“   r   )r2   rŒ   rš   Úmessager   r   r   ÚtestInheritFlags¯  s    z$NonBlockingTCPTests.testInheritFlagsc             C   s6   t  d¡ | j t| jf¡ t  d¡ | j t¡ d S )Ngš™™™™™¹?g      à?)rŽ   r   r}   r   r   r0   r–   r“   )r2   r   r   r   Ú_testInheritFlagsº  s    

z%NonBlockingTCPTests._testInheritFlagsc          	   C   s”   | j  d¡ |  t¡ | j  ¡ \}}W d Q R X | j ¡  t | j gg g t¡\}}}| j |krh|  	d¡ | j  ¡ \}}|  
|j¡ |  | ¡ ¡ d S )Nr   z'Error trying to do accept after select.)r.   rª  rç   ÚBlockingIOErrorr‹   rd  rY   r  ÚMAIN_TIMEOUTrä   rB   r   rj  r1  )r2   rŒ   rš   r  r°  rÓ   r   r   r   Ú
testAcceptÀ  s    


zNonBlockingTCPTests.testAcceptc             C   s    | j  ¡  | j t| jf¡ d S )N)rd  rl   r}   r   r   r0   )r2   r   r   r   Ú_testAcceptÓ  s    
zNonBlockingTCPTests._testAcceptc             C   s   | j  ¡ \}}| ¡  d S )N)r.   r‹   r   )r2   rŒ   rš   r   r   r   ÚtestConnectÚ  s    zNonBlockingTCPTests.testConnectc             C   s"   | j  d¡ | j  t| jf¡ d S )Nr/  )r}   rO  r   r   r0   )r2   r   r   r   Ú_testConnectß  s    z NonBlockingTCPTests._testConnectc          	   C   sš   | j  ¡ \}}|  |j¡ | d¡ |  t¡ | tt	ƒ¡}W d Q R X | j
 ¡  t |gg g t¡\}}}||kr||  d¡ | tt	ƒ¡}|  |t	¡ d S )Nr   z0Error during select call to non-blocking socket.)r.   r‹   rB   r   rª  rç   rq  r‘   rb  r“   rd  rY   r  rr  rä   r’   )r2   rŒ   rš   r”   r  r°  rÓ   r   r   r   r  ã  s    


zNonBlockingTCPTests.testRecvc             C   s,   | j  t| jf¡ | j ¡  | j  t¡ d S )N)r}   r   r   r0   rd  rl   rt  r“   )r2   r   r   r   r  ÷  s    
zNonBlockingTCPTests._testRecvN)r{   )r5   r6   r7   r;   rg  rh  r   rÁ  ri  Z_testSetBlocking_overflowr†   rÀ  ru   r	   Úrequires_linux_versionrl  rm  ro  rp  rs  rt  ru  rv  r  r  r   r   r   r   rc  O  s"   
2
rc  c               @   sú   e Zd ZdZdZdZdZdZdZe	Z
dZe	Zd;d	d
„Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd „ Zd!d"„ Zd#d$„ Zd%d&„ Zd'd(„ Zd)d*„ Zd+d,„ Zd-d.„ Zd/d0„ Z d1d2„ Z!d3d4„ Z"d5d6„ Z#d7d8„ Z$d9d:„ Z%dS )<ÚFileObjectClassTestCaseao  Unit 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  zutf-8ÚstrictNr   r‰  r{   c             C   s   t j| |d d S )N)r|   )r˜   r;   )r2   r|   r   r   r   r;     s    z FileObjectClassTestCase.__init__c             C   sR   dd„ t dƒD ƒ\| _| _| _| _t | ¡ | jj| j	| j
| j| j| jd| _d S )Nc             S   s   g | ]}t  ¡ ‘qS r   )r<   r`   )rÉ   r*   r   r   r   rË     s    z1FileObjectClassTestCase.setUp.<locals>.<listcomp>rí   )ÚencodingÚerrorsÚnewline)r‘  Úevt1Úevt2Úserv_finishedÚcli_finishedr˜   r3   r™   r}  Ú	read_moderN   rz  r{  r|  Ú	read_file)r2   r   r   r   r3     s    "
zFileObjectClassTestCase.setUpc             C   s6   | j  ¡  | j ¡  |  | jj¡ d | _t | ¡ d S )N)r  rY   r‚  r   r×   Úclosedr˜   r4   )r2   r   r   r   r4   %  s
    

z FileObjectClassTestCase.tearDownc             C   s0   t  | ¡ | jj| j| j| j| j| jd| _	d S )N)rz  r{  r|  )
r˜   rq   r›   r}  Ú
write_moderN   rz  r{  r|  Ú
write_file)r2   r   r   r   rq   ,  s    
z#FileObjectClassTestCase.clientSetUpc             C   s6   | j  ¡  | j ¡  |  | jj¡ d | _t | ¡ d S )N)r€  rY   r…  r   r×   rƒ  r˜   rt   )r2   r   r   r   rt   4  s
    

z&FileObjectClassTestCase.clientTearDownc          	   C   sd   | j  d¡ | j d¡ |  tj| jjd¡ |  t¡}| j d¡ W d Q R X |  dt	|j
ƒ¡ d S )Nr[   r  z!cannot read from timed out object)r™   rO  r‚  r  rç   r	   rv  r   rÚ   rÐ   rï   )r2   Zctxr   r   r   ÚtestReadAfterTimeout;  s    z,FileObjectClassTestCase.testReadAfterTimeoutc             C   s.   | j  | jdd… ¡ | j  ¡  | j ¡  d S )Nr   r  )r…  r°  Ú	write_msgÚflushr  rl   )r2   r   r   r   Ú_testReadAfterTimeoutG  s    
z-FileObjectClassTestCase._testReadAfterTimeoutc             C   s<   | j  t| jƒd ¡}| j  d¡}|| }|  || j¡ d S )Nr  )r‚  r  rb  Úread_msgr’   )r2   Ú	first_segZ
second_segr”   r   r   r   ÚtestSmallReadL  s    z%FileObjectClassTestCase.testSmallReadc             C   s   | j  | j¡ | j  ¡  d S )N)r…  r°  r‡  rˆ  )r2   r   r   r   Ú_testSmallReadS  s    z&FileObjectClassTestCase._testSmallReadc             C   s   | j  ¡ }|  || j¡ d S )N)r‚  r  r’   rŠ  )r2   r”   r   r   r   ÚtestFullReadW  s    
z$FileObjectClassTestCase.testFullReadc             C   s   | j  | j¡ | j  ¡  d S )N)r…  r°  r‡  r   )r2   r   r   r   Ú_testFullRead\  s    z%FileObjectClassTestCase._testFullReadc             C   s>   t | jƒƒ }x| j d¡}|s P ||7 }qW |  || j¡ d S )Nr[   )rÂ   rŠ  r‚  r  r’   )r2   rK  Úcharr   r   r   ÚtestUnbufferedRead`  s    z*FileObjectClassTestCase.testUnbufferedReadc             C   s   | j  | j¡ | j  ¡  d S )N)r…  r°  r‡  rˆ  )r2   r   r   r   Ú_testUnbufferedReadj  s    z+FileObjectClassTestCase._testUnbufferedReadc             C   s   | j  ¡ }|  || j¡ d S )N)r‚  Úreadliner’   rŠ  )r2   Úliner   r   r   ÚtestReadlinen  s    
z$FileObjectClassTestCase.testReadlinec             C   s   | j  | j¡ | j  ¡  d S )N)r…  r°  r‡  rˆ  )r2   r   r   r   Ú_testReadlines  s    z%FileObjectClassTestCase._testReadlinec             C   s&   | j  ¡  | j ¡ }|  || j¡ d S )N)r™   r   r‚  r  r’   rŠ  )r2   r”   r   r   r   ÚtestCloseAfterMakefilew  s    

z.FileObjectClassTestCase.testCloseAfterMakefilec             C   s   | j  | j¡ | j  ¡  d S )N)r…  r°  r‡  rˆ  )r2   r   r   r   Ú_testCloseAfterMakefile~  s    z/FileObjectClassTestCase._testCloseAfterMakefilec             C   s@   | j  ¡  | j ttƒ¡}t| jtƒr.| 	¡ }|  
|| j¡ d S )N)r‚  r   r™   r‘   rb  r“   rÁ   rŠ  rÐ   Údecoder’   )r2   r”   r   r   r   ÚtestMakefileAfterMakefileClose‚  s
    
z6FileObjectClassTestCase.testMakefileAfterMakefileClosec             C   s   | j  | j¡ | j  ¡  d S )N)r…  r°  r‡  rˆ  )r2   r   r   r   Ú_testMakefileAfterMakefileClose‰  s    z7FileObjectClassTestCase._testMakefileAfterMakefileClosec             C   s   |   | jj ¡ d S )N)r×   r‚  rƒ  )r2   r   r   r   ÚtestClosedAttr  s    z&FileObjectClassTestCase.testClosedAttrc             C   s   |   | jj ¡ d S )N)r×   r…  rƒ  )r2   r   r   r   Ú_testClosedAttr  s    z'FileObjectClassTestCase._testClosedAttrc             C   s,   |   | jj| j¡ |   | jj| j ¡ ¡ d S )N)r’   r‚  rŠ  r  rÊ   r™   rÛ   )r2   r   r   r   ÚtestAttributes“  s    z&FileObjectClassTestCase.testAttributesc             C   s,   |   | jj| j¡ |   | jj| j ¡ ¡ d S )N)r’   r…  rŠ  r„  rÊ   r›   rÛ   )r2   r   r   r   Ú_testAttributes—  s    z'FileObjectClassTestCase._testAttributesc             C   s8   | j  ¡  |  t| j j¡ | j ¡  |  t| jj¡ d S )N)r‚  r   rç   r3  rÛ   r™   r   r‚   )r2   r   r   r   ÚtestRealClose›  s    

z%FileObjectClassTestCase.testRealClosec             C   s   d S )Nr   )r2   r   r   r   Ú_testRealClose¡  s    z&FileObjectClassTestCase._testRealClose)r{   )&r5   r6   r7   rD   rN   rz  r{  r|  r  r“   rŠ  r„  r‡  r;   r3   r4   rq   rt   r†  r‰  rŒ  r  rŽ  r  r‘  r’  r•  r–  r—  r˜  rš  r›  rœ  r  rž  rŸ  r   r¡  r   r   r   r   rx    sD   



rx  c               @   sd   e Zd ZdZdZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ ZdS )Ú!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.r   c             C   sL   | j  ¡ }|  |d| j ¡ | j dd¡| _ | j  ¡ }|  |d| j ¡ d S )Ns   A. r   r   s   B. )r‚  r“  r’   r‡  r™   r}  )r2   r”  r   r   r   ÚtestUnbufferedReadline±  s
    

z8UnbufferedFileObjectClassTestCase.testUnbufferedReadlinec             C   s2   | j  d| j ¡ | j  d| j ¡ | j  ¡  d S )Ns   A. s   B. )r…  r°  r‡  rˆ  )r2   r   r   r   Ú_testUnbufferedReadline¹  s    z9UnbufferedFileObjectClassTestCase._testUnbufferedReadlinec             C   sD   | j  ¡  | j  d¡}|  || j¡ | j ¡  |  t| j jd¡ d S )Ni   )r™   r   r‘   r’   rŠ  r‚  rç   r   )r2   r”   r   r   r   ÚtestMakefileClose¾  s
    

z3UnbufferedFileObjectClassTestCase.testMakefileClosec             C   s   | j  | j¡ | j  ¡  d S )N)r…  r°  r‡  rˆ  )r2   r   r   r   Ú_testMakefileCloseÇ  s    z4UnbufferedFileObjectClassTestCase._testMakefileClosec             C   s6   t  | j¡}| j ¡  t  | j¡}|  |d |¡ d S )Nr[   )r  r  r™   r‚  r   r’   )r2   Zrefcount_beforeZrefcount_afterr   r   r   ÚtestMakefileCloseSocketDestroyË  s    
z@UnbufferedFileObjectClassTestCase.testMakefileCloseSocketDestroyc             C   s   d S )Nr   )r2   r   r   r   Ú_testMakefileCloseSocketDestroyÑ  s    zAUnbufferedFileObjectClassTestCase._testMakefileCloseSocketDestroyc             C   s  | j  d¡ |  | j tdƒ¡d ¡ |  | j t| jƒd ¡d ¡ | j	 
¡  | j d¡ | j t| jƒd ¡}|d kr–t d¡ | j t| jƒd ¡}tdƒ}| j |¡}|  |d¡ ||d |…  }|  || j¡ |  | j tdƒ¡d ¡ |  | j d¡d ¡ d S )NFr/  r  g      ð?g      à?r  r[   )r™   rª  r’   r‚  ÚreadintorD  r  rb  rŠ  r}  rY   r~  rl   rŽ   r   )r2   r‹  rK  r«  r”   r   r   r   ÚtestSmallReadNonBlockingØ  s     

z:UnbufferedFileObjectClassTestCase.testSmallReadNonBlockingc             C   s>   | j  d¡ | j | j¡ | j ¡  | j ¡  | j d¡ d S )Ng      ð?g      @)	r}  rl   r…  r°  r‡  rˆ  r~  rY   r  )r2   r   r   r   Ú_testSmallReadNonBlockingë  s
    

z;UnbufferedFileObjectClassTestCase._testSmallReadNonBlockingc             C   s"   | j  d¡ | jr|  | j¡ d S )Ng      @)r€  rl   Úserv_skippedrM   )r2   r   r   r   ÚtestWriteNonBlockingô  s    z6UnbufferedFileObjectClassTestCase.testWriteNonBlockingc             C   sv   d | _ | j d¡ dtj }d}| j |¡}|  |d¡ x8t|ƒD ]&}| j |¡}|d kr\P |  |d¡ qBW d| _ d S )NFrp  r/  r   z$failed to saturate the socket buffer)	r¬  r›   rª  r   ru  r…  r°  r  r‘  )r2   ZBIGZLIMITr«  r*   r   r   r   Ú_testWriteNonBlockingû  s    
z7UnbufferedFileObjectClassTestCase._testWriteNonBlockingN)r5   r6   r7   rD   rN   r£  r¤  r¥  r¦  r§  r¨  rª  r«  r­  r®  r   r   r   r   r¢  ¥  s   		r¢  c               @   s   e Zd ZdZdS )Ú#LineBufferedFileObjectClassTestCaser[   N)r5   r6   r7   rN   r   r   r   r   r¯    s   r¯  c               @   s   e Zd ZdZdS )Ú$SmallBufferedFileObjectClassTestCaser„   N)r5   r6   r7   rN   r   r   r   r   r°    s   r°  c               @   s*   e Zd ZdZdZe d¡ZdZeZ	dZ
dS )Ú"UnicodeReadFileObjectClassTestCasez=Tests for socket.makefile() in text mode (rather than binary)r   zutf-8r‰  rë   N)r5   r6   r7   rD   r  r“   r™  rŠ  r„  r‡  r|  r   r   r   r   r±    s   
r±  c               @   s*   e Zd ZdZdZeZdZe d¡Z	dZ
dS )Ú#UnicodeWriteFileObjectClassTestCasez=Tests for socket.makefile() in text mode (rather than binary)r   rˆ  zutf-8rë   N)r5   r6   r7   rD   r  r“   rŠ  r„  r™  r‡  r|  r   r   r   r   r²  %  s   
r²  c               @   s0   e Zd ZdZdZe d¡ZdZe d¡Z	dZ
dS )Ú'UnicodeReadWriteFileObjectClassTestCasez=Tests for socket.makefile() in text mode (rather than binary)r   zutf-8rˆ  rë   N)r5   r6   r7   rD   r  r“   r™  rŠ  r„  r‡  r|  r   r   r   r   r³  /  s   

r³  c               @   s   e Zd ZdZdd„ ZdS )ÚNetworkConnectionTestzProve network connection.c             C   s   t  t| jf¡| _| j| _d S )N)r	   Úcreate_connectionr   r0   r}   r›   )r2   r   r   r   rq   <  s    z!NetworkConnectionTest.clientSetUpN)r5   r6   r7   rD   rq   r   r   r   r   r´  9  s   r´  c               @   s   e Zd ZdZdS )ÚBasicTCPTest2zLTests that NetworkConnection does not break existing TCP functionality.
    N)r5   r6   r7   rD   r   r   r   r   r¶  B  s   r¶  c               @   sD   e Zd ZG dd„ dejƒZejdd„ ƒZdd„ Zdd„ Z	d	d
„ Z
dS )ÚNetworkConnectionNoServerc               @   s   e Zd Zdd„ ZdS )z$NetworkConnectionNoServer.MockSocketc             G   s   t  d¡‚d S )Nz	timed out)r	   rv  )r2   r?   r   r   r   r   I  s    z,NetworkConnectionNoServer.MockSocket.connectN)r5   r6   r7   r   r   r   r   r   Ú
MockSocketH  s   r¸  c             c   s&   t j }| jt _ z
dV  W d|t _ X dS )z*Return a socket which times out on connectN)r	   r¸  )r2   Z
old_socketr   r   r   Úmocked_socket_moduleL  s
    
z.NetworkConnectionNoServer.mocked_socket_modulec          	   C   s^   t  ¡ }t tjtj¡}|  |j¡ |  t¡}| 	t
|f¡ W d Q R X |  |jjtj¡ d S )N)r   rG  r	   r,   r-   rB   r   rç   r   r   r   r’   rï   r   ZECONNREFUSED)r2   r0   r}   rð   r   r   r   Útest_connectV  s    z&NetworkConnectionNoServer.test_connectc          	   C   sH   t  ¡ }|  t¡}t t|f¡ W d Q R X t  ¡ }|  |j	j
|¡ d S )N)r   rG  rç   r   r	   rµ  r   Zget_socket_conn_refused_errsrÚ   rï   r   )r2   r0   rð   Zexpected_errnosr   r   r   Útest_create_connection^  s
    z0NetworkConnectionNoServer.test_create_connectionc          
   C   s>   |   ¡ , |  tj¡ t tdf¡ W d Q R X W d Q R X d S )NiÒ  )r¹  rç   r	   rv  rµ  r   )r2   r   r   r   Útest_create_connection_timeoutv  s    
z8NetworkConnectionNoServer.test_create_connection_timeoutN)r5   r6   r7   r	   r¸  Ú
contextlibÚcontextmanagerr¹  rº  r»  r¼  r   r   r   r   r·  F  s
   
r·  c               @   sv   e Zd Zddd„Zdd„ Zdd„ Zdd	„ ZeZd
d„ ZeZ	dd„ Z
eZdd„ ZeZdd„ ZeZdd„ ZeZdd„ ZdS )ÚNetworkConnectionAttributesTestr{   c             C   s   t j| |d t | ¡ d S )N)r|   )r+   r;   rS   )r2   r|   r   r   r   r;   €  s    z(NetworkConnectionAttributesTest.__init__c             C   s   t  ¡ | _d S )N)r   rG  Úsource_port)r2   r   r   r   rq   „  s    z+NetworkConnectionAttributesTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r}   r   rS   rt   )r2   r   r   r   rt   ‡  s    
z.NetworkConnectionAttributesTest.clientTearDownc             C   s   | j  ¡ \}}| ¡  d S )N)r.   r‹   r   )r2   rŒ   rš   r   r   r   Ú_justAcceptŒ  s    z+NetworkConnectionAttributesTest._justAcceptc             C   s8   t jt| jfdd| _|  | jj¡ |  | jjd¡ d S )Né   )rv  r„   )	r	   rµ  r   r0   r}   rB   r   r’   rß   )r2   r   r   r   Ú_testFamily‘  s    z+NetworkConnectionAttributesTest._testFamilyc             C   sH   t jt| jfdd| jfd| _|  | jj¡ |  | j 	¡ d | j¡ d S )NrÂ  rë   )rv  Zsource_addressr[   )
r	   rµ  r   r0   rÀ  r}   rB   r   r’   r‚   )r2   r   r   r   Ú_testSourceAddress—  s    z2NetworkConnectionAttributesTest._testSourceAddressc          	   C   sd   |   t ¡ d k¡ t d¡ z$t t| jf¡| _|  | jj	¡ W d t d ¡ X |  
| j ¡ d¡ d S )Nr   )r×   r	   r0  r2  rµ  r   r0   r}   rB   r   r’   r1  )r2   r   r   r   Ú_testTimeoutDefault   s    
z3NetworkConnectionAttributesTest._testTimeoutDefaultc          	   C   sh   |   t ¡ d k¡ t d¡ z(tjt| jfd d| _|  | jj	¡ W d t d ¡ X |  
| j ¡ d ¡ d S )NrÂ  )rv  )r×   r	   r0  r2  rµ  r   r0   r}   rB   r   r’   r1  )r2   r   r   r   Ú_testTimeoutNone¬  s    
z0NetworkConnectionAttributesTest._testTimeoutNonec             C   s,   t jt| jfdd| _|  | j ¡ d¡ d S )NrÂ  )rv  )r	   rµ  r   r0   r}   r’   r1  )r2   r   r   r   Ú_testTimeoutValueNamed¸  s    z6NetworkConnectionAttributesTest._testTimeoutValueNamedc             C   s8   t  t| jfd¡| _|  | jj¡ |  | j ¡ d¡ d S )NrÂ  )	r	   rµ  r   r0   r}   rB   r   r’   r1  )r2   r   r   r   Ú_testTimeoutValueNonamed½  s    z8NetworkConnectionAttributesTest._testTimeoutValueNonamedN)r{   )r5   r6   r7   r;   rq   rt   rÁ  Z
testFamilyrÃ  ZtestSourceAddressrÄ  ZtestTimeoutDefaultrÅ  ZtestTimeoutNonerÆ  ZtestTimeoutValueNamedrÇ  ZtestTimeoutValueNonamedrÈ  r   r   r   r   r¿  ~  s    
r¿  c               @   sB   e Zd Zddd„Zdd„ Zdd„ Zdd	„ ZeZd
d„ Zdd„ Z	dS )ÚNetworkConnectionBehaviourTestr{   c             C   s   t j| |d t | ¡ d S )N)r|   )r+   r;   rS   )r2   r|   r   r   r   r;   Å  s    z'NetworkConnectionBehaviourTest.__init__c             C   s   d S )Nr   )r2   r   r   r   rq   É  s    z*NetworkConnectionBehaviourTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r}   r   rS   rt   )r2   r   r   r   rt   Ì  s    
z-NetworkConnectionBehaviourTest.clientTearDownc             C   s2   | j  ¡ \}}|  |j¡ t d¡ | d¡ d S )Nr  s   done!)r.   r‹   rB   r   rŽ   r   r–   )r2   rŒ   rš   r   r   r   ÚtestInsideTimeoutÑ  s    
z0NetworkConnectionBehaviourTest.testInsideTimeoutc             C   s0   t  t| jf¡ | _}| d¡}|  |d¡ d S )NrT  s   done!)r	   rµ  r   r0   r}   r‘   r’   )r2   r(   rØ  r   r   r   Ú_testInsideTimeoutØ  s    
z1NetworkConnectionBehaviourTest._testInsideTimeoutc                s4   t jt| jfdd | _‰ |  t j‡ fdd„¡ d S )Nr[   )rv  c                  s
   ˆ   d¡S )NrT  )r‘   r   )r(   r   r   r¾   ß  r¿   zDNetworkConnectionBehaviourTest._testOutsideTimeout.<locals>.<lambda>)r	   rµ  r   r0   r}   rç   rv  )r2   r   )r(   r   Ú_testOutsideTimeoutÝ  s    z2NetworkConnectionBehaviourTest._testOutsideTimeoutN)r{   )
r5   r6   r7   r;   rq   rt   rÊ  ZtestOutsideTimeoutrË  rÌ  r   r   r   r   rÉ  Ã  s   
rÉ  c               @   s6   e Zd Zdd„ Zdd„ Ze eedƒd¡dd„ ƒZ	d	S )
ÚTCPTimeoutTestc                s    ‡ fdd„}ˆ   tj|d¡ d S )Nc                 s   ˆ j  d¡ ˆ j  ¡  d S )Ng      ð?)r.   rO  r‹   )r?   r@   )r2   r   r   Úraise_timeoutå  s    z4TCPTimeoutTest.testTCPTimeout.<locals>.raise_timeoutz*Error generating a timeout exception (TCP))rç   r	   rv  )r2   rÎ  r   )r2   r   ÚtestTCPTimeoutä  s    
zTCPTimeoutTest.testTCPTimeoutc             C   s|   d}y| j  d¡ | j  ¡ }W nJ tjk
r>   |  d¡ Y n, tk
rT   d}Y n   |  d¡ Y nX |sx|  d¡ d S )NFg        z%caught timeout instead of error (TCP)Tz!caught unexpected exception (TCP)z3accept() returned success when we did not expect it)r.   rO  r‹   r	   rv  rä   r   )r2   ÚokÚfoor   r   r   ÚtestTimeoutZeroë  s    zTCPTimeoutTest.testTimeoutZerork  ztest needs signal.alarm()c          
      s
  | j  d¡ G dd„ dtƒ‰ ‡ fdd„}t tj|¡}z¾yšzˆyt d¡ | j  ¡ }W n` tjk
rt   |  	d¡ Y nL ˆ k
r†   Y n:   |  	dt
 ¡ d d… t ¡ f  ¡ Y nX |  	d	¡ W d t d
¡ X W n ˆ k
rð   |  	d¡ Y nX W d t tj|¡ X d S )Ng      @c               @   s   e Zd ZdS )z4TCPTimeoutTest.testInterruptedTimeout.<locals>.AlarmN)r5   r6   r7   r   r   r   r   ÚAlarm   s   rÓ  c                s   ˆ ‚d S )Nr   )rq  rÛ  )rÓ  r   r   Úalarm_handler  s    z<TCPTimeoutTest.testInterruptedTimeout.<locals>.alarm_handlerr„   zcaught timeout instead of Alarmz3caught other exception instead of Alarm: %s(%s):
%sznothing caughtr   zgot Alarm in wrong place)r.   rO  r@  rq  rr  rk  r‹   r	   rv  rä   r  Úexc_infoÚ	tracebackÚ
format_exc)r2   rÔ  rx  rÑ  r   )rÓ  r   ÚtestInterruptedTimeoutù  s(    
$z%TCPTimeoutTest.testInterruptedTimeoutN)
r5   r6   r7   rÏ  rÒ  r†   rÀ  ru   rq  rØ  r   r   r   r   rÍ  â  s   rÍ  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚUDPTimeoutTestc                s    ‡ fdd„}ˆ   tj|d¡ d S )Nc                 s   ˆ j  d¡ ˆ j  d¡ d S )Ng      ð?i   )r.   rO  r‘   )r?   r@   )r2   r   r   rÎ    s    z4UDPTimeoutTest.testUDPTimeout.<locals>.raise_timeoutz*Error generating a timeout exception (UDP))rç   r	   rv  )r2   rÎ  r   )r2   r   ÚtestUDPTimeout  s    
zUDPTimeoutTest.testUDPTimeoutc             C   s~   d}y| j  d¡ | j  d¡}W nJ tjk
r@   |  d¡ Y n, tk
rV   d}Y n   |  d¡ Y nX |sz|  d¡ d S )NFg        i   z%caught timeout instead of error (UDP)Tz!caught unexpected exception (UDP)z1recv() returned success when we did not expect it)r.   rO  r‘   r	   rv  rä   r   )r2   rÐ  rÑ  r   r   r   rÒ  $  s    zUDPTimeoutTest.testTimeoutZeroN)r5   r6   r7   rÚ  rÒ  r   r   r   r   rÙ    s   rÙ  c               @   s   e Zd Zdd„ Zdd„ ZdS )ÚTestExceptionsc             C   sJ   |   tttƒ¡ |   ttjtƒ¡ |   ttjtƒ¡ |   ttjtƒ¡ d S )N)r×   Ú
issubclassr   r@  r	   rè   ré   rv  )r2   r   r   r   ÚtestExceptionTree4  s    z TestExceptions.testExceptionTreec          	   C   sb   t   t jt jd¡}t   t jt jd| ¡ ¡}| ¡  |  |j¡ |  t¡ | 	d¡ W d Q R X d S )Nr   F)
r	   r,   r-   rÛ   r   rB   rº  rç   r   rª  )r2   Zsock0r(   r   r   r   Útest_setblocking_invalidfd:  s    z)TestExceptions.test_setblocking_invalidfdN)r5   r6   r7   rÝ  rÞ  r   r   r   r   rÛ  2  s   rÛ  r%  zLinux specific testc               @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTestLinuxAbstractNamespaceél   c             C   s˜   d}t   t jt j¡z}| |¡ | ¡  t   t jt j¡L}| | ¡ ¡ | ¡ d &}|  | ¡ |¡ |  | 	¡ |¡ W d Q R X W d Q R X W d Q R X d S )Ns    python-test-hello ÿr   )
r	   r²   r-   rK   r1   r   r‚   r‹   r’   Zgetpeername)r2   ÚaddressÚs1r¼  Zs3r   r   r   ÚtestLinuxAbstractNamespaceL  s    
z5TestLinuxAbstractNamespace.testLinuxAbstractNamespacec          	   C   sL   dd| j d   }t tjtj¡ }| |¡ |  | ¡ |¡ W d Q R X d S )NrÕ  ó   hr[   )ÚUNIX_PATH_MAXr	   r²   r-   rK   r’   r‚   )r2   rá  r   r   r   r   ÚtestMaxNameW  s    
z&TestLinuxAbstractNamespace.testMaxNamec          	   C   s>   dd| j   }t tjtj¡}|  t|j|¡ W d Q R X d S )Nú Úh)rå  r	   r²   r-   rç   r   rK   )r2   rá  r   r   r   r   ÚtestNameOverflow]  s    z+TestLinuxAbstractNamespace.testNameOverflowc             C   s>   t   t jt j¡}z| d¡ |  | ¡ d¡ W d | ¡  X d S )Nz python test s    python test )r	   r²   r-   rK   r’   r‚   r   )r2   r   r   r   r   ÚtestStrNameb  s
    
z&TestLinuxAbstractNamespace.testStrNamec          	   C   s>   t   t jt j¡$}| tdƒ¡ |  | ¡ d¡ W d Q R X d S )Ns    python test )r	   r²   r-   rK   rD  r’   r‚   )r2   r   r   r   r   ÚtestBytearrayNamek  s    z,TestLinuxAbstractNamespace.testBytearrayNameN)	r5   r6   r7   rå  rã  ræ  ré  rê  rë  r   r   r   r   rß  G  s   	rß  ztest needs socket.AF_UNIXc               @   sT   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Zdd„ Z	dd„ Z
dd„ ZdS )ÚTestUnixDomainc             C   s   t   t jt j¡| _d S )N)r	   r²   r-   r(   )r2   r   r   r   r3   t  s    zTestUnixDomain.setUpc             C   s   | j  ¡  d S )N)r(   r   )r2   r   r   r   r4   w  s    zTestUnixDomain.tearDownc          
   C   s:   y
t  |¡S  tk
r4   |  d |t ¡ ¡¡ Y nX d S )NzBPathname {0!a} cannot be represented in file system encoding {1!r})r&   Úfsencodere  rM   rÒ   r  Úgetfilesystemencoding)r2   r°   r   r   r   Úencodedz  s    
zTestUnixDomain.encodedc          
   C   sX   yt  ||¡ W nB tk
rR } z$t|ƒdkr@|  d |¡¡ n‚ W d d }~X Y nX d S )NzAF_UNIX path too longz6Pathname {0!a} is too long to serve as an AF_UNIX path)r   r®   r   rÐ   rM   rÒ   )r2   r(   r°   rw   r   r   r   rK   …  s    
zTestUnixDomain.bindc             C   s   |   | j ¡ d¡ d S )N)rë   N)rÚ   r(   r‚   )r2   r   r   r   ÚtestUnbound‘  s    zTestUnixDomain.testUnboundc             C   s@   t j tj¡}|  | j|¡ |  tj|¡ |  	| j 
¡ |¡ d S )N)r&   r°   Úabspathr   ÚTESTFNrK   r(   rB   r¯   r’   r‚   )r2   r°   r   r   r   ÚtestStrAddr•  s    zTestUnixDomain.testStrAddrc             C   sF   t j tj¡}|  | j|  |¡¡ |  tj	|¡ |  
| j ¡ |¡ d S )N)r&   r°   rñ  r   rò  rK   r(   rï  rB   r¯   r’   r‚   )r2   r°   r   r   r   ÚtestBytesAddrœ  s    zTestUnixDomain.testBytesAddrc             C   sR   t j tj¡}|  |¡}|  | j| dd¡¡ |  	tj
|¡ |  | j ¡ |¡ d S )NÚasciiÚsurrogateescape)r&   r°   rñ  r   ZTESTFN_UNICODErï  rK   r(   r™  rB   r¯   r’   r‚   )r2   r°   rg  r   r   r   ÚtestSurrogateescapeBind£  s
    
z&TestUnixDomain.testSurrogateescapeBindc             C   sT   t jd kr|  d¡ tj t j¡}|  | j|¡ |  t j	|¡ |  
| j ¡ |¡ d S )Nz!No unencodable filename available)r   ZTESTFN_UNENCODABLErM   r&   r°   rñ  rK   r(   rB   r¯   r’   r‚   )r2   r°   r   r   r   ÚtestUnencodableAddr¬  s    

z"TestUnixDomain.testUnencodableAddrN)r5   r6   r7   r3   r4   rï  rK   rð  ró  rô  r÷  rø  r   r   r   r   rì  q  s   	rì  c               @   s†   e Zd ZdZddd„Zdd„ Zdd„ Zd	d
„ ZeZdd„ Z	eZ
dd„ Zdd„ Zdd„ ZeZdd„ ZeZdd„ Zdd„ Zdd„ ZeZdS )ÚBufferIOTestzF
    Test the buffer versions of socket.recv() and socket.send().
    r{   c             C   s   t j| |d d S )N)r|   )r˜   r;   )r2   r|   r   r   r   r;   »  s    zBufferIOTest.__init__c             C   sZ   t   ddgttƒ ¡}| j |¡}|  |ttƒ¡ | ¡ }|d ttƒ… }|  |t¡ d S )Nr\  r   )r]  rb  r“   r™   rJ  r’   r  )r2   rK  r˜  r”   r   r   r   ÚtestRecvIntoArray¾  s    zBufferIOTest.testRecvIntoArrayc             C   s   t tƒ}| j |¡ d S )N)rí  r“   r›   r–   )r2   rK  r   r   r   Ú_testRecvIntoArrayÆ  s    zBufferIOTest._testRecvIntoArrayc             C   sD   t dƒ}| j |¡}|  |ttƒ¡ |d ttƒ… }|  |t¡ d S )Ni   )rD  r™   rJ  r’   rb  r“   )r2   rK  r˜  r”   r   r   r   ÚtestRecvIntoBytearrayÊ  s
    z"BufferIOTest.testRecvIntoBytearrayc             C   sH   t dƒ}| j t|ƒ¡}|  |ttƒ¡ |d ttƒ… }|  |t¡ d S )Ni   )rD  r™   rJ  r¡  r’   rb  r“   )r2   rK  r˜  r”   r   r   r   ÚtestRecvIntoMemoryviewÓ  s
    z#BufferIOTest.testRecvIntoMemoryviewc             C   s^   t   ddgttƒ ¡}| j |¡\}}|  |ttƒ¡ | ¡ }|d ttƒ… }|  |t¡ d S )Nr\  r   )r]  rb  r“   r™   rM  r’   r  )r2   rK  r˜  rš   r”   r   r   r   ÚtestRecvFromIntoArrayÜ  s    z"BufferIOTest.testRecvFromIntoArrayc             C   s   t tƒ}| j |¡ d S )N)rí  r“   r›   r–   )r2   rK  r   r   r   Ú_testRecvFromIntoArrayä  s    z#BufferIOTest._testRecvFromIntoArrayc             C   sH   t dƒ}| j |¡\}}|  |ttƒ¡ |d ttƒ… }|  |t¡ d S )Ni   )rD  r™   rM  r’   rb  r“   )r2   rK  r˜  rš   r”   r   r   r   ÚtestRecvFromIntoBytearrayè  s
    z&BufferIOTest.testRecvFromIntoBytearrayc             C   sL   t dƒ}| j t|ƒ¡\}}|  |ttƒ¡ |d ttƒ… }|  |t¡ d S )Ni   )rD  r™   rM  r¡  r’   rb  r“   )r2   rK  r˜  rš   r”   r   r   r   ÚtestRecvFromIntoMemoryviewñ  s
    z'BufferIOTest.testRecvFromIntoMemoryviewc             C   s    t dƒ}|  t| jj|d¡ d S )NrJ   i   )rD  rç   r3  r™   rM  )r2   rK  r   r   r   ÚtestRecvFromIntoSmallBufferú  s    z(BufferIOTest.testRecvFromIntoSmallBufferc             C   s   | j  t¡ d S )N)r›   r–   r“   )r2   r   r   r   Ú_testRecvFromIntoSmallBufferÿ  s    z)BufferIOTest._testRecvFromIntoSmallBufferc             C   s$   t ƒ }| j |¡ | j |d¡ d S )Nr   )rD  r™   rM  )r2   rK  r   r   r   ÚtestRecvFromIntoEmptyBuffer  s    z(BufferIOTest.testRecvFromIntoEmptyBufferN)r{   )r5   r6   r7   rD   r;   rú  rû  rü  Z_testRecvIntoBytearrayrý  Z_testRecvIntoMemoryviewrþ  rÿ  r   Z_testRecvFromIntoBytearrayr  Z_testRecvFromIntoMemoryviewr  r  r  Z_testRecvFromIntoEmptyBufferr   r   r   r   rù  ·  s$   
rù  iÐ  éÈ   éÒ   c           
   C   sf   t tdƒsdS ytdƒ} W n tttfk
r4   dS X | " x| D ]}| d¡rBdS qBW W dQ R X dS )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/modulesztipc TN)ru   r	   r   ÚFileNotFoundErrorÚIsADirectoryErrorÚPermissionErrorr,  )r   r”  r   r   r   ÚisTipcAvailable  s    


r  z6TIPC module is not loaded, please 'sudo modprobe tipc'c               @   s   e Zd Zdd„ ZdS )ÚTIPCTestc             C   sº   t   t jt j¡}t   t jt j¡}|  |j¡ |  |j¡ | t jt jd¡ t jt	t
tf}| |¡ t jt	t
ttt
 d ƒ df}| t|¡ | d¡\}}|  | ¡ |¡ |  |t¡ d S )Nr[   r„   r   i   )r	   r  rò   rB   r   rM  ró   rô   ÚTIPC_ADDR_NAMESEQÚ
TIPC_STYPEÚ
TIPC_LOWERÚ
TIPC_UPPERrK   ÚTIPC_ADDR_NAMEr  rî   r“   rÝ  r’   r‚   )r2   r–  r}   ÚsrvaddrZsendaddrr”   Zrecvaddrr   r   r   ÚtestRDM%  s    
zTIPCTest.testRDMN)r5   r6   r7   r  r   r   r   r   r  "  s   r  c               @   s6   e Zd Zddd„Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚTIPCThreadableTestr{   c             C   s   t jj| |d t | ¡ d S )N)r|   )r†   r‡   r;   rS   )r2   r|   r   r   r   r;   =  s    zTIPCThreadableTest.__init__c             C   s„   t   t jt j¡| _|  | jj¡ | j t jt jd¡ t j	t
ttf}| j |¡ | j ¡  |  ¡  | j ¡ \| _| _|  | jj¡ d S )Nr[   )r	   r  r-   r–  rB   r   rM  ró   rô   r  r  r  r  rK   r1   rZ   r‹   rŒ   r   )r2   r  r   r   r   r3   A  s    
zTIPCThreadableTest.setUpc             C   sd   t  d¡ t tjtj¡| _|  | jj¡ tjt	t
ttt
 d ƒ df}| j |¡ | j ¡ | _d S )Ngš™™™™™¹?r„   r   )rŽ   r   r	   r  r-   r}   rB   r   r  r  r  r  r  r   r‚   Úcliaddr)r2   rš   r   r   r   rq   M  s    
zTIPCThreadableTest.clientSetUpc             C   s,   | j  d¡}|  |t¡ |  | j| j¡ d S )Ni   )rŒ   r‘   r’   r“   r  r   )r2   r”   r   r   r   r•   Y  s    zTIPCThreadableTest.testStreamc             C   s   | j  t¡ | j  ¡  d S )N)r}   r–   r“   r   )r2   r   r   r   r—   ^  s    zTIPCThreadableTest._testStreamN)r{   )r5   r6   r7   r;   r3   rq   r•   r—   r   r   r   r   r  :  s
   
r  c               @   s4   e Zd Zdd„ Zdd„ Zdd„ Zdd„ Zd	d
„ ZdS )ÚContextManagersTestc          	   C   sˆ   t   ¡ }|  |j¡ W d Q R X |  |j¡ t   ¡ }| ¡  W d Q R X |  |j¡ t   ¡ }|  t|jd¡ W d Q R X |  |j¡ d S )Ns   foo)r	   rJ  r'  r×   r   rç   r   rt  )r2   r(   r   r   r   Ú_testSocketClasse  s    


z$ContextManagersTest._testSocketClassc             C   s2   | j  ¡ \}}|  |j¡ | d¡}| |¡ d S )Ni   )r.   r‹   rB   r   r‘   rt  )r2   rŒ   rš   rØ  r   r   r   ÚtestCreateConnectionBases  s    
z,ContextManagersTest.testCreateConnectionBasec          	   C   sX   | j  ¡ }t |¡.}|  |j¡ | d¡ |  | d¡d¡ W d Q R X |  	|j¡ d S )Ns   fooi   )
r.   r‚   r	   rµ  rJ  r'  rt  r’   r‘   r×   )r2   rá  r(   r   r   r   Ú_testCreateConnectionBasey  s    

z-ContextManagersTest._testCreateConnectionBasec             C   s2   | j  ¡ \}}|  |j¡ | d¡}| |¡ d S )Ni   )r.   r‹   rB   r   r‘   rt  )r2   rŒ   rš   rØ  r   r   r   ÚtestCreateConnectionClose  s    
z-ContextManagersTest.testCreateConnectionClosec          	   C   sH   | j  ¡ }t |¡}| ¡  W d Q R X |  |j¡ |  t|j	d¡ d S )Ns   foo)
r.   r‚   r	   rµ  r   r×   r'  rç   r   rt  )r2   rá  r(   r   r   r   Ú_testCreateConnectionClose‡  s
    
z.ContextManagersTest._testCreateConnectionCloseN)r5   r6   r7   r  r  r  r  r  r   r   r   r   r  c  s
   r  c               @   s„   e Zd Ze eedƒd¡e ddd¡dd„ ƒƒZ	dd	„ Z
d
d„ Zdd„ Ze edkd¡dd„ ƒZe edkd¡dd„ ƒZdd„ ZdS )ÚInheritanceTestrR  zSOCK_CLOEXEC not definedr„   rj  rk  c          	   C   sD   t   t jt jt jB ¡$}|  |jt j¡ |  | ¡ ¡ W d Q R X d S )N)r	   r,   r-   rR  r’   rÂ   rJ  Úget_inheritable)r2   r   r   r   r   Útest_SOCK_CLOEXEC  s    z!InheritanceTest.test_SOCK_CLOEXECc          	   C   s,   t   ¡ }| |  | ¡ d¡ W d Q R X d S )NF)r	   r’   r  )r2   r(   r   r   r   Útest_default_inheritable™  s    z(InheritanceTest.test_default_inheritablec          
   C   sL   t   ¡ }|6 | ¡ }| ¡  | |  | ¡ d¡ W d Q R X W d Q R X d S )NF)r	   r  r   r’   r  )r2   r(   Znewsockr   r   r   Útest_dupž  s    zInheritanceTest.test_dupc          	   C   sP   t   ¡ }|: | d¡ |  | ¡ d¡ | d¡ |  | ¡ d¡ W d Q R X d S )NTF)r	   Úset_inheritabler’   r  )r2   r(   r   r   r   Útest_set_inheritable¦  s    

z$InheritanceTest.test_set_inheritableNz
need fcntlc          	   C   sn   t   ¡ }|X | ¡ }|  | ¡ d¡ t |tj¡}|tj M }t |tj|¡ |  | ¡ d¡ W d Q R X d S )NFT)r	   rÛ   r’   r  r   ÚF_GETFDÚ
FD_CLOEXECZF_SETFD)r2   r(   r±  r_  r   r   r   Útest_get_inheritable_cloexec¯  s    z,InheritanceTest.test_get_inheritable_cloexecc          	   C   sh   t   ¡ }|R | ¡ }|  t |tj¡tj@ tj¡ | d¡ |  t |tj¡tj@ d¡ W d Q R X d S )NTr   )r	   rÛ   r’   r   r#  r$  r!  )r2   r(   r±  r   r   r   Útest_set_inheritable_cloexec½  s    
z,InheritanceTest.test_set_inheritable_cloexecc             C   sH   t  ¡ \}}|  |j¡ |  |j¡ |  | ¡ d¡ |  | ¡ d¡ d S )NF)r	   r   rB   r   r’   r  )r2   râ  r¼  r   r   r   Útest_socketpairÊ  s
    zInheritanceTest.test_socketpair)r5   r6   r7   r†   rÀ  ru   r	   r   rw  r  r  r   r"  rÂ  r   r%  r&  r'  r   r   r   r   r    s   	r  r©  zSOCK_NONBLOCK not definedc               @   s,   e Zd Zddd„Ze ddd¡dd	„ ƒZd
S )ÚNonblockConstantTestTç        c             C   sº   |rj|   |jtj¡ |   | ¡ |¡ |  t |tjtj	¡tj	@ ¡ |dkrZ|  
| ¡ ¡ q¶|  | ¡ ¡ nL|   |jtj¡ |   | ¡ d ¡ |  
t |tjtj	¡tj	@ ¡ |  | ¡ ¡ d S )Nr   )r’   rÂ   r	   r-   r1  r×   r   r%   r&   r'   rJ  re  )r2   r   Únonblockrv  r   r   r   ÚcheckNonblockÕ  s    	z"NonblockConstantTest.checkNonblockr„   rj  rk  c          	   C   s^  t   t jt jt jB ¡„}|  |¡ | d¡ | j|dd | d¡ |  |¡ | d ¡ | j|dd | d¡ | j|dd | d¡ | j|dd W d Q R X t  ¡ }t  d¡ t   ¡ }|  |¡ W d Q R X t  d ¡ t   ¡ }|  |d¡ W d Q R X t  d¡ t   ¡ }| j|dd W d Q R X t  d ¡ t   ¡ }|  |d¡ W d Q R X t  |¡ d S )Nr[   F)r*  r   g       @)rv  g        )	r	   r,   r-   r©  r+  rª  rO  r0  r2  )r2   r   Útr   r   r   Útest_SOCK_NONBLOCKî  s6    














z'NonblockConstantTest.test_SOCK_NONBLOCKN)Tr)  )r5   r6   r7   r+  r   rw  r-  r   r   r   r   r(  Ò  s   
r(  rX  zWindows specificzneed multiprocessingc               @   s@   e Zd Zedd„ ƒZdd„ Zdd„ Zdd„ Zd	d
„ Zdd„ Z	dS )ÚTestSocketSharingc             C   sD   |  ¡ }|  ¡ }t |¡}| ¡ \}}| |¡ | ¡  | ¡  d S )N)rn   r	   Ú	fromsharer‹   rt  r   )r×  ÚqZsdatarn  r   r¼  rw  r   r   r   ÚremoteProcessServer  s    

z%TestSocketSharing.remoteProcessServerc       	      C   s´   t  ¡ }t j| j|fd}| ¡  | j |j¡}| j ¡ }| j 	¡  | 
|¡ d}| 
|¡ t |¡}g }x| d¡}|s|P | |¡ qlW | 	¡  d |¡}|  ||¡ | ¡  d S )N)rR  r?   s
   slapmahfrorZ  r¿   )Úmultiprocessingrd   ZProcessr1  rT  r.   ÚshareÚpidr‚   r   rs   r	   rµ  r‘   r²  rÍ   r’   )	r2   r0  rå   rØ  rš   rn  r   ÚmÚreceivedr   r   r   Ú	testShare#  s(    






zTestSocketSharing.testSharec             C   s@   | j  t ¡ ¡}|  ttj|d d… ¡ |  ttj|d ¡ d S )Nr  s   foo)r.   r3  r&   Úgetpidrç   r3  r	   r/  )r2   rØ  r   r   r   ÚtestShareLengthF  s    z!TestSocketSharing.testShareLengthc             C   sb   |   | ¡ d ¡ |   | ¡ | ¡ ¡ |   |j|j¡ |   |j|j¡ |jdkr^|   |j|j¡ d S )Nr   )r’   r1  rß   rÂ   rà   )r2   ZorgÚotherr   r   r   ÚcompareSocketsK  s    
z TestSocketSharing.compareSocketsc             C   s<   | j  t ¡ ¡}t |¡}z|  | j |¡ W d | ¡  X d S )N)r.   r3  r&   r8  r	   r/  r;  r   )r2   rØ  r   r   r   r   ÚtestShareLocal[  s
    
z TestSocketSharing.testShareLocalc          
   C   s¤   t jt jg}t jt jg}x†|D ]~}xx|D ]p}yt   ||¡}W n tk
rR   w(Y nX z8| t ¡ ¡}t  	|¡}z|  
||¡ W d | ¡  X W d | ¡  X q(W qW d S )N)r	   r,   r¼   r-   r   r   r3  r&   r8  r/  r;  r   )r2   ZfamiliesÚtypesr   r,  ÚsourcerØ  Zsharedr   r   r   Ú	testTypesc  s    


zTestSocketSharing.testTypesN)
r5   r6   r7   rñ  r1  r7  r9  r;  r<  r?  r   r   r   r   r.    s   #r.  c               @   s   e Zd ZdZdZdZdZdZedd„ ƒZ	edd	„ ƒZ
d
d„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Z d6d7„ Z!d8d9„ Z"d:d;„ Z#d<S )=ÚSendfileUsingSendTestz>
    Test the send() implementation of socket.sendfile().
    i    i    r¿   r„   c          	   C   s–   dd„ }d  dd„ t| jƒD ƒ¡}ttjdƒ(}x || j| jƒD ]}| |¡ q@W W d Q R X ttjdƒ$}| ¡ | _	t
| j	ƒ| jksˆt‚W d Q R X d S )Nc             s   s6   | |kst ‚x| |kr&|V  | |8 } qW | r2| V  d S )N)rî  )ZtotalÚstepr   r   r   Úchunksƒ  s    
z0SendfileUsingSendTest.setUpClass.<locals>.chunksr¿   c             S   s   g | ]}t  tj¡ ¡ ‘qS r   )ÚrandomÚchoiceÚstringZascii_lettersr±  )rÉ   r*   r   r   r   rË   ‹  s   z4SendfileUsingSendTest.setUpClass.<locals>.<listcomp>r‰  r   )rÍ   r‘  ÚBUFSIZEr   r   rò  ÚFILESIZEr°  r  ÚFILEDATArb  rî  )r×  rB  Úchunkr   Zcsizer   r   r   Ú
setUpClass  s    

z SendfileUsingSendTest.setUpClassc             C   s   t  t j¡ d S )N)r   r¯   rò  )r×  r   r   r   ÚtearDownClass”  s    z#SendfileUsingSendTest.tearDownClassc             C   s6   | j  t¡ | j  ¡ \}}| | j¡ |  |j¡ |S )N)r.   rO  rr  r‹   ÚTIMEOUTrB   r   )r2   rŒ   rš   r   r   r   Úaccept_conn˜  s
    z!SendfileUsingSendTest.accept_connc             C   s0   g }x |  | j¡}|sP | |¡ qW d |¡S )Nr¿   )r‘   rF  r²  rÍ   )r2   rŒ   r6  rI  r   r   r   Ú	recv_dataŸ  s    zSendfileUsingSendTest.recv_datac             C   s
   t |dƒS )NZ_sendfile_use_send)rh   )r2   r(   r   r   r   Úmeth_from_sock¨  s    z$SendfileUsingSendTest.meth_from_sockc          
   C   sr   | j  ¡ }ttjdƒ}t |¡H}|8}|  |¡}||ƒ}|  || j	¡ |  | 
¡ | j	¡ W d Q R X W d Q R X d S )Nr   )r.   r‚   r   r   rò  r	   rµ  rO  r’   rG  Útell)r2   rá  Úfiler(   ÚmethÚsentr   r   r   Ú_testRegularFile¯  s    

z&SendfileUsingSendTest._testRegularFilec             C   s6   |   ¡ }|  |¡}|  t|ƒ| j¡ |  || j¡ d S )N)rM  rN  r’   rb  rG  rH  )r2   rŒ   rØ  r   r   r   ÚtestRegularFile¸  s    
z%SendfileUsingSendTest.testRegularFilec          
   C   s|   | j  ¡ }t | j¡}t |¡R}|B}| |¡}|  || j	¡ |  | 
¡ | j	¡ |  tj|j|¡ W d Q R X W d Q R X d S )N)r.   r‚   ÚioÚBytesIOrH  r	   rµ  r³  r’   rG  rP  rç   r·  r¸  )r2   rá  rQ  r(   rS  r   r   r   Ú_testNonRegularFileÀ  s    

z)SendfileUsingSendTest._testNonRegularFilec             C   s6   |   ¡ }|  |¡}|  t|ƒ| j¡ |  || j¡ d S )N)rM  rN  r’   rb  rG  rH  )r2   rŒ   rØ  r   r   r   ÚtestNonRegularFileÊ  s    
z(SendfileUsingSendTest.testNonRegularFilec          
   C   sš   | j  ¡ }tjd }t|dƒ |  tj|¡ W d Q R X t|dƒ}t |¡D}|4}|  	|¡}||ƒ}|  
|d¡ |  
| ¡ d¡ W d Q R X W d Q R X d S )NÚ2r‰  r   r   )r.   r‚   r   rò  r   rB   r¯   r	   rµ  rO  r’   rP  )r2   rá  ÚfilenamerQ  r(   rR  rS  r   r   r   Ú_testEmptyFileSendÒ  s    



z(SendfileUsingSendTest._testEmptyFileSendc             C   s"   |   ¡ }|  |¡}|  |d¡ d S )Nr¿   )rM  rN  r’   )r2   rŒ   rØ  r   r   r   ÚtestEmptyFileSendÞ  s    
z'SendfileUsingSendTest.testEmptyFileSendc          
   C   sz   | j  ¡ }ttjdƒ}t |¡P}|@}|  |¡}||dd}|  || j	d ¡ |  | 
¡ | j	¡ W d Q R X W d Q R X d S )Nr   iˆ  )Úoffset)r.   r‚   r   r   rò  r	   rµ  rO  r’   rG  rP  )r2   rá  rQ  r(   rR  rS  r   r   r   Ú_testOffsetå  s    

z!SendfileUsingSendTest._testOffsetc             C   sB   |   ¡ }|  |¡}|  t|ƒ| jd ¡ |  || jdd … ¡ d S )Niˆ  )rM  rN  r’   rb  rG  rH  )r2   rŒ   rØ  r   r   r   Ú
testOffsetî  s    
z SendfileUsingSendTest.testOffsetc          
   C   sz   | j  ¡ }ttjdƒ}tj|ddL}|<}d}|  |¡}|||d}|  ||¡ |  | 	¡ |¡ W d Q R X W d Q R X d S )Nr   r„   )rv  iGKL )rV  )
r.   r‚   r   r   rò  r	   rµ  rO  r’   rP  )r2   rá  rQ  r(   rV  rR  rS  r   r   r   Ú
_testCountö  s    

z SendfileUsingSendTest._testCountc             C   s@   d}|   ¡ }|  |¡}|  t|ƒ|¡ |  || jd |… ¡ d S )NiGKL )rM  rN  r’   rb  rH  )r2   rV  rŒ   rØ  r   r   r   Ú	testCount   s
    
zSendfileUsingSendTest.testCountc          
   C   sz   | j  ¡ }ttjdƒ}tj|ddL}|<}d}|  |¡}|||d}|  ||¡ |  | 	¡ |¡ W d Q R X W d Q R X d S )Nr   r„   )rv  r[   )rV  )
r.   r‚   r   r   rò  r	   rµ  rO  r’   rP  )r2   rá  rQ  r(   rV  rR  rS  r   r   r   Ú_testCountSmall	  s    

z%SendfileUsingSendTest._testCountSmallc             C   s@   d}|   ¡ }|  |¡}|  t|ƒ|¡ |  || jd |… ¡ d S )Nr[   )rM  rN  r’   rb  rH  )r2   rV  rŒ   rØ  r   r   r   ÚtestCountSmall  s
    
z$SendfileUsingSendTest.testCountSmallc          
   C   s€   | j  ¡ }ttjdƒ}tj|ddR}|B}d}|  |¡}||d|d}|  ||¡ |  | 	¡ |d ¡ W d Q R X W d Q R X d S )Nr   r„   )rv  i§† i×  )r^  rV  )
r.   r‚   r   r   rò  r	   rµ  rO  r’   rP  )r2   rá  rQ  r(   rV  rR  rS  r   r   r   Ú_testCountWithOffset  s    

z*SendfileUsingSendTest._testCountWithOffsetc             C   sD   d}|   ¡ }|  |¡}|  t|ƒ|¡ |  || jd|d … ¡ d S )Ni§† i×  )rM  rN  r’   rb  rH  )r2   rV  rŒ   rØ  r   r   r   ÚtestCountWithOffset&  s
    
z)SendfileUsingSendTest.testCountWithOffsetc          
   C   sr   | j  ¡ }ttjdƒ}t |¡H}|8}| d¡ |  |¡}|  	t
||¡ |  	t
|j|¡ W d Q R X W d Q R X d S )Nr   F)r.   r‚   r   r   rò  r	   rµ  rª  rO  rç   r3  r³  )r2   rá  rQ  r(   rR  r   r   r   Ú_testNonBlocking/  s    


z&SendfileUsingSendTest._testNonBlockingc             C   s    |   ¡ }| d¡r|  d¡ d S )Ni    z$was not supposed to receive any data)rM  r‘   rä   )r2   rŒ   r   r   r   ÚtestNonBlocking8  s    
z%SendfileUsingSendTest.testNonBlockingc          
   C   sd   | j  ¡ }ttjdƒ}tj|dd6}|&}|  |¡}||ƒ}|  || j	¡ W d Q R X W d Q R X d S )Nr   r„   )rv  )
r.   r‚   r   r   rò  r	   rµ  rO  r’   rG  )r2   rá  rQ  r(   rR  rS  r   r   r   Ú_testWithTimeout?  s    

z&SendfileUsingSendTest._testWithTimeoutc             C   s6   |   ¡ }|  |¡}|  t|ƒ| j¡ |  || j¡ d S )N)rM  rN  r’   rb  rG  rH  )r2   rŒ   rØ  r   r   r   ÚtestWithTimeoutG  s    
z%SendfileUsingSendTest.testWithTimeoutc          
   C   s`   | j  ¡ }ttjdƒ@}t |¡*}| d¡ |  |¡}|  	tj
||¡ W d Q R X W d Q R X d S )Nr   g{®Gáz„?)r.   r‚   r   r   rò  r	   rµ  rO  rO  rç   rv  )r2   rá  rQ  r(   rR  r   r   r   Ú_testWithTimeoutTriggeredSendO  s    


z3SendfileUsingSendTest._testWithTimeoutTriggeredSendc             C   s   |   ¡ }| d¡ d S )Ni€X )rM  r‘   )r2   rŒ   r   r   r   ÚtestWithTimeoutTriggeredSendW  s    z2SendfileUsingSendTest.testWithTimeoutTriggeredSendc             C   s   d S )Nr   )r2   r   r   r   Ú_test_errors]  s    z"SendfileUsingSendTest._test_errorsc          
   C   s  t tjdƒ:}tjtjd }|  |¡}|  td||¡ W d Q R X W d Q R X t tjdƒ4}t ¡  }|  |¡}|  td||¡ W d Q R X W d Q R X t tjdƒt}t ¡ `}|  |¡}| jtd||dd | jtd||d	d | jtd||d
d | jtd||dd W d Q R X W d Q R X d S )Nr   )rÂ   r-   r  zbinary modezpositive integerrZ  )rV  gš™™™™™¹?r   r  )	r   r   rò  r	   r   rO  r  r3  rv   )r2   rQ  r   rR  r   r   r   Útest_errors`  s*    
 

 

z!SendfileUsingSendTest.test_errorsN)$r5   r6   r7   rD   rG  rF  rH  rL  rñ  rJ  rK  rM  rN  rO  rT  rU  rX  rY  r\  r]  r_  r`  ra  rb  rc  rd  re  rf  rg  rh  ri  rj  rk  rl  rm  rn  r   r   r   r   r@  w  s@   		
	
	
	
		r@  r³  z%os.sendfile() required for this test.c               @   s   e Zd ZdZdd„ ZdS )ÚSendfileUsingSendfileTestzB
    Test the sendfile() implementation of socket.sendfile().
    c             C   s
   t |dƒS )Nr¸  )rh   )r2   r(   r   r   r   rO  ~  s    z(SendfileUsingSendfileTest.meth_from_sockN)r5   r6   r7   rD   rO  r   r   r   r   ro  x  s   ro  zAF_ALG requiredc               @   s|   e Zd Zdd„ Ze dd¡dd„ ƒZdd„ Ze dd	¡d
d„ ƒZe dd¡dd„ ƒZ	e dd	¡dd„ ƒZ
dd„ Zdd„ ZdS )ÚLinuxKernelCryptoAPIc          
   C   sj   t   t jt jd¡}y| ||f¡ W n< tk
r` } z| ¡  t t|ƒ||¡‚W d d }~X Y nX |S d S )Nr   )	r	   r    r   rK   r  r   r†   ZSkipTestrÐ   )r2   ÚtyprÊ   r(   rw   r   r   r   Ú
create_alg…  s    $zLinuxKernelCryptoAPI.create_algrí   rT  c          
   C   sÀ   t  d¡}|  dd¡ }| ¡ \}}|" | d¡ |  | d¡|¡ W d Q R X | ¡ \}}|L | dtj	¡ | dtj	¡ | dtj	¡ | d	¡ |  | d¡|¡ W d Q R X W d Q R X d S )
NZ@ba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015adÚhashZsha256s   abci   ó   aó   bó   cr¿   )
rí  Úfromhexrr  r‹   rt  r’   r‘   r–   r	   ÚMSG_MORE)r2   rá   ÚalgoÚopr]   r   r   r   Útest_sha256’  s    


z LinuxKernelCryptoAPI.test_sha256c          
   C   sp   t  d¡}|  dd¡P}| tjtjd¡ | ¡ \}}|" | d¡ |  	| 
d¡|¡ W d Q R X W d Q R X d S )NZ(effcdf6ae5eb2fa2d27416d5f184df9c259a7c79rs  z
hmac(sha1)s   Jefes   what do ya want for nothing?i   )rí  rw  rr  rM  r	   ÚSOL_ALGÚALG_SET_KEYr‹   rt  r’   r‘   )r2   rá   ry  rz  r]   r   r   r   Útest_hmac_sha1¤  s    

z#LinuxKernelCryptoAPI.test_hmac_sha1r  c          
   C   s¼  t  d¡}t  d¡}d}t  d¡}t|ƒ}|  dd¡z}| tjtj|¡ | ¡ \}}|6 |j	tj
|tjd | |¡ |  | |¡|¡ W d Q R X | ¡ \}}|, |j	|gtj|d |  | |¡|¡ W d Q R X d	}	|g|	 }
| ¡ \}}|& |j	|
tj
|d | ||	 ¡}W d Q R X |  t|ƒ||	 ¡ |  |d |… |¡ | ¡ \}}|( |j	|gtj|d | ||	 ¡}W d Q R X |  t|ƒ||	 ¡ |  |||	 ¡ W d Q R X d S )
NZ 06a9214036b8a15b512e03d534120006Z 3dafba429d9eb430b422da802c9fac41s   Single block msgZ e353779c1079aeb82708942dbe77181aZskcipherzcbc(aes))rz  Úivr_  )rz  r  i   )rí  rw  rb  rr  rM  r	   r|  r}  r‹   Úsendmsg_afalgÚALG_OP_ENCRYPTrx  rt  r’   r‘   ÚALG_OP_DECRYPT)r2   Úkeyr  r”   Z
ciphertextZmsglenry  rz  r]   Z
multiplierZlongmsgÚencZdecr   r   r   Útest_aes_cbc¯  sD    






z!LinuxKernelCryptoAPI.test_aes_cbcr   c             C   s²  t  d¡}t  d¡}t  d¡}t  d¡}t  d¡}t  d¡}t|ƒ}t|ƒ}|  dd¡N}	|	 tjtj|¡ |	 tjtjd |¡ |	 	¡ \}
}|
v |
j
tj||tjd	 |
 |tj¡ |
 |¡ |
 |t|ƒ | ¡}|  |||| … ¡ |  ||| d … ¡ W d Q R X |	 	¡ \}
}|
f || }|
j
|gtj||d
 |
 |t|ƒ | ¡}|  |||| … ¡ |  ||| d … ¡ W d Q R X t d¡j}|	 	¡ \}
}|
” || }|
 |gtjtj|tjƒgtjtj|t|ƒƒ| gtjtj||ƒgf¡ |
 t|ƒ| ¡}|  |||| … ¡ |  ||| d … ¡ W d Q R X |	 	¡ \}
}|
N || | }|
j
|gtj||d
 |
 t|ƒ| ¡}|  |||d … ¡ W d Q R X W d Q R X d S )NZ c939cc13397c1d37de6ae0e1cb7c423cZb3d8cc017cbb89b39e0f67e2Z c3b3c41f113a31b73d9a5cd432103069Z 24825602bd12a984e0092d3e448eda5fZ 93fe7d9e9bfd10348a5606e5cafa7354Z 0032a1dc85f1c9786925a2e71d8272ddZaeadzgcm(aes))rz  r  Úassoclenr_  )rz  r  r†  r   )rí  rw  rb  rr  rM  r	   r|  r}  ZALG_SET_AEAD_AUTHSIZEr‹   r€  r  rx  rt  r‘   r’   r   ÚStructrÑ  r   Z
ALG_SET_OPZ
ALG_SET_IVZALG_SET_AEAD_ASSOCLENr‚  )r2   rƒ  r  ZplainZassocZexpected_ctZexpected_tagZtaglenr†  ry  rz  r]   Zresr”   Zpack_uint32r   r   r   Útest_aead_aes_gcmØ  s`    







   z&LinuxKernelCryptoAPI.test_aead_aes_gcmc          
   C   sn   |   dd¡X}t d¡}| tjtj|¡ | ¡ \}}|  | d¡}|  	t
|ƒd¡ W d Q R X W d Q R X d S )NÚrngZdrbg_pr_sha256r  )rr  r&   ÚurandomrM  r	   r|  r}  r‹   r‘   r’   rb  )r2   ry  Z
extra_seedrz  r]   Zrnr   r   r   Útest_drbg_pr_sha256  s    

z(LinuxKernelCryptoAPI.test_drbg_pr_sha256c          
   C   sÒ   t   t jt jd¡}|² |  t¡ | ¡  W d Q R X |  t¡ |jd d W d Q R X |  t¡ | d¡ W d Q R X |  t¡ |jt jd d W d Q R X |  t¡ |jt jdd W d Q R X W d Q R X d S )Nr   )rz  r[   )rz  r†  r  )r	   r    r   rç   rv   r€  r  )r2   r(   r   r   r   Útest_sendmsg_afalg_args"  s    z,LinuxKernelCryptoAPI.test_sendmsg_afalg_argsc          	   C   s¦   t   t jt jd¡}|  |j¡ |  t¡ | d¡ W d Q R X |  t	d¡ | d¡ W d Q R X |  t¡ | d¡ W d Q R X |  t	d¡ | d¡ W d Q R X d S )Nr   )ZtttttttttttttrÊ   ztype too long)ZttttttttttttttrÊ   )rÂ   Z?nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnzname too long)rÂ   Z@nnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnnn)
r	   r    r   rB   r   rç   r  rK   r  r3  )r2   r(   r   r   r   Útest_length_restriction4  s    z,LinuxKernelCryptoAPI.test_length_restrictionN)r5   r6   r7   rr  r   rw  r{  r~  r…  rˆ  r‹  rŒ  r  r   r   r   r   rp  ‚  s   )?rp  Úwinzrequires Windowsc               @   s$   e Zd ZddddddhZdd„ Zd	S )
ÚTestMSWindowsTCPFlagsZ
TCP_MAXSEGZTCP_NODELAYZTCP_FASTOPENZTCP_KEEPCNTZTCP_KEEPIDLEZTCP_KEEPINTVLc                s6   dd„ t tƒD ƒ}‡ fdd„|D ƒ}ˆ  g |d¡ d S )Nc             S   s   g | ]}|  d ¡r|‘qS )ZTCP)r,  )rÉ   r   r   r   r   rË   V  s    z<TestMSWindowsTCPFlags.test_new_tcp_flags.<locals>.<listcomp>c                s   g | ]}|ˆ j kr|‘qS r   )ÚknownTCPFlags)rÉ   r   )r2   r   r   rË   W  s    zANew TCP flags were discovered. See bpo-32394 for more information)r­   r	   r’   )r2   ZprovidedÚunknownr   )r2   r   Útest_new_tcp_flagsU  s    z(TestMSWindowsTCPFlags.test_new_tcp_flagsN)r5   r6   r7   r  r’  r   r   r   r   r  F  s   r  c              C   s  t ttttttttg	} |  	t
tttttttttttttg¡ |  t¡ |  t¡ |  t¡ |  	ttg¡ |  	ttg¡ |  	t t!g¡ |  t"¡ |  	t#t$g¡ |  	t%t&t't(t)t*t+t,t-t.t/t0t1t2t3t4t5t6t7t8t9t:t;t<t=g¡ |  t>¡ t? @¡ }t?jA| Ž  t?jB|Ž  d S )N)CrÕ   r  rY  rÍ  rÛ  rù  r¶  r*  rÙ  Úextendrc  rx  r¢  r¯  r°  r±  r²  r³  r·  r¿  rÉ  r  r  r(  r²  r]  rì  rß  r  r  rÃ  rÔ  rõ  r÷  rp  r	  r…   r¤  r(  r)  r*  r,  r-  r/  r0  r.  r2  r3  r4  r6  r7  r9  r;  r<  r=  r>  r?  rG  rQ  r.  r@  ro  r  r   Zthreading_setupZrun_unittestZthreading_cleanup)ZtestsÚthread_infor   r   r   Ú	test_main\  sr    





r•  Ú__main__)²r†   Ztestr   r   rV  rU  r	   r  r©   rŽ   rÖ  rc   r  r&   r]  r½  Úweakrefr   rq  rl  r’  r   rC  r¾  rE  Ú_threadri   r<   r2  r?  r   r   r±  r“   rr  rŠ   rÖ   r   r   r   r   r!   r#   r)   ZHAVE_SOCKET_CANZHAVE_SOCKET_CAN_ISOTPZHAVE_SOCKET_RDSZHAVE_SOCKET_ALGZHAVE_SOCKET_VSOCKr¨  rÁ  r‡   r+   r8   r9   rF   rR   rS   rz   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÷  r	  r  r*  r/  rG  rL  rO  rP  rR  rS  rT  rn  rv  ry  r  r”  r—  r¤  r¯  ró  r'  r(  r)  r*  r+  rc  r,  r-  r.  r/  r0  r1  r2  r3  r4  r5  r6  r7  r9  r:  r;  r<  r=  r>  r?  r@  ru   rG  rQ  rY  r]  rc  rx  r¢  r¯  r°  r±  r²  r³  rb  r´  r¶  r·  r¿  rÉ  rÍ  rÙ  rÛ  r+  rß  rì  rù  r  r  r  r  r  r  r  r  r(  rÊ   r.  r@  ro  rp  r,  r  r•  r5   r   r   r   r   Ú<module>   s:  








3u!#	
        
D[
*
?.{7ww= #P;  k   7




















	 )5# 4 $l


	8E9
)
ES
',C
<
e  
 D&
A