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 )NFT)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 )NFT)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 )Nr   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 )Nr   FT)r	   ÚAF_ALGr   r   r   r   )r   r   r   r   Ú_have_socket_algX   s    r!   c              C   s   t ƒ d k	} | S )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                   s4   e Zd Z‡ fdd„Z‡ fdd„Z‡ fdd„Z‡  ZS )ÚThreadSafeCleanupTestCasec                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   r;   rB   rC   Ú__classcell__r   r   )rA   r   r9      s   r9   c               @   sD   e 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 )
ÚSocketCANTestÚ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   rK   ÚbufsizeÚcan_frame_fmtr   ÚcalcsizeZcan_frame_sizeÚbcm_cmd_msg_fmtr3   r   r   r   r   rE   ¢   s   

rE   c               @   s   e Zd ZdZdd„ ZdS )ÚSocketRDSTesti    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   rL   )r2   r   r   r   r3   Ü   s    zSocketRDSTest.setUpN)r5   r6   r7   rM   r3   r   r   r   r   rQ   Õ   s   rQ   c               @   sD   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S )ÚThreadableTestc             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 )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<   ÚEventrW   Úclient_readyÚdoneÚqueueÚQueueÚserver_crashedÚidÚrfindÚgetattrÚthreadÚstart_new_threadÚ	clientRunZclient_threadrS   rX   Úwait)r2   Z
methodnamer*   Ztest_methodr   r   r   rU     s(    





zThreadableTest._setUpc             C   s>   |   ¡  | j ¡  | j d d d ¡ | j ¡ r:| j ¡ }|‚d S )N)rT   ra   rk   r]   Ú__exit__rb   ZqsizeÚget)r2   Úexcr   r   r   rV   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)rW   rk   ÚclientSetUpÚBaseExceptionrb   ÚputÚclientTearDownr`   rX   rd   ÚhasattrÚ	TypeError)r2   Z	test_funcÚer   r   r   rj   =  s$    


"zThreadableTest.clientRunc             C   s   t dƒ‚d S )Nz clientSetUp must be implemented.)ÚNotImplementedError)r2   r   r   r   rp   S  s    zThreadableTest.clientSetUpc             C   s   | j  ¡  t ¡  d S )N)ra   rX   rh   Úexit)r2   r   r   r   rs   V  s    
zThreadableTest.clientTearDownN)
r5   r6   r7   r;   rY   rU   rV   rj   rp   rs   r   r   r   r   rR   å   s   &	rR   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;   rR   )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   rp   `  s    z!ThreadedTCPSocketTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r|   r   rR   rs   )r2   r   r   r   rs   c  s    
z$ThreadedTCPSocketTest.clientTearDownN)rz   )r5   r6   r7   r;   rp   rs   r   r   r   r   ry   Z  s   
ry   c               @   s&   e Zd Zd	dd„Zdd„ Zdd„ ZdS )
ÚThreadedUDPSocketTestrz   c             C   s   t j| |d t | ¡ d S )N)r{   )r8   r;   rR   )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   rp   n  s    z!ThreadedUDPSocketTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r|   r   rR   rs   )r2   r   r   r   rs   q  s    
z$ThreadedUDPSocketTest.clientTearDownN)rz   )r5   r6   r7   r;   rp   rs   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 )
ÚThreadedCANSocketTestrz   c             C   s   t j| |d t | ¡ d S )N)r{   )rE   r;   rR   )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|   rJ   rK   r   )r2   r   r   r   rp   |  s
    z!ThreadedCANSocketTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r|   r   rR   rs   )r2   r   r   r   rs   …  s    
z$ThreadedCANSocketTest.clientTearDownN)rz   )r5   r6   r7   r;   rp   rs   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 )
ÚThreadedRDSSocketTestrz   c             C   s   t j| |d t | ¡ d S )N)r{   )rQ   r;   rR   )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|   rJ   ÚHOSTÚgetsocknameÚcli_addrr   )r2   r   r   r   rp     s    z!ThreadedRDSSocketTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r|   r   rR   rs   )r2   r   r   r   rs   ›  s    
z$ThreadedRDSSocketTest.clientTearDownN)rz   )r5   r6   r7   r;   rp   rs   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 )ÚThreadedVSOCKSocketStreamTestrz   c             C   s   t jj| |d t | ¡ d S )N)r{   )ÚunittestÚTestCaser;   rR   )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   rJ   ÚVMADDR_CID_ANYÚ	VSOCKPORTr1   rY   Ú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   rp   ´  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)rz   )r5   r6   r7   r;   r3   rp   r”   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 )ÚSocketConnectedTestrz   c             C   s   t j| |d d S )N)r{   )ry   r;   )r2   r{   r   r   r   r;   Ê  s    zSocketConnectedTest.__init__c             C   s*   t  | ¡ |  ¡  | j ¡ \}}|| _d S )N)ry   r3   rY   r.   rŠ   Úcli_conn)r2   r‹   Úaddrr   r   r   r3   Í  s    
zSocketConnectedTest.setUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r˜   r   ry   r4   )r2   r   r   r   r4   Õ  s    
zSocketConnectedTest.tearDownc             C   s(   t  | ¡ | j t| jf¡ | j| _d S )N)ry   rp   r|   r   r€   r0   Ú	serv_conn)r2   r   r   r   rp   Ú  s    
zSocketConnectedTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)rš   r   ry   rs   )r2   r   r   r   rs   ß  s    
z"SocketConnectedTest.clientTearDownN)rz   )r5   r6   r7   r;   r3   r4   rp   rs   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 )ÚSocketPairTestrz   c             C   s   t jj| |d t | ¡ d S )N)r{   )r…   r†   r;   rR   )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   rp   ñ  s    zSocketPairTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r|   r   rR   rs   )r2   r   r   r   rs   ô  s    
zSocketPairTest.clientTearDownN)rz   )r5   r6   r7   r;   r3   r4   rp   rs   r   r   r   r   r›   ä  s
   
r›   c               @   s$   e Zd Zdd„ Zdd„ Zdd„ ZdS )ÚSocketTestBasec             C   s   |   ¡ | _|  ¡  d S )N)Ú	newSocketr.   Ú
bindServer)r2   r   r   r   r3   	  s    
zSocketTestBase.setUpc             C   s   |   | j¡ | j ¡ | _d S )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   r3   rŸ   r4   r   r   r   r   r      s   	r   c                   s   e Zd Z‡ fdd„Z‡  ZS )ÚSocketListeningTestMixinc                s   t ƒ  ¡  | j ¡  d S )N)r:   r3   r.   r1   )r2   )rA   r   r   r3     s    
zSocketListeningTestMixin.setUp)r5   r6   r7   r3   rD   r   r   )rA   r   r¢     s   r¢   c                   s<   e Zd Z‡ fdd„Zdd„ Zdd„ Zdd„ Zd	d
„ Z‡  ZS )ÚThreadedSocketTestMixinc                s   t ƒ j||Ž t | ¡ d S )N)r:   r;   rR   )r2   r?   r@   )rA   r   r   r;   '  s    z ThreadedSocketTestMixin.__init__c             C   s   |   ¡ | _|  ¡  d S )N)ÚnewClientSocketr|   Ú
bindClient)r2   r   r   r   rp   +  s    
z#ThreadedSocketTestMixin.clientSetUpc             C   s   |   ¡ S )N)rž   )r2   r   r   r   r¤   /  s    z'ThreadedSocketTestMixin.newClientSocketc             C   s   |   | j¡ | j ¡ | _d S )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   rR   rs   )r2   r   r   r   rs   8  s    
z&ThreadedSocketTestMixin.clientTearDown)	r5   r6   r7   r;   rp   r¤   r¥   rs   rD   r   r   )rA   r   r£     s
   r£   c                   s@   e Zd Z‡ fdd„Z‡ fdd„Z‡ fdd„Z‡ fdd„Z‡  ZS )	ÚConnectedStreamTestMixinc                s*   t ƒ  ¡  |  ¡  | j ¡ \}}|| _d S )N)r:   r3   rY   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:   rp   r|   r   r¡   rš   )r2   )rA   r   r   rp   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:   rs   )r2   )rA   r   r   rs   Y  s    

z'ConnectedStreamTestMixin.clientTearDown)r5   r6   r7   r3   r4   rp   rs   rD   r   r   )rA   r   r¦   >  s   	r¦   c                   s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )ÚUnixSocketTestBasec                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   r3   r    rD   r   r   )rA   r   r§   b  s   r§   c               @   s   e Zd Zdd„ ZdS )ÚUnixStreamBasec             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   rž   r   r   r   r   r°   t  s   r°   c                   s(   e Zd ZeZ‡ fdd„Zdd„ Z‡  ZS )ÚInetTestBasec                s   t ƒ  ¡  | jd | _d S )NrZ   )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   r€   r³   r3   r    rD   r   r   )rA   r   r²   {  s   r²   c               @   s   e Zd Zdd„ ZdS )ÚTCPTestBasec             C   s   t   t jt j¡S )N)r	   r,   r-   )r2   r   r   r   rž   Š  s    zTCPTestBase.newSocketN)r5   r6   r7   rž   r   r   r   r   r´   ‡  s   r´   c               @   s   e Zd Zdd„ ZdS )ÚUDPTestBasec             C   s   t   t jt j¡S )N)r	   r,   r   )r2   r   r   r   rž     s    zUDPTestBase.newSocketN)r5   r6   r7   rž   r   r   r   r   rµ     s   rµ   c               @   s   e Zd Zdd„ ZdS )ÚSCTPStreamBasec             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   rž   r   r   r   r   r¶   “  s   r¶   c               @   s   e Zd ZejZdS )ÚInet6TestBaseN)r5   r6   r7   r   ÚHOSTv6r³   r   r   r   r   r¸   ›  s   r¸   c               @   s   e Zd Zdd„ ZdS )ÚUDP6TestBasec             C   s   t   t jt j¡S )N)r	   ÚAF_INET6r   )r2   r   r   r   rž   £  s    zUDP6TestBase.newSocketN)r5   r6   r7   rž   r   r   r   r   rº      s   rº   c                s*   dd„ ‰ ‡ ‡fdd„}dd„ }| r&|S |S )Nc              _   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Á   rt   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 )Nc                s   g | ]}t ˆ |ƒs|‘qS r   )rt   )Ú.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 )
Nc             S   s$   g | ]}t |tƒrtt|ƒs|‘qS r   )rÀ   Ústrrt   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Ï   rg   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   rv   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ÚassertNotInrJ   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   rJ   r   ræ   ru   Ú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   rL   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EPERMrL   r‘   )r2   Zoldhnrv   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  ru   )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	   Úgetnameinforu   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)rH   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é    é   rZ   )r   rZ   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   rZ   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   rt   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æ   Ú
ValueErrorru   )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	   r4  )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   )r4  r6  r,   c                s
   ˆˆ | ƒS )Nr   )Úa)r,   r6  r   r   r½   C  r¾   z5GeneralModuleTests.testIPv4toString.<locals>.<lambda>c                s   ˆ   ttf| |¡S )N)ræ   r   r2  )r  r7  )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	   r4  r6  r,   r‘   r  r*  r+  )r2   r   ÚgÚassertInvalidr   )r,   r6  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   )r6  r»   Úhas_ipv6zIPv6 not availablez+could not import needed symbols from socketÚwin32z::i&'  zIPv6 might not be supportedc                s
   ˆˆ | ƒS )Nr   )r7  )r»   r6  r   r   r½   q  r¾   z5GeneralModuleTests.testIPv6toString.<locals>.<lambda>c                s   ˆ  ttfˆ | ¡S )N)ræ   r   r2  )r7  )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:0r8  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	   r6  r»   r<  rL   ÚImportErrorr  r*  r   Úwinerrorr‘   r+  )r2   r<  rv   r:  r   )r»   r   r6  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_ntoarA  r,   c                s
   ˆˆ | ƒS )Nr   )r7  )r,   rA  r   r   r½   ¤  r¾   z5GeneralModuleTests.testStringToIPv4.<locals>.<lambda>c                s   ˆ   ttf| |¡S )N)ræ   r   r2  )r  r7  )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	   rB  rA  r,   r‘   Ú	bytearray)r2   r   r9  r:  r   )r,   rA  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   )rA  r»   r<  zIPv6 not availablez+could not import needed symbols from socketr=  s                   i&'  zIPv6 might not be supportedc                s
   ˆˆ | ƒS )Nr   )r7  )r»   rA  r   r   r½   Ë  r¾   z5GeneralModuleTests.testStringToIPv6.<locals>.<lambda>c                s   ˆ  ttfˆ | ¡S )N)ræ   r   r2  )r7  )r   r2   r   r   r½   Ì  s   z::z::1s                  z!aef:b01:506:1001:ffff:9997:55:170s   
ïÿÿ™— Ups   s   s   )r	   rA  r»   r<  rL   r>  r  r*  r   r?  r‘   rC  )r2   r<  rv   r:  r   )r»   r   rA  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 invalidrZ   )r   Úfind_unused_portr	   r,   r-   rB   r   rJ   r   rö   rõ   r   rL   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 )NrZ   r   zfailed to set reuse mode)
r	   r,   r-   rB   r   Ú
setsockoptrò   ró   rH  rI  )r2   r(   rJ  r   r   r   ÚtestSetSockOptø  s
    z!GeneralModuleTests.testSetSockOptc             C   s6   t   t jt j¡}| d¡ | ¡  |  t|jd¡ d S )NrZ   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	   rJ   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Þ   rt   rÙ   rÁ   rQ  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   rF  ræ   r  rJ   r€   Ú	itertoolsÚcountr   rÿ   Z
EADDRINUSE)r2   r(   r0   Zbig_portZneg_portr*   rv   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  )rZ   éd   rY  )	rÖ   rt   r	   rB   r   ræ   r2  r   rX  )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?  rL   ræ   ru   )r2   r   rn   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 versionrS  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_SERVICErL   r€   r‘   Úlenr   ÚIPV6_ENABLEDrt   r  r(  r,   r-   rÏ   ZSOL_TCPZ
AI_PASSIVEÚ	AF_UNSPECræ   ÚUnicodeEncodeErrorr_  )
r2   rÒ   ÚinfoZinfosrÞ   rÁ   r\   Zsocktyper7  Ú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_exr`  rc  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æ   r2  Ú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   rZ   )ræ   r2  rk  rl  )r?   )r2   r   r   Úraising_handler¼  s    zEGeneralModuleTests.check_sendall_interrupted.<locals>.raising_handlerg      ø?rZ   ó   xr   )rt   Úsignalr	   rL   rœ   ÚSIGALRMrN  ræ   ÚZeroDivisionErrorrj  Úsendallr   ÚSOCK_MAX_SIZEÚtimeoutr   )r2   Zwith_timeoutrm  rn  Úcr   Ú	old_alarmr   )r2   r   Úcheck_sendall_interrupted´  s*    




z,GeneralModuleTests.check_sendall_interruptedc             C   s   |   d¡ d S )NF)rx  )r2   r   r   r   Útest_sendall_interruptedÓ  s    z+GeneralModuleTests.test_sendall_interruptedc             C   s   |   d¡ d S )NT)rx  )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Ö   ÚreadablerI  ÚwritableÚseekabler   ræ   r2  )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   rZ   r  )	r	   rJ   r€   r   rÚ   ræ   r   r1   ru   )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)ÚrtrH   ú+r7  )r‰  zinvalid mode)rŠ  r	   ÚassertRaisesRegexr2  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 )NrZ   )r	   ÚrangeÚpickleZHIGHEST_PROTOCOLræ   ru   Ú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-   rJ   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   rZ   )r  r	   r,   r-   rJ   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-   rJ   )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	   r`  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  r`  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	   r`  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   rQ  rZ   TF)rg   r	   r-   r,   r‘   rÁ   rN  Úsetblocking)r2   r¨  rQ  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 )NrZ   c             s   s   | ]\}}|d kr|V  qdS )>   rQ  r¨  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  ru   )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   rJ   r   r€   r¼  rt   r   rb  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ü   rt   r	   r   r  r	  r  r  r  r  r   Úcpython_onlyr#  r-  r3  r5  r;  r@  rD  rE  rG  rK  rM  rO  rP  rR  rV  r&   rÉ   rZ  r\  rg  rh  Zis_resource_enabledri  rx  ry  rz  r}  r  r„  r…  r‹  r  r”  r–  r—  rb  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   rJ   )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   rJ   )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   rZ   )	r	   r   r   r   rL  ÚSOL_CAN_RAWrÌ  r‘   rH  )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=IIrI   )r   Úpackr	   r   r   r   rL  rÍ  rÏ  r‘   rH  rC  )r2   Úcan_idZcan_maskZ
can_filterr   r   r   r   Ú
testFilter&  s    zBasicCANTest.testFilterN)r5   r6   r7   rô   r…   r¿  rt   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 )ÚCANTestrz   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 )NrI   ó    )ra  Úljustr   rÐ  rN   )ÚclsrÑ  ÚdataÚcan_dlcr   r   r   Úbuild_can_frame8  s    zCANTest.build_can_framec             C   s&   t  | j|¡\}}}|||d |… fS )N)r   r   rN   )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   rZ   )r   ÚrecvfromrM   r‘   ÚcfrK   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Ü  rM   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Ü  rM   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Ü  rM   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||||||||	|
¡
}|| j }| |¡}|  |t|ƒ¡ d S )Ni#  éÀ   éÿ   éî   r   i"  rZ   )r	   r   r   rÄ  rB   r   r   rK   rÑ  Úbytesr×  rÙ  rÝ  rÅ  r   rÐ  rP   r•   r‘   ra  )r2   ZbcmZopcoder^  rU  Zival1_secondsZ
ival1_usecZival2_secondsZ
ival2_usecZ
bcm_can_idZnframesÚheaderZheader_plus_frameZ
bytes_sentr   r   r   ÚtestBCMn  s2    

zCANTest.testBCMN)rz   )r5   r6   r7   r;   ÚclassmethodrÙ  rÛ  rÞ  rß  rà  rá  rä  rç  r…   r¿  rt   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 )NrF   )r:   r;   rK   )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Ê  rZ   rƒ   )r	   r   r   r   rŽ  r   rJ   )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   rK   rJ   r‘   r   r   rÿ   ZENODEVrL   )r2   r   r™   rv   r   r   r   ÚtestBind«  s    
zISOTPTest.testBind)r5   r6   r7   r;   rô   rÇ  r…   r¿  rt   r	   rñ  rË  rò  rD   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   rL  rò   Z	SO_RCVBUFZ	SO_SNDBUF)r2   rM   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 )ÚRDSTestrz   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Ü  rM   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Ü  rM   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û  rM   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Ü  rM   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Ü  rM   r‘   r×  )r2   r   r‡  rH   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)rz   )r5   r6   r7   r;   r3   rö  r÷  rù  rú  rÎ   r	   rý  rÿ  r  r  r  r  rD   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-   rH  r
  r  r	  rL  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 ),ÚBasicTCPTestrz   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   ra  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Ü  ra  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š   rs  )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’   ra   rk   )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   rZ   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)rz   )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 )ÚBasicUDPTestrz   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   ra  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Ü  ra  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æ   r2  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)rz   )
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)r/  rþ  Úsendmsg_to_server_defaultsra  )r2   r?   r   r   r   ÚsendmsgToServer	  s    zSendrecvmsgBase.sendmsgToServerc             G   s   |j |f|žŽ }|  |¡ |S )N)rû  ÚregisterRecvmsgResult)r2   r(   rM   r?   Úresultr   r   r   Ú	doRecvmsg		  s    
zSendrecvmsgBase.doRecvmsgc             C   s   d S )Nr   )r2   r4  r   r   r   r3  	  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   r0  r1  r2  r5  r3  r8  r;  rÉ   rg   r	   r:  r<  r=  rC  rD   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   rZ   )rC  Úrecvmsg_intor3  ÚassertGreaterEqualÚassertLessEqualrì  )r2   r(   rM   r?   Úbufr4  r   r   r   r5  h	  s    
zRecvmsgIntoMixin.doRecvmsgN)r5   r6   r7   r5  r   r   r   r   rE  e	  s   rE  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=  rD   r   r   )rA   r   rJ  q	  s   rJ  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   rL  r<  rD   r   r   )rA   r   rM  y	  s   rM  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   r/  Š	  s    z&SendrecvmsgConnectionlessBase.cli_sockc             C   s   g g d| j fS )Nr   )r¡   )r2   r   r   r   r1  Ž	  s    z8SendrecvmsgConnectionlessBase.sendmsg_to_server_defaultsc             C   s   | j  || j¡S )N)r/  rí   r¡   )r2   r“   r   r   r   r0  ’	  s    z*SendrecvmsgConnectionlessBase.sendToServerN)r5   r6   r7   rL  rO  r/  r1  r0  r   r   r   r   rN  	  s   rN  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   rO  œ	  s    z"SendrecvmsgConnectedBase.serv_sockc             C   s   | j S )N)rš   )r2   r   r   r   r/   	  s    z!SendrecvmsgConnectedBase.cli_sockc             C   s   d S )Nr   )r2   r6  r7  r   r   r   r8  ¤	  s    z,SendrecvmsgConnectedBase.checkRecvmsgAddressN)r5   r6   r7   rL  rO  r/  r8  r   r   r   r   rP  –	  s   rP  c                   s   e Zd Z‡ fdd„Z‡  ZS )ÚSendrecvmsgServerTimeoutBasec                s   t ƒ  ¡  | j | j¡ d S )N)r:   r3   rO  rN  rD  )r2   )rA   r   r   r3   ­	  s    
z"SendrecvmsgServerTimeoutBase.setUp)r5   r6   r7   r3   rD   r   r   )rA   r   rQ  ª	  s   rQ  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‘   rO  r   ra  r’   )r2   r   r   r   ÚtestSendmsg¶	  s    zSendmsgTests.testSendmsgc             C   s   |   |  tg¡ttƒ¡ d S )N)r‘   r2  r’   ra  )r2   r   r   r   Ú_testSendmsgº	  s    zSendmsgTests._testSendmsgc             C   s   |   | j ttƒ¡t¡ d S )N)r‘   rO  r   ra  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‘   r2  r’   ra  )r2   r   r   r   Ú_testSendmsgDataGeneratorÁ	  s    z&SendmsgTests._testSendmsgDataGeneratorc             C   s   |   | j ttƒ¡t¡ d S )N)r‘   rO  r   ra  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‘   r2  r’   ra  )r2   r   r   r   Ú_testSendmsgAncillaryGeneratorÉ	  s    z+SendmsgTests._testSendmsgAncillaryGeneratorc             C   s   |   | j ttƒ¡t¡ d S )N)r‘   rO  r   ra  r’   )r2   r   r   r   ÚtestSendmsgArrayÍ	  s    zSendmsgTests.testSendmsgArrayc             C   s$   |   |  t dt¡g¡ttƒ¡ d S )NÚB)r‘   r2  Úarrayr’   ra  )r2   r   r   r   Ú_testSendmsgArrayÑ	  s    zSendmsgTests._testSendmsgArrayc             C   s   |   | j ttƒ¡t¡ d S )N)r‘   rO  r   ra  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‘   r2  r’   ra  )r2   r   r   r   Ú_testSendmsgGatherÙ	  s    zSendmsgTests._testSendmsgGatherc             C   s   |   | j d¡d¡ d S )Niè  s   done)r‘   rO  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æ   ru   r/  rþ  r2  Úobjectr’   r0  )r2   r   r   r   Ú_testSendmsgBadArgsà	  s     







z SendmsgTests._testSendmsgBadArgsc             C   s   |   | j d¡d¡ d S )Niè  s   done)r‘   rO  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æ   ru   r2  r’   r`  r0  )r2   r   r   r   Ú_testSendmsgBadCmsgö	  s    





z SendmsgTests._testSendmsgBadCmsgÚ
CMSG_SPACEc             C   s   |   | j d¡d¡ d S )Niè  s   done)r‘   rO  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æ   ru   r2  r’   r`  r0  )r2   r   r   r   Ú_testSendmsgBadMultiCmsg
  s
    

z%SendmsgTests._testSendmsgBadMultiCmsgc             C   s   |   | j d¡d¡ d S )Niè  s   done)r‘   rO  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 )Nrd  )r   r   r¾   s   done)
rt   r	   ræ   r   r2  r’   ÚassertIsNonerî   rÿ   r0  )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)r/  r   ræ   r   r2  r’   )r2   r   r   r   Ú_testSendmsgAfterClose$
  s    
z#SendmsgTests._testSendmsgAfterCloseN)r5   r6   r7   rS  rT  rU  rV  rW  rX  rY  r\  r]  r^  r_  ra  rb  rc  rÎ   r	   re  rÂ   rf  rg  ri  rj  rk  r   r   r   r   rR  ²	  s(   rR  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‘   rO  r   ra  r’   )r2   r   r   r   ÚtestSendmsgExplicitNoneAddr-
  s    z.SendmsgStreamTests.testSendmsgExplicitNoneAddrc             C   s"   |   |  tgg dd ¡ttƒ¡ d S )Nr   )r‘   r2  r’   ra  )r2   r   r   r   Ú_testSendmsgExplicitNoneAddr1
  s    z/SendmsgStreamTests._testSendmsgExplicitNoneAddrc             C   s.   |   | j d¡d¡ |  | jj| jd¡ d S )Ni   s   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)ru  )r‘   rO  r   rÖ   r.  rk   rD  )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)r/  rN  r2  r	   ru  r   rÿ   ÚENOMEMrã   r.  rX   )r2   rn   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)ru  )r‘   rO  r   rÖ   r.  rk   rD  )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   r2  r	   ZMSG_DONTWAITrÙ   rî   rÿ   ZEAGAINZEWOULDBLOCKrp  r.  rX   )r2   rï   r   r   r   Ú_testSendmsgDontWaitX
  s     
z'SendmsgStreamTests._testSendmsgDontWaitN)r5   r6   r7   rm  rn  ro  rq  rÇ   r  r*  rr  rÂ   rs  r   r   r   r   rl  )
  s   
rl  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   r/  rþ  r’   )r2   r   r   r   Ú_testSendmsgNoDestAddrp
  s    z1SendmsgConnectionlessTests._testSendmsgNoDestAddrN)r5   r6   r7   ru  rv  r   r   r   r   rt  f
  s   rt  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)r?  )r5  rO  ra  r’   r‘   r8  r‚   rC  )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsg{
  s
    zRecvmsgGenericTests.testRecvmsgc             C   s   |   t¡ d S )N)r0  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)r?  )r5  rO  ra  r’   r‘   r8  r‚   rC  )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsgExplicitDefaults†
  s    z/RecvmsgGenericTests.testRecvmsgExplicitDefaultsc             C   s   |   t¡ d S )N)r0  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)r?  )r5  rO  ra  r’   r‘   r8  r‚   rC  )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsgShorter’
  s    z&RecvmsgGenericTests.testRecvmsgShorterc             C   s   |   t¡ d S )N)r0  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)r?  )r5  rO  ra  r’   r‘   r8  r‚   rC  )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsgTruncž
  s    z$RecvmsgGenericTests.testRecvmsgTruncc             C   s   |   t¡ d S )N)r0  r’   )r2   r   r   r   Ú_testRecvmsgTrunc§
  s    z%RecvmsgGenericTests._testRecvmsgTruncc             C   sT   |   | jttƒd¡\}}}}|  |t¡ |  || j¡ |  |g ¡ | j|dd d S )NrZ   T)r?  )r5  rO  ra  r’   r‘   r8  r‚   rC  )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsgShortAncillaryBufª
  s    z0RecvmsgGenericTests.testRecvmsgShortAncillaryBufc             C   s   |   t¡ d S )N)r0  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)r?  )r5  rO  ra  r’   r‘   r8  r‚   rC  )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsgLongAncillaryBuf¶
  s    z/RecvmsgGenericTests.testRecvmsgLongAncillaryBufc             C   s   |   t¡ d S )N)r0  r’   )r2   r   r   r   Ú_testRecvmsgLongAncillaryBuf¿
  s    z0RecvmsgGenericTests._testRecvmsgLongAncillaryBufc             C   s"   | j  ¡  |  t| j| j d¡ d S )Ni   )rO  r   ræ   r   r5  )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¸ž?)
rO  rN  ræ   r	   ru  r5  ra  r’   r.  rX   )r2   r   r   r   ÚtestRecvmsgTimeoutÊ
  s
    z&RecvmsgGenericTests.testRecvmsgTimeoutc             C   s   |   | jj| jd¡ d S )N)ru  )rÖ   r.  rk   rD  )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~  FrK  )r?  rB  T)r?  )r5  rO  ra  r’   r	   rø  r‘   r8  r‚   rC  rg   )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsgPeekÖ
  s(    z#RecvmsgGenericTests.testRecvmsgPeekc             C   s   |   t¡ d S )N)r0  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)r?  )
rO  rN  rD  r5  ra  r’   r‘   r8  r‚   rC  )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‘   r2  r’   ra  )r2   r   r   r   Ú_testRecvmsgFromSendmsg  s    z+RecvmsgGenericTests._testRecvmsgFromSendmsgN)r5   r6   r7   rx  ry  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   rw  w
  s(   						#rw  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¾   )r?  )r5  rO  r‘   r8  r‚   rC  )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsgEOF  s
    z(RecvmsgGenericStreamTests.testRecvmsgEOFc             C   s   | j  ¡  d S )N)r/  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)r?  i   T)r5  rO  ra  r’   r8  r‚   r‘   rC  )r2   r  rü  r^  r™   r  r“   r   r   r   ÚtestRecvmsgOverflow  s    z-RecvmsgGenericStreamTests.testRecvmsgOverflowc             C   s   |   t¡ d S )N)r0  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)r?  )ræ   ru   rO  rû  r2  ra  r’   rC  r`  r‘   r8  r‚   rC  )r2   r“   rü  r^  r™   r   r   r   ÚtestRecvmsgBadArgs3  s$    
zRecvmsgTests.testRecvmsgBadArgsc             C   s   |   t¡ d S )N)r0  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)r?  )rC  ra  r’   ræ   ru   rO  rF  r`  r2  r‘   r8  r‚   rC  )r2   rI  Únbytesrü  r^  r™   r   r   r   ÚtestRecvmsgIntoBadArgsP  s0    
z'RecvmsgIntoTests.testRecvmsgIntoBadArgsc             C   s   |   t¡ d S )N)r0  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)r?  )	rC  ra  r’   rO  rF  r‘   r8  r‚   rC  )r2   rI  r–  rü  r^  r™   r   r   r   ÚtestRecvmsgIntoGeneratoro  s    z)RecvmsgIntoTests.testRecvmsgIntoGeneratorc             C   s   |   t¡ d S )N)r0  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 )NrZ  r   T)r?  )
r[  ra  r’   rO  rF  r‘   Útobytesr8  r‚   rC  )r2   rI  r–  rü  r^  r™   r   r   r   ÚtestRecvmsgIntoArray}  s    z%RecvmsgIntoTests.testRecvmsgIntoArrayc             C   s   |   t¡ d S )N)r0  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)r?  )	rC  rO  rF  Ú
memoryviewr‘   ra  r8  r‚   rC  )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)r0  )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   rZ   i  r*   rƒ   r  )Úsocklen_t_limitr	   r£  Úlistr  r  r[  Úitemsizer‘   rH  ræ   r  r  Úmaxsize)r2   Útoobigr¯  Únr"   r   r   r   ÚtestCMSG_LENª  s    

zCmsgMacroTests.testCMSG_LENrd  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 )NrZ   i  r   r*   rƒ   r  )r¤  r	   rd  r¥  r  r  r[  r¦  rG  r£  rH  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   r4  r   r   r   r3  ó  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 )NrZ   r*   )	r	   rò   Ú
SCM_RIGHTSr[  Ú	frombytesra  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‘   r2  r’   r	   rò   r¸  r[  r²  ra  )r2   r©  r   r   r   ÚcreateAndSendFDs  s    zSCMRightsTest.createAndSendFDsrZ   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)r?  rA  rB  r*   r   )r‘   r’   r8  r‚   rC  r	   r9  r×   r¥  rH  ra  r[  Útuplerò   r¸  rì  Ú
SIZEOF_INTr¹  r¶  )r2   Znumfdsr4  Ú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 )NrZ   i (  )rÃ  r5  rO  ra  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*   rZ   )
r‘   r2  r’   r	   rò   r¸  r[  r²  r›  ra  )r2   r   r   r   Ú_testFDPassSimple,  s    zSCMRightsTest._testFDPassSimplec             C   s    |   d|  | jttƒd¡¡ d S )Nrì   i (  )rÃ  r5  rO  ra  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._testMultipleFDPassrd  c             C   s*   |   d|  | jttƒt dt ¡¡¡ d S )Nrì   )rÃ  r5  rO  ra  r’   r	   rd  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 )NrZ   rì   )rÁ  )	rÃ  r5  rO  ra  r’   r	   r£  r¿  r9  )r2   r   r   r   ÚtestFDPassCMSG_LENH  s    z SCMRightsTest.testFDPassCMSG_LENc             C   s   |   d¡ d S )NrZ   )r½  )r2   r   r   r   Ú_testFDPassCMSG_LENR  s    z!SCMRightsTest._testFDPassCMSG_LENr%  zskipping, see issue #12958r8  zskipping, see issue #22397c             C   s$   | j d|  | jttƒd¡dd d S )Nrƒ   i (  )rÀ  )rÃ  r5  rO  ra  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‘   r2  r’   r	   rò   r¸  r[  ra  )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Ã  r5  rO  ra  r’   r	   rd  r¿  r£  r9  )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‘   r2  r’   r	   rò   r¸  r[  ra  )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)r2  r   r×   rÿ   r  r‘   ra  )r2   r“   rü  r–  rv   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Ã  r5  rO  ra  r’   r	   r9  )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)r?  rB  rZ   )r5  rO  ra  r’   r‘   r8  r‚   rC  r	   r9  rH  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)r?  rB  rƒ   r*   )r5  rO  ra  r’   r‘   r8  r‚   rC  r	   r9  rH  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)r?  r@  rB  )r‘   r’   r8  r‚   rC  r	   r9  )r2   r4  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Û  r5  rO  ra  r’   r	   r9  )r2   r   r   r   ÚtestCmsgTruncNoBufSizeÝ  s    z$SCMRightsTest.testCmsgTruncNoBufSizec             C   s   |   d¡ d S )NrZ   )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Û  r5  rO  ra  r’   r	   r9  )r2   r   r   r   ÚtestCmsgTrunc0é  s    zSCMRightsTest.testCmsgTrunc0c             C   s   |   d¡ d S )NrZ   )r½  )r2   r   r   r   Ú_testCmsgTrunc0î  s    zSCMRightsTest._testCmsgTrunc0c             C   s   |   |  | jttƒd¡¡ d S )NrZ   )rÛ  r5  rO  ra  r’   )r2   r   r   r   ÚtestCmsgTrunc1ô  s    zSCMRightsTest.testCmsgTrunc1c             C   s   |   d¡ d S )NrZ   )r½  )r2   r   r   r   Ú_testCmsgTrunc1÷  s    zSCMRightsTest._testCmsgTrunc1c             C   s"   |   |  | jttƒtd ¡¡ d S )Nrƒ   )rÛ  r5  rO  ra  r’   r¿  )r2   r   r   r   ÚtestCmsgTrunc2Intú  s    zSCMRightsTest.testCmsgTrunc2Intc             C   s   |   d¡ d S )NrZ   )r½  )r2   r   r   r   Ú_testCmsgTrunc2Int  s    z SCMRightsTest._testCmsgTrunc2Intc          	   C   s(   |   |  | jttƒt d¡d ¡¡ d S )Nr   rZ   )rÛ  r5  rO  ra  r’   r	   r£  )r2   r   r   r   ÚtestCmsgTruncLen0Minus1  s    z%SCMRightsTest.testCmsgTruncLen0Minus1c             C   s   |   d¡ d S )NrZ   )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)r?  r@  r   rZ   r*   )r5  rO  ra  r’   r‘   r8  r‚   rC  r	   r9  rò   r¸  rG  rH  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 )NrZ   )r½  )r2   r   r   r   Ú_testCmsgTruncLen0)  s    z SCMRightsTest._testCmsgTruncLen0c             C   s   | j t d¡d dd d S )Nr   rZ   )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ƒ   rZ   )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)rZ   r   )r   )r   )9r5   r6   r7   r×  r²  r¶  r3  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 )NrZ   T)r?  rA  rB  r   r*   )rO  rL  r	   ÚIPPROTO_IPV6ÚIPV6_RECVHOPLIMITr.  rX   r5  ra  r’   r‘   r8  r‚   rC  r9  r×   r¾  ÚIPV6_HOPLIMITrì  r¿  r[  r¹  rG  rH  )r2   Ú
ancbufsizeÚmaxhoprÁ  r“   rü  r^  r™   rº  r»  r¼  r7  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)ru  )rÖ   r.  rk   rD  r0  r’   )r2   r   r   r   Ú_testRecvHopLimit}  s    z&RFC3542AncillaryTest._testRecvHopLimitrd  c             C   s   | j t t¡d d S )N)r÷  )rù  r	   rd  r¿  )r2   r   r   r   ÚtestRecvHopLimitCMSG_SPACE…  s    z/RFC3542AncillaryTest.testRecvHopLimitCMSG_SPACEc             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  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)ru  r*   )rÖ   r.  rk   rD  r‘   r2  r’   r	   rô  rö  r[  rþ  ra  )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 )NrZ   T)r?  rA  rB  rƒ   r*   r   rê  )rO  rL  r	   rô  rõ  ÚIPV6_RECVTCLASSr.  rX   r5  ra  r’   r‘   r8  r‚   rC  r9  ró  ÚIPV6_TCLASSr¿  r[  r¹  rG  rH  rö  )r2   r÷  rø  rÁ  r“   rü  r^  r™   ZancmapZtcdatar7  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)ru  )rÖ   r.  rk   rD  r0  r’   )r2   r   r   r   Ú _testRecvTrafficClassAndHopLimitÎ  s    z5RFC3542AncillaryTest._testRecvTrafficClassAndHopLimitc             C   s   | j t t¡d d d S )Nrƒ   )r÷  )r  r	   rd  r¿  )r2   r   r   r   Ú)testRecvTrafficClassAndHopLimitCMSG_SPACEÓ  s    z>RFC3542AncillaryTest.testRecvTrafficClassAndHopLimitCMSG_SPACEc             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  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)ru  r*   )rÖ   r.  rk   rD  r‘   r2  r’   r	   rô  r  r[  Útraffic_classrö  rþ  ra  )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)ru  r*   rÔ  )rÖ   r.  rk   rD  r2  r’   r	   rô  r  r[  r	  r›  rö  rþ  r   r×   rÿ   r  r‘   ra  )r2   r–  rv   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 )NrZ   r   T)r?  r@  rB  )rO  rL  r	   rô  rõ  r.  rX   r5  ra  r’   r‘   r8  r‚   rC  r9  )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	   r9  )r2   r   r   r   rÜ  (  s    z+RFC3542AncillaryTest.testCmsgTruncNoBufSizec             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  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	   r9  )r2   r   r   r   ÚtestSingleCmsgTrunc08  s    z)RFC3542AncillaryTest.testSingleCmsgTrunc0c             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  r’   )r2   r   r   r   Ú_testSingleCmsgTrunc0?  s    z*RFC3542AncillaryTest._testSingleCmsgTrunc0c             C   s   | j dd d S )NrZ   )r÷  )r  )r2   r   r   r   ÚtestSingleCmsgTrunc1G  s    z)RFC3542AncillaryTest.testSingleCmsgTrunc1c             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  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)ru  )rÖ   r.  rk   rD  r0  r’   )r2   r   r   r   Ú_testSingleCmsgTrunc2IntT  s    z-RFC3542AncillaryTest._testSingleCmsgTrunc2Intc             C   s   | j t d¡d d d S )Nr   rZ   )r÷  )r  r	   r£  )r2   r   r   r   ÚtestSingleCmsgTruncLen0Minus1Y  s    z2RFC3542AncillaryTest.testSingleCmsgTruncLen0Minus1c             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  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 )NrZ   T)r?  r@  r   )rO  rL  r	   rô  rõ  r.  rX   r5  ra  r’   r£  r¿  r‘   r8  r‚   rC  r9  rH  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)ru  )rÖ   r.  rk   rD  r0  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 )NrZ   T)r?  r@  rB  r   r*   rê  )rO  rL  r	   rô  rõ  r  r.  rX   r5  ra  r’   r‘   r8  r‚   rC  r9  rÙ   r  rö  r¿  r[  r¹  rG  rH  )r2   r÷  rÁ  r“   rü  r^  r™   rº  r»  r¼  r7  r   r   r   ÚcheckTruncatedSecondHeader}  s(    






z/RFC3542AncillaryTest.checkTruncatedSecondHeaderc             C   s   | j t t¡tjd d S )N)rÁ  )r  r	   rd  r¿  r9  )r2   r   r   r   ÚtestSecondCmsgTrunc0  s    z)RFC3542AncillaryTest.testSecondCmsgTrunc0c             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  r’   )r2   r   r   r   Ú_testSecondCmsgTrunc0£  s    z*RFC3542AncillaryTest._testSecondCmsgTrunc0c             C   s   |   t t¡d ¡ d S )NrZ   )r  r	   rd  r¿  )r2   r   r   r   ÚtestSecondCmsgTrunc1¨  s    z)RFC3542AncillaryTest.testSecondCmsgTrunc1c             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  r’   )r2   r   r   r   Ú_testSecondCmsgTrunc1­  s    z*RFC3542AncillaryTest._testSecondCmsgTrunc1c             C   s   |   t t¡dt  ¡ d S )Nrƒ   )r  r	   rd  r¿  )r2   r   r   r   ÚtestSecondCmsgTrunc2Int²  s    z,RFC3542AncillaryTest.testSecondCmsgTrunc2Intc             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  r’   )r2   r   r   r   Ú_testSecondCmsgTrunc2Int¸  s    z-RFC3542AncillaryTest._testSecondCmsgTrunc2Intc             C   s"   |   t t¡t d¡ d ¡ d S )Nr   rZ   )r  r	   rd  r¿  r£  )r2   r   r   r   ÚtestSecondCmsgTruncLen0Minus1½  s    z2RFC3542AncillaryTest.testSecondCmsgTruncLen0Minus1c             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  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 )NrZ   T)r?  r@  r   r*   rê  )rO  rL  r	   rô  rõ  r  r.  rX   r5  ra  r’   rd  r¿  r£  r‘   r8  r‚   rC  r9  r  rö  ÚpopÚremover[  r¹  rG  rH  rÕ  )
r2   r“   rü  r^  r™   Z
cmsg_typesrº  r»  r¼  r7  r   r   r   ÚtestSecomdCmsgTruncInDataÈ  s4    





"



z.RFC3542AncillaryTest.testSecomdCmsgTruncInDatac             C   s$   |   | jj| jd¡ |  t¡ d S )N)ru  )rÖ   r.  rk   rD  r0  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'  rF  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   r6  r7  r   r   r   r8    s    z+SendrecvmsgUDP6TestBase.checkRecvmsgAddressN)r5   r6   r7   r8  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   r.  *  s   r.  c               @   s   e Zd ZdS )ÚSendrecvmsgTCPTestBaseN)r5   r6   r7   r   r   r   r   r/  4  s   r/  c               @   s   e Zd ZdS )ÚSendmsgTCPTestN)r5   r6   r7   r   r   r   r   r0  8  s   r0  c               @   s   e Zd ZdS )ÚRecvmsgTCPTestN)r5   r6   r7   r   r   r   r   r1  <  s   r1  c               @   s   e Zd ZdS )ÚRecvmsgIntoTCPTestN)r5   r6   r7   r   r   r   r   r2  A  s   r2  c               @   s   e Zd ZdS )ÚSendrecvmsgSCTPStreamTestBaseN)r5   r6   r7   r   r   r   r   r3  G  s   r3  r,   r-   r·   c               @   s   e Zd ZdS )ÚSendmsgSCTPStreamTestN)r5   r6   r7   r   r   r   r   r4  L  s   r4  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:   r5  rŽ  r   rÿ   ÚENOTCONNrL   )r2   rv   )rA   r   r   rŽ  V  s    z$RecvmsgSCTPStreamTest.testRecvmsgEOF)r5   r6   r7   rŽ  rD   r   r   )rA   r   r5  Q  s   r5  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:   r7  rŽ  r   rÿ   r6  rL   )r2   rv   )rA   r   r   rŽ  c  s    z(RecvmsgIntoSCTPStreamTest.testRecvmsgEOF)r5   r6   r7   rŽ  rD   r   r   )rA   r   r7  ^  s   r7  c               @   s   e Zd ZdS )ÚSendrecvmsgUnixStreamTestBaseN)r5   r6   r7   r   r   r   r   r8  l  s   r8  r±   c               @   s   e Zd ZdS )ÚSendmsgUnixStreamTestN)r5   r6   r7   r   r   r   r   r9  p  s   r9  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 )NrZ   r   r   )ZsignumrÚ  r   r   r   r½   š  r¾   z.InterruptedTimeoutBase.setUp.<locals>.<lambda>)r:   r3   rp  rq  rB   )r2   Zorig_alrm_handler)rA   r   r   r3   —  s    

zInterruptedTimeoutBase.setUpg      @Ú	setitimergš™™™™™©?c             C   s   t  t j|¡ d S )N)rp  r?  ÚITIMER_REAL)r2   Úsecondsr   r   r   ÚsetAlarm¦  s    zInterruptedTimeoutBase.setAlarmrƒ   c             C   s   t  |¡ d S )N)rp  rj  )r2   rA  r   r   r   rB  ¬  s    )
r5   r6   r7   r3   ru  rt   rp  Ú
alarm_timerB  rD   r   r   )rA   r   r>  ’  s   

r>  Úsiginterruptrj  r?  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.   rN  ru  )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   )rB  rC  ræ   rr  )r2   r  r?   r@   rï   r   r   r   ÚcheckInterruptedRecv½  s
    z/InterruptedRecvTimeoutTest.checkInterruptedRecvc             C   s   |   | jjd¡ d S )Ni   )rF  r.   r   )r2   r   r   r   ÚtestInterruptedRecvTimeoutÇ  s    z5InterruptedRecvTimeoutTest.testInterruptedRecvTimeoutc             C   s   |   | jjtdƒ¡ d S )Ni   )rF  r.   Ú	recv_intorC  )r2   r   r   r   ÚtestInterruptedRecvIntoTimeoutÊ  s    z9InterruptedRecvTimeoutTest.testInterruptedRecvIntoTimeoutc             C   s   |   | jjd¡ d S )Ni   )rF  r.   rÜ  )r2   r   r   r   ÚtestInterruptedRecvfromTimeoutÍ  s    z9InterruptedRecvTimeoutTest.testInterruptedRecvfromTimeoutc             C   s   |   | jjtdƒ¡ d S )Ni   )rF  r.   Úrecvfrom_intorC  )r2   r   r   r   Ú"testInterruptedRecvfromIntoTimeoutÐ  s    z=InterruptedRecvTimeoutTest.testInterruptedRecvfromIntoTimeoutrû  c             C   s   |   | jjd¡ d S )Ni   )rF  r.   rû  )r2   r   r   r   ÚtestInterruptedRecvmsgTimeoutÓ  s    z8InterruptedRecvTimeoutTest.testInterruptedRecvmsgTimeoutrF  c             C   s   |   | jjtdƒg¡ d S )Ni   )rF  r.   rF  rC  )r2   r   r   r   Ú!testInterruptedRecvmsgIntoTimeout×  s    z<InterruptedRecvTimeoutTest.testInterruptedRecvmsgIntoTimeout)r5   r6   r7   r3   rF  rG  rI  rJ  rL  rÎ   r	   rM  rN  rD   r   r   )rA   r   rE  ²  s   
rE  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Ì   rN  ru  )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   rQ  õ  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æ   rr  rB  rC  )r2   r  r?   r@   rï   r   r   r   ÚcheckInterruptedSendø  s    z/InterruptedSendTimeoutTest.checkInterruptedSendr.  rå  c             C   s   |   | jjd¡ d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rS  rš   r•   )r2   r   r   r   ÚtestInterruptedSendTimeout  s    z5InterruptedSendTimeoutTest.testInterruptedSendTimeoutc             C   s   |   | jjd| j¡ d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rS  rš   rí   r¡   )r2   r   r   r   ÚtestInterruptedSendtoTimeout	  s    z7InterruptedSendTimeoutTest.testInterruptedSendtoTimeoutrþ  c             C   s   |   | jjdg¡ d S )Ns   aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)rS  rš   rþ  )r2   r   r   r   ÚtestInterruptedSendmsgTimeout  s    z8InterruptedSendTimeoutTest.testInterruptedSendmsgTimeout)r5   r6   r7   r3   rQ  rS  r   Zrequires_mac_verrT  rU  rÎ   r	   rV  rD   r   r   )rA   r   rO  Þ  s   		
rO  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      ð?rZ   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   rY  rZ  r   r   r   r   rW    s   rW  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 )ÚBasicSocketPairTestrz   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	   rt   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)rz   )r5   r6   r7   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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 )%ÚNonBlockingTCPTestsrz   c             C   s   t  ¡ | _tj| |d d S )N)r{   )r<   r_   Úeventry   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©  rh  r0  rÖ   Úgetblockingr   r)   r‘   rI  rN  r   rŠ   r   )r2   rR  Ú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        rZ   )	r  r#  Z	ULONG_MAXrL   r.   r©  r‘   r0  rh  )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¨  rI  rc  r‘   r0  r   r/   r0   r1   r   rŠ   r   rÖ   )r2   rR  rd  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.   rN  rŠ   r   ra  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Š   rb  rX   r  ÚMAIN_TIMEOUTrã   rB   r   rh  r0  )r2   r‹   r™   r  r®  rÒ   r   r   r   Ú
testAcceptÀ  s    


zNonBlockingTCPTests.testAcceptc             C   s    | j  ¡  | j t| jf¡ d S )N)rb  rk   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|   rN  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æ   ro  r   ra  r’   rb  rX   r  rp  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   rb  rk   rs  r’   )r2   r   r   r   r  ÷  s    
zNonBlockingTCPTests._testRecvN)rz   )r5   r6   r7   r;   re  rf  r   rÀ  rg  Z_testSetBlocking_overflowr…   r¿  rt   r	   Úrequires_linux_versionrj  rk  rm  rn  rq  rr  rs  rt  r  r  r   r   r   r   ra  O  s"   
2
ra  c               @   sö   e 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.d/„ Zd0d1„ Z d2d3„ Z!d4d5„ Z"d6d7„ Z#d8d9„ Z$dS );ÚFileObjectClassTestCaser  zutf-8ÚstrictNr   rˆ  rz   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_moderM   rx  ry  rz  Ú	read_file)r2   r   r   r   r3     s    "
zFileObjectClassTestCase.setUpc             C   s6   | j  ¡  | j ¡  |  | jj¡ d | _t | ¡ d S )N)r}  rX   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)rx  ry  rz  )
r—   rp   rš   r|  Ú
write_moderM   rx  ry  rz  Ú
write_file)r2   r   r   r   rp   ,  s    
z#FileObjectClassTestCase.clientSetUpc             C   s6   | j  ¡  | j ¡  |  | jj¡ d | _t | ¡ d S )N)r~  rX   rƒ  r   rÖ   r  r—   rs   )r2   r   r   r   rs   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 )NrZ   r  z!cannot read from timed out object)r˜   rN  r€  r  ræ   r	   ru  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}  rk   )r2   r   r   r   Ú_testReadAfterTimeoutG  s    
z-FileObjectClassTestCase._testReadAfterTimeoutc             C   s<   | j  t| jƒd ¡}| j  d¡}|| }|  || j¡ d S )Nr  )r€  r  ra  Ú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 )NrZ   )rÁ   rˆ  r€  r  r‘   )r2   rI  Ú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   ra  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æ   r2  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)rz   )%r5   r6   r7   rM   rx  ry  rz  r  r’   rˆ  r‚  r…  r;   r3   r4   rp   rs   r„  r‡  rŠ  r‹  rŒ  r  r  r  r“  r”  r•  r–  r˜  r™  rš  r›  rœ  r  rž  rŸ  r   r   r   r   rv    sB   


rv  c               @   s`   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d„ Zdd„ Zdd„ ZdS )Ú!UnbufferedFileObjectClassTestCaser   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 )NrZ   )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  rZ   )r˜   r©  r‘   r€  ÚreadintorC  r  ra  rˆ  r{  rX   r|  rk   r   rŽ   )r2   r‰  rI  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{  rk   rƒ  r®  r…  r†  r|  rX   r}  )r2   r   r   r   Ú_testSmallReadNonBlockingë  s
    

z;UnbufferedFileObjectClassTestCase._testSmallReadNonBlockingc             C   s"   | j  d¡ | jr|  | j¡ d S )Ng      @)r~  rk   Úserv_skippedrL   )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 )NFro  r.  r   z$failed to saturate the socket buffer)	rª  rš   r©  r   rt  rƒ  r®  r  r  )r2   ZBIGZLIMITr©  r*   r   r   r   Ú_testWriteNonBlockingû  s    
z7UnbufferedFileObjectClassTestCase._testWriteNonBlockingN)r5   r6   r7   rM   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 )Ú#LineBufferedFileObjectClassTestCaserZ   N)r5   r6   r7   rM   r   r   r   r   r­    s   r­  c               @   s   e Zd ZdZdS )Ú$SmallBufferedFileObjectClassTestCaserƒ   N)r5   r6   r7   rM   r   r   r   r   r®    s   r®  c               @   s&   e Zd ZdZe d¡ZdZeZdZ	dS )Ú"UnicodeReadFileObjectClassTestCaser   zutf-8rˆ  rê   N)
r5   r6   r7   r  r’   r—  rˆ  r‚  r…  rz  r   r   r   r   r¯    s
   
r¯  c               @   s&   e Zd ZdZeZdZe d¡ZdZ	dS )Ú#UnicodeWriteFileObjectClassTestCaser   r‡  zutf-8rê   N)
r5   r6   r7   r  r’   rˆ  r‚  r—  r…  rz  r   r   r   r   r°  %  s
   
r°  c               @   s,   e Zd ZdZe d¡ZdZe d¡ZdZ	dS )Ú'UnicodeReadWriteFileObjectClassTestCaser   zutf-8r‡  rê   N)
r5   r6   r7   r  r’   r—  rˆ  r‚  r…  rz  r   r   r   r   r±  /  s
   

r±  c               @   s   e Zd Zdd„ ZdS )ÚNetworkConnectionTestc             C   s   t  t| jf¡| _| j| _d S )N)r	   Úcreate_connectionr€   r0   r|   rš   )r2   r   r   r   rp   <  s    z!NetworkConnectionTest.clientSetUpN)r5   r6   r7   rp   r   r   r   r   r²  9  s   r²  c               @   s   e Zd ZdS )ÚBasicTCPTest2N)r5   r6   r7   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	   ru  )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 )N)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   rF  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   rF  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	   ru  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 )ÚNetworkConnectionAttributesTestrz   c             C   s   t j| |d t | ¡ d S )N)r{   )r+   r;   rR   )r2   r{   r   r   r   r;   €  s    z(NetworkConnectionAttributesTest.__init__c             C   s   t  ¡ | _d S )N)r   rF  Úsource_port)r2   r   r   r   rp   „  s    z+NetworkConnectionAttributesTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r|   r   rR   rs   )r2   r   r   r   rs   ‡  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é   )ru  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ê   )ru  Zsource_addressrZ   )
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	   r/  r1  r³  r€   r0   r|   rB   r   r‘   r0  )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À  )ru  )rÖ   r	   r/  r1  r³  r€   r0   r|   rB   r   r‘   r0  )r2   r   r   r   Ú_testTimeoutNone¬  s    
z0NetworkConnectionAttributesTest._testTimeoutNonec             C   s,   t jt| jfdd| _|  | j ¡ d¡ d S )NrÀ  )ru  )r	   r³  r€   r0   r|   r‘   r0  )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‘   r0  )r2   r   r   r   Ú_testTimeoutValueNonamed½  s    z8NetworkConnectionAttributesTest._testTimeoutValueNonamedN)rz   )r5   r6   r7   r;   rp   rs   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 )ÚNetworkConnectionBehaviourTestrz   c             C   s   t j| |d t | ¡ d S )N)r{   )r+   r;   rR   )r2   r{   r   r   r   r;   Å  s    z'NetworkConnectionBehaviourTest.__init__c             C   s   d S )Nr   )r2   r   r   r   rp   É  s    z*NetworkConnectionBehaviourTest.clientSetUpc             C   s   | j  ¡  d | _ t | ¡ d S )N)r|   r   rR   rs   )r2   r   r   r   rs   Ì  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 )NrS  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 )NrZ   )ru  c                  s
   ˆ   d¡S )NrS  )r   r   )r(   r   r   r½   ß  r¾   zDNetworkConnectionBehaviourTest._testOutsideTimeout.<locals>.<lambda>)r	   r³  r€   r0   r|   ræ   ru  )r2   r   )r(   r   Ú_testOutsideTimeoutÝ  s    z2NetworkConnectionBehaviourTest._testOutsideTimeoutN)rz   )
r5   r6   r7   r;   rp   rs   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.   rN  rŠ   )r?   r@   )r2   r   r   Úraise_timeoutå  s    z4TCPTimeoutTest.testTCPTimeout.<locals>.raise_timeoutz*Error generating a timeout exception (TCP))ræ   r	   ru  )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.   rN  rŠ   r	   ru  rã   r   )r2   ÚokÚfoor   r   r   ÚtestTimeoutZeroë  s    zTCPTimeoutTest.testTimeoutZerorj  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   )rp  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.   rN  r>  rp  rq  rj  rŠ   r	   ru  rã   r  Úexc_infoÚ	tracebackÚ
format_exc)r2   rÒ  rw  rÏ  r   )rÑ  r   ÚtestInterruptedTimeoutù  s(    
$z%TCPTimeoutTest.testInterruptedTimeoutN)
r5   r6   r7   rÍ  rÐ  r…   r¿  rt   rp  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.   rN  r   )r?   r@   )r2   r   r   rÌ    s    z4UDPTimeoutTest.testUDPTimeout.<locals>.raise_timeoutz*Error generating a timeout exception (UDP))ræ   r	   ru  )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.   rN  r   r	   ru  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è   ru  )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-   rJ   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Ô  ó   hrZ   )ÚUNIX_PATH_MAXr	   r±   r-   rJ   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   rJ   )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-   rJ   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-   rJ   rC  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&   Úfsencoderd  rL   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Ï   rL   rÑ   )r2   r(   r¯   rv   r   r   r   rJ   …  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   ÚTESTFNrJ   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ð  rJ   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í  rJ   r(   r—  rB   r®   r‘   r   )r2   r¯   rf  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_UNENCODABLErL   r&   r¯   rï  rJ   r(   rB   r®   r‘   r   )r2   r¯   r   r   r   ÚtestUnencodableAddr¬  s    

z"TestUnixDomain.testUnencodableAddrN)r5   r6   r7   r3   r4   rí  rJ   rî  rñ  rò  rõ  rö  r   r   r   r   rê  q  s   	rê  c               @   s‚   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
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 )ÚBufferIOTestrz   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 )NrZ  r   )r[  ra  r’   r˜   rH  r‘   r›  )r2   rI  r–  r“   r   r   r   ÚtestRecvIntoArray¾  s    zBufferIOTest.testRecvIntoArrayc             C   s   t tƒ}| j |¡ d S )N)rì  r’   rš   r•   )r2   rI  r   r   r   Ú_testRecvIntoArrayÆ  s    zBufferIOTest._testRecvIntoArrayc             C   sD   t dƒ}| j |¡}|  |ttƒ¡ |d ttƒ… }|  |t¡ d S )Ni   )rC  r˜   rH  r‘   ra  r’   )r2   rI  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   )rC  r˜   rH  rŸ  r‘   ra  r’   )r2   rI  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 )NrZ  r   )r[  ra  r’   r˜   rK  r‘   r›  )r2   rI  r–  r™   r“   r   r   r   ÚtestRecvFromIntoArrayÜ  s    z"BufferIOTest.testRecvFromIntoArrayc             C   s   t tƒ}| j |¡ d S )N)rì  r’   rš   r•   )r2   rI  r   r   r   Ú_testRecvFromIntoArrayä  s    z#BufferIOTest._testRecvFromIntoArrayc             C   sH   t dƒ}| j |¡\}}|  |ttƒ¡ |d ttƒ… }|  |t¡ d S )Ni   )rC  r˜   rK  r‘   ra  r’   )r2   rI  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   )rC  r˜   rK  rŸ  r‘   ra  r’   )r2   rI  r–  r™   r“   r   r   r   ÚtestRecvFromIntoMemoryviewñ  s
    z'BufferIOTest.testRecvFromIntoMemoryviewc             C   s    t dƒ}|  t| jj|d¡ d S )NrI   i   )rC  ræ   r2  r˜   rK  )r2   rI  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   )rC  r˜   rK  )r2   rI  r   r   r   ÚtestRecvFromIntoEmptyBuffer  s    z(BufferIOTest.testRecvFromIntoEmptyBufferN)rz   )r5   r6   r7   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 )NÚAF_TIPCFz/proc/modulesztipc T)rt   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 )NrZ   rƒ   r   i   )r	   r  rñ   rB   r   rL  rò   ró   ÚTIPC_ADDR_NAMESEQÚ
TIPC_STYPEÚ
TIPC_LOWERÚ
TIPC_UPPERrJ   Ú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 )ÚTIPCThreadableTestrz   c             C   s   t jj| |d t | ¡ d S )N)r{   )r…   r†   r;   rR   )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 )NrZ   )r	   r  r-   r•  rB   r   rL  rò   ró   r  r  r  r  rJ   r1   rY   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   rp   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)rz   )r5   r6   r7   r;   r3   rp   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	   rI  r%  rÖ   r   ræ   r   rs  )r2   r(   r   r   r   Ú_testSocketClasse  s    


z$ContextManagersTest._testSocketClassc             C   s2   | j  ¡ \}}|  |j¡ | d¡}| |¡ d S )Ni   )r.   rŠ   rB   r   r   rs  )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³  rI  r%  rs  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   rs  )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   rs  )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 )ÚInheritanceTestrQ  zSOCK_CLOEXEC not definedrƒ   rh  ri  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-   rQ  r‘   rÁ   rI  Ú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¿  rt   r	   r   ru  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-   r0  rÖ   r   r%   r&   r'   rI  rc  )r2   r   Únonblockru  r   r   r   ÚcheckNonblockÕ  s    	z"NonblockConstantTest.checkNonblockrƒ   rh  ri  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 )NrZ   F)r(  r   g       @)ru  g        )	r	   r,   r-   r¨  r)  r©  rN  r/  r1  )r2   r   Útr   r   r   Útest_SOCK_NONBLOCKî  s6    














z'NonblockConstantTest.test_SOCK_NONBLOCKN)Tr'  )r5   r6   r7   r)  r   ru  r+  r   r   r   r   r&  Ò  s   
r&  rW  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)rm   r	   Ú	fromsharerŠ   rs  r   )rÖ  ÚqZsdatarl  r   r»  rv  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)rP  r?   s
   slapmahfrorY  r¾   )Úmultiprocessingrc   ZProcessr/  rR  r.   ÚshareÚpidr   r   rr   r	   r³  r   r°  rÌ   r‘   )	r2   r.  rä   r×  r™   rl  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.   r1  r&   Úgetpidræ   r2  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‘   r0  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.   r1  r&   r6  r	   r-  r9  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   r1  r&   r6  r-  r9  r   )r2   ZfamiliesÚtypesr   r*  Úsourcer×  Zsharedr   r   r   Ú	testTypesc  s    


zTestSocketSharing.testTypesN)
r5   r6   r7   rï  r/  r5  r7  r9  r:  r=  r   r   r   r   r,    s   #r,  c               @   sü   e 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d/d0„ Zd1d2„ Zd3d4„ Zd5d6„ Z d7d8„ Z!d9d:„ Z"d;S )<ÚSendfileUsingSendTesti    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ƒ}| ¡ | _	W d Q R X d S )Nc             s   s*   x| |kr|V  | |8 } qW | r&| V  d S )Nr   )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  ÚFILEDATA)rÖ  r@  Ú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.   rN  rp  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   rD  r°  rÌ   )r2   r‹   r4  rG  r   r   r   Ú	recv_dataŸ  s    zSendfileUsingSendTest.recv_datac             C   s
   t |dƒS )NZ_sendfile_use_send)rg   )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³  rM  r‘   rE  Útell)r2   rß  Úfiler(   ÚmethÚsentr   r   r   Ú_testRegularFile¯  s    

z&SendfileUsingSendTest._testRegularFilec             C   s6   |   ¡ }|  |¡}|  t|ƒ| j¡ |  || j¡ d S )N)rK  rL  r‘   ra  rE  rF  )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ÚBytesIOrF  r	   r³  r²  r‘   rE  rN  ræ   r¶  r·  )r2   rß  rO  r(   rQ  r   r   r   Ú_testNonRegularFileÀ  s    

z)SendfileUsingSendTest._testNonRegularFilec             C   s6   |   ¡ }|  |¡}|  t|ƒ| j¡ |  || j¡ d S )N)rK  rL  r‘   ra  rE  rF  )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³  rM  r‘   rN  )r2   rß  ÚfilenamerO  r(   rP  rQ  r   r   r   Ú_testEmptyFileSendÒ  s    



z(SendfileUsingSendTest._testEmptyFileSendc             C   s"   |   ¡ }|  |¡}|  |d¡ d S )Nr¾   )rK  rL  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³  rM  r‘   rE  rN  )r2   rß  rO  r(   rP  rQ  r   r   r   Ú_testOffsetå  s    

z!SendfileUsingSendTest._testOffsetc             C   sB   |   ¡ }|  |¡}|  t|ƒ| jd ¡ |  || jdd … ¡ d S )Niˆ  )rK  rL  r‘   ra  rE  rF  )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ƒ   )ru  iGKL )rU  )
r.   r   r   r   rð  r	   r³  rM  r‘   rN  )r2   rß  rO  r(   rU  rP  rQ  r   r   r   Ú
_testCountö  s    

z SendfileUsingSendTest._testCountc             C   s@   d}|   ¡ }|  |¡}|  t|ƒ|¡ |  || jd |… ¡ d S )NiGKL )rK  rL  r‘   ra  rF  )r2   rU  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ƒ   )ru  rZ   )rU  )
r.   r   r   r   rð  r	   r³  rM  r‘   rN  )r2   rß  rO  r(   rU  rP  rQ  r   r   r   Ú_testCountSmall	  s    

z%SendfileUsingSendTest._testCountSmallc             C   s@   d}|   ¡ }|  |¡}|  t|ƒ|¡ |  || jd |… ¡ d S )NrZ   )rK  rL  r‘   ra  rF  )r2   rU  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ƒ   )ru  i§† i×  )r\  rU  )
r.   r   r   r   rð  r	   r³  rM  r‘   rN  )r2   rß  rO  r(   rU  rP  rQ  r   r   r   Ú_testCountWithOffset  s    

z*SendfileUsingSendTest._testCountWithOffsetc             C   sD   d}|   ¡ }|  |¡}|  t|ƒ|¡ |  || jd|d … ¡ d S )Ni§† i×  )rK  rL  r‘   ra  rF  )r2   rU  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©  rM  ræ   r2  r²  )r2   rß  rO  r(   rP  r   r   r   Ú_testNonBlocking/  s    


z&SendfileUsingSendTest._testNonBlockingc             C   s    |   ¡ }| d¡r|  d¡ d S )Ni    z$was not supposed to receive any data)rK  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ƒ   )ru  )
r.   r   r   r   rð  r	   r³  rM  r‘   rE  )r2   rß  rO  r(   rP  rQ  r   r   r   Ú_testWithTimeout?  s    

z&SendfileUsingSendTest._testWithTimeoutc             C   s6   |   ¡ }|  |¡}|  t|ƒ| j¡ |  || j¡ d S )N)rK  rL  r‘   ra  rE  rF  )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³  rN  rM  ræ   ru  )r2   rß  rO  r(   rP  r   r   r   Ú_testWithTimeoutTriggeredSendO  s    


z3SendfileUsingSendTest._testWithTimeoutTriggeredSendc             C   s   |   ¡ }| d¡ d S )Ni€X )rK  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 integerrX  )rU  gš™™™™™¹?r   r  )	r   r   rð  r	   r   rM  rŽ  r2  ru   )r2   rO  r   rP  r   r   r   Útest_errors`  s*    
 

 

z!SendfileUsingSendTest.test_errorsN)#r5   r6   r7   rE  rD  rF  rJ  rï  rH  rI  rK  rL  rM  rR  rS  rV  rW  rZ  r[  r]  r^  r_  r`  ra  rb  rc  rd  re  rf  rg  rh  ri  rj  rk  rl  r   r   r   r   r>  w  s>   		
	
	
	
		r>  r²  z%os.sendfile() required for this test.c               @   s   e Zd Zdd„ ZdS )ÚSendfileUsingSendfileTestc             C   s
   t |dƒS )Nr·  )rg   )r2   r(   r   r   r   rM  ~  s    z(SendfileUsingSendfileTest.meth_from_sockN)r5   r6   r7   rM  r   r   r   r   rm  x  s   rm  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   rJ   r  r   r…   ZSkipTestrÏ   )r2   ÚtyprÉ   r(   rv   r   r   r   Ú
create_alg…  s    $zLinuxKernelCryptoAPI.create_algrì   rS  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ì  Úfromhexrp  rŠ   rs  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(effcdf6ae5eb2fa2d27416d5f184df9c259a7c79rq  z
hmac(sha1)s   Jefes   what do ya want for nothing?i   )rì  ru  rp  rL  r	   ÚSOL_ALGÚALG_SET_KEYrŠ   rs  r‘   r   )r2   rà   rw  rx  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))rx  Úivr^  )rx  r}  i   )rì  ru  ra  rp  rL  r	   rz  r{  rŠ   Úsendmsg_afalgÚALG_OP_ENCRYPTrv  rs  r‘   r   ÚALG_OP_DECRYPT)r2   Úkeyr}  r“   Z
ciphertextZmsglenrw  rx  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))rx  r}  Úassoclenr^  )rx  r}  r„  r   )rì  ru  ra  rp  rL  r	   rz  r{  ZALG_SET_AEAD_AUTHSIZErŠ   r~  r  rv  rs  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„  rw  rx  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  )rp  r&   ÚurandomrL  r	   rz  r{  rŠ   r   r‘   ra  )r2   rw  Z
extra_seedrx  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   )rx  rZ   )rx  r„  r  )r	   r    r   ræ   ru   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  rJ   rŽ  r2  )r2   r(   r   r   r   Útest_length_restriction4  s    z,LinuxKernelCryptoAPI.test_length_restrictionN)r5   r6   r7   rp  r   ru  ry  r|  rƒ  r†  r‰  rŠ  r‹  r   r   r   r   rn  ‚  s   )?rn  Ú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  rW  rË  rÙ  r÷  r´  r(  r×  Úextendra  rv  r   r­  r®  r¯  r°  r±  rµ  r½  rÇ  r  r  r&  r°  r[  rê  rÝ  r
  r  rÂ  rÓ  ró  rõ  rn  r  r„   r¢  r&  r'  r(  r*  r+  r-  r.  r,  r0  r1  r2  r4  r5  r7  r9  r:  r;  r<  r=  rE  rO  r,  r>  rm  r  r   Zthreading_setupZrun_unittestZthreading_cleanup)ZtestsÚthread_infor   r   r   Ú	test_main\  sr    





r“  Ú__main__)²r…   Ztestr   rÿ   rT  rT  r	   r  r¨   r   rÔ  rb   r  r&   r[  r»  Úweakrefr   rp  rk  r‘  r   rA  r½  rC  Ú_threadrh   r<   r0  r>  r   r€   r¯  r’   rp  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   rE   rQ   rR   ry   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-  rE  rJ  rM  rN  rP  rQ  rR  rl  rt  rw  r  r’  r•  r¢  r­  rñ  r%  r&  r'  r(  r)  rb  r*  r+  r,  r-  r.  r/  r0  r1  r2  r3  r4  r5  r7  r8  r9  r:  r;  r<  r=  r>  rt   rE  rO  rW  r[  ra  rv  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>  rm  rn  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