Your IP : 3.141.41.109


Current Path : /opt/alt/python35/lib64/python3.5/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/multiprocessing/__pycache__/connection.cpython-35.opt-1.pyc



��Yf�x�@sIddddgZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZdd	l
m
Z
mZdd
lmZy2ddlZddlmZmZmZmZWn*ek
r"ejdkr�dZYnXd
ZdZej�ZdZdgZeed�rldZedg7Zejdkr�dZedg7Zedd�Zdd�Zdd�Z dd�Z!dd�Z"Gdd�d�Z#er�Gdd�de#�Z$Gd d!�d!e#�Z%Gd"d�de&�Z'ddd#d�Z(ejdkr[d$d%d�Z)nd$d&d�Z)Gd'd(�d(e&�Z*d)d*�Z+ejdkr�Gd+d,�d,e&�Z,d-d.�Z-d/Z.d0Z/d1Z0d2Z1d3d4�Z2d5d6�Z3Gd7d8�d8e&�Z4d9d:�Z5d;d<�Z6Gd=d>�d>e'�Z7d?d@�Z8ejdkr|dAdB�Z9ej:ej;hZ<ddCd�Z=n?ddl>Z>ee>dD�r�e>j?Z@n	e>jAZ@ddEd�Z=ejdkrdFdG�ZBdHdI�ZCejDe%eB�dJdK�ZEdLdM�ZFejDe$eE�n(dNdG�ZBdOdI�ZCejDe%eB�dS)P�Client�Listener�Pipe�wait�N�)�	reduction)�util)�AuthenticationError�BufferTooShort)�ForkingPickler)�
WAIT_OBJECT_0�WAIT_ABANDONED_0�WAIT_TIMEOUT�INFINITE�win32i g4@�AF_INET�AF_UNIX�AF_PIPEcCstj�|S)N)�time)�timeout�r�?/opt/alt/python35/lib64/python3.5/multiprocessing/connection.py�
_init_timeout;srcCstj�|kS)N)r)�trrr�_check_timeout>srcCs�|dkrd
S|dkr8tjdddtj��S|dkrptjdd	tj�tt�fdd
�Std��dS)z?
    Return an arbitrary free address for the given family
    r�	localhostrr�prefixz	listener-�dirrz\\.\pipe\pyc-%d-%d-�zunrecognized familyN)rr)	�tempfileZmktemprZget_temp_dir�os�getpid�next�
_mmap_counter�
ValueError)�familyrrr�arbitrary_addressEs r&cCsitjdkr+|dkr+td|��tjdkre|dkrett|�setd|��dS)zD
    Checks if the family is valid for the current environment.
    rrzFamily %s is not recognized.rN)�sys�platformr$�hasattr�socket)r%rrr�_validate_familySs
r+cCset|�tkrdSt|�tkr;|jd�r;dSt|�tkrQdStd|��dS)z]
    Return the types of the address

    This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
    rz\\rrzaddress type of %r unrecognizedN)�type�tuple�str�
startswithr$)�addressrrr�address_type_s!r1c@s!eZdZdZdddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
dd��Ze
dd��Ze
dd��Z
dd�Zdd�Zdddd�Zdd�Zddd�Zdd d!�Zd"d#�Zd$d%d&�Zd'd(�Zd)d*�ZdS)+�_ConnectionBaseNTcCs]|j�}|dkr$td��|r>|r>td��||_||_||_dS)Nrzinvalid handlez6at least one of `readable` and `writable` must be True)�	__index__r$�_handle�	_readable�	_writable)�self�handle�readable�writablerrr�__init__us			z_ConnectionBase.__init__cCs|jdk	r|j�dS)N)r4�_close)r7rrr�__del__�sz_ConnectionBase.__del__cCs|jdkrtd��dS)Nzhandle is closed)r4�OSError)r7rrr�
_check_closed�sz_ConnectionBase._check_closedcCs|jstd��dS)Nzconnection is write-only)r5r>)r7rrr�_check_readable�s	z_ConnectionBase._check_readablecCs|jstd��dS)Nzconnection is read-only)r6r>)r7rrr�_check_writable�s	z_ConnectionBase._check_writablecCs/|jrd|_n
|j�td��dS)NFzbad message length)r6r5�closer>)r7rrr�_bad_message_length�s	
z#_ConnectionBase._bad_message_lengthcCs
|jdkS)z True if the connection is closedN)r4)r7rrr�closed�sz_ConnectionBase.closedcCs|jS)z"True if the connection is readable)r5)r7rrrr9�sz_ConnectionBase.readablecCs|jS)z"True if the connection is writable)r6)r7rrrr:�sz_ConnectionBase.writablecCs|j�|jS)z+File descriptor or handle of the connection)r?r4)r7rrr�fileno�s
z_ConnectionBase.filenocCs.|jdk	r*z|j�Wdd|_XdS)zClose the connectionN)r4r<)r7rrrrB�sz_ConnectionBase.closercCs�|j�|j�t|�}|jdkrAtt|��}t|�}|dkretd��||kr}td��|dkr�||}n7|dkr�td��n|||kr�td��|j||||��dS)z,Send the bytes data from a bytes-like objectrrzoffset is negativezbuffer length < offsetNzsize is negativezbuffer length < offset + size)r?rA�
memoryview�itemsize�bytes�lenr$�_send_bytes)r7�buf�offset�size�m�nrrr�
send_bytes�s"


z_ConnectionBase.send_bytescCs.|j�|j�|jtj|��dS)zSend a (picklable) objectN)r?rArJr�dumps)r7�objrrr�send�s

z_ConnectionBase.sendcCsg|j�|j�|dk	r8|dkr8td��|j|�}|dkr]|j�|j�S)z7
        Receive bytes data as a bytes object.
        Nrznegative maxlength)r?r@r$�_recv_bytesrC�getvalue)r7Z	maxlengthrKrrr�
recv_bytes�s


z_ConnectionBase.recv_bytescCs�|j�|j�t|���}|j}|t|�}|dkrWtd��n||krotd��|j�}|j�}|||kr�t|j	���|j
d�|j||||||��|SWdQRXdS)zq
        Receive bytes data into a writeable bytes-like object.
        Return the number of bytes read.
        rznegative offsetzoffset too largeN)r?r@rFrGrIr$rT�tellr
rU�seek�readinto)r7rKrLrNrGZbytesize�resultrMrrr�recv_bytes_into�s"

	
z_ConnectionBase.recv_bytes_intocCs3|j�|j�|j�}tj|j��S)zReceive a (picklable) object)r?r@rTr�loads�	getbuffer)r7rKrrr�recv�s

z_ConnectionBase.recvgcCs!|j�|j�|j|�S)z/Whether there is any input available to be read)r?r@�_poll)r7rrrr�poll�s

z_ConnectionBase.pollcCs|S)Nr)r7rrr�	__enter__sz_ConnectionBase.__enter__cCs|j�dS)N)rB)r7�exc_type�	exc_value�exc_tbrrr�__exit__sz_ConnectionBase.__exit__)�__name__�
__module__�__qualname__r4r;r=r?r@rArC�propertyrDr9r:rErBrPrSrVr[r^r`rarerrrrr2rs(

r2c@saeZdZdZdZejdd�Zdd�Zddd	�Z	d
d�Z
dd
�ZdS)�PipeConnectionz�
        Connection class based on a Windows named pipe.
        Overlapped I/O is used, so the handles must have been created
        with FILE_FLAG_OVERLAPPED.
        FcCs||j�dS)N)r4)r7Z_CloseHandlerrrr<szPipeConnection._closecCs�tj|j|dd�\}}zJy.|tjkrQtj|jgdt�}Wn|j��YnXWd|jd�\}}XdS)N�
overlappedTF)	�_winapiZ	WriteFiler4�ERROR_IO_PENDING�WaitForMultipleObjects�eventr�cancel�GetOverlappedResult)r7rK�ov�err�waitresZnwrittenrrrrJs!
zPipeConnection._send_bytesNc	Csi|jrd|_tj�S|dkr.dnt|d�}y�tj|j|dd�\}}zJy.|tjkr�tj|j	gdt
�}Wn|j��YnXWd|jd�\}}|dkr�tj�}|j
|j��|S|tjkr|j||�SXWnCtk
rX}z#|jtjkrCt�n�WYdd}~XnXtd��dS)NF�rkTrz.shouldn't get here; expected KeyboardInterrupt)�_got_empty_message�io�BytesIO�minrl�ReadFiler4rmrnrorrprq�writer]ZERROR_MORE_DATA�_get_more_datar>�winerror�ERROR_BROKEN_PIPE�EOFError�RuntimeError)	r7�maxsizeZbsizerrrsrtZnread�f�errrrT&s6		
!
	zPipeConnection._recv_bytescCs?|js%tj|j�ddkr)dStt|g|��S)NrT)rvrl�
PeekNamedPiper4�boolr)r7rrrrr_Fs	zPipeConnection._pollcCs�|j�}tj�}|j|�tj|j�d}|dk	rgt|�||krg|j�tj	|j|dd�\}}|j
d�\}}|j|j��|S)NrrkT)r]rwrxr{rlr�r4rIrCrzrq)r7rrr�rKr��leftrsZrbytesrrrr|Ls
"
!zPipeConnection._get_more_data)rfrgrh�__doc__rvrl�CloseHandler<rJrTr_r|rrrrrjs rjc@s�eZdZdZer?ejdd�ZejZ	ej
Zn$ej
dd�ZejZ	ejZe	dd�Zedd�Zd	d
�Zddd
�Zdd�ZdS)�
Connectionzo
    Connection class based on an arbitrary file descriptor (Unix only), or
    a socket handle (Windows).
    cCs||j�dS)N)r4)r7r<rrrr<cszConnection._closecCs||j�dS)N)r4)r7r<rrrr<hscCsPt|�}x=||j|�}||8}|dkr8P||d�}qWdS)Nr)rIr4)r7rKr{�	remainingrOrrr�_sendms
zConnection._sendcCs�tj�}|j}|}xo|dkr�|||�}t|�}|dkrr||krft�ntd��|j|�||8}qW|S)Nrzgot end of file during message)rwrxr4rIrr>r{)r7rM�readrKr8r��chunkrOrrr�_recvvs		
zConnection._recvcCs\t|�}tjd|�}|dkrG|j|�|j|�n|j||�dS)Nz!ii@)rI�structZpackr�)r7rKrO�headerrrrrJ�s
zConnection._send_bytesNcCsS|jd�}tjd|j��\}|dk	rF||krFdS|j|�S)N�z!i)r�r�ZunpackrU)r7r�rKrMrrrrT�s
zConnection._recv_bytescCst|g|�}t|�S)N)rr�)r7r�rrrrr_�szConnection._poll)rfrgrhr�rl�_multiprocessingZclosesocketr<rSZ_writer^Z_readr rBr{r�r�r�rJrTr_rrrrr�\s				r�c@s�eZdZdZdddddd�Zdd�Zdd	�Zed
d��Zedd��Z	d
d�Z
dd�ZdS)rz�
    Returns a listener object.

    This is a wrapper for a bound socket which is 'listening' for
    connections, or for a Windows named pipe.
    NrcCs�|p|rt|�pt}|p-t|�}t|�|dkr[t||�|_nt|||�|_|dk	r�t|t�r�t	d��||_
dS)Nrzauthkey should be a byte string)r1�default_familyr&r+�PipeListener�	_listener�SocketListener�
isinstancerH�	TypeError�_authkey)r7r0r%�backlog�authkeyrrrr;�s
zListener.__init__cCsW|jdkrtd��|jj�}|jrSt||j�t||j�|S)zz
        Accept a connection on the bound socket or named pipe of `self`.

        Returns a `Connection` object.
        Nzlistener is closed)r�r>�acceptr��deliver_challenge�answer_challenge)r7�crrrr��s	zListener.acceptcCs,|j}|dk	r(d|_|j�dS)zA
        Close the bound socket or named pipe of `self`.
        N)r�rB)r7ZlistenerrrrrB�s		zListener.closecCs
|jjS)N)r��_address)r7rrr�<lambda>�szListener.<lambda>cCs
|jjS)N)r��_last_accepted)r7rrrr��scCs|S)Nr)r7rrrra�szListener.__enter__cCs|j�dS)N)rB)r7rbrcrdrrrre�szListener.__exit__)rfrgrhr�r;r�rBrir0Z
last_acceptedrarerrrrr�s	cCs�|pt|�}t|�|dkr7t|�}nt|�}|dk	rkt|t�rktd��|dk	r�t||�t||�|S)z=
    Returns a connection to the address of a `Listener`
    rNzauthkey should be a byte string)	r1r+�
PipeClient�SocketClientr�rHr�r�r�)r0r%r�r�rrrr�s


TcCs�|rYtj�\}}|jd�|jd�t|j��}t|j��}n6tj�\}}t|dd�}t|dd�}||fS)zL
        Returns pair of connection objects at either end of a pipe
        Tr:Fr9)r*Z
socketpair�setblockingr��detachr �pipe)�duplex�s1�s2�c1�c2Zfd1Zfd2rrrr�s

c
	CsAtd�}|r;tj}tjtjB}tt}}ntj}tj}dt}}tj||tjBtj	Btj
tjBtjBd||tj
tj�}tj||dtjtjtjtj�}tj|tjdd�tj|dd�}|jd�\}	}
t|d|�}t|d|�}||fS)	zL
        Returns pair of connection objects at either end of a pipe
        rrrNrkTr:r9)r&rl�PIPE_ACCESS_DUPLEX�GENERIC_READ�
GENERIC_WRITE�BUFSIZEZPIPE_ACCESS_INBOUND�CreateNamedPipe�FILE_FLAG_OVERLAPPED�FILE_FLAG_FIRST_PIPE_INSTANCE�PIPE_TYPE_MESSAGE�PIPE_READMODE_MESSAGE�	PIPE_WAIT�NMPWAIT_WAIT_FOREVER�NULL�
CreateFile�
OPEN_EXISTING�SetNamedPipeHandleState�ConnectNamedPiperqrj)
r�r0Zopenmode�accessZobsizeZibsizeZh1Zh2rk�_rsr�r�rrrrs2			


c@s=eZdZdZddd�Zdd�Zdd�Zd	S)
r�zO
    Representation of a socket which is bound to an address and listening
    rcCstjtt|��|_yqtjdkrI|jjtjtjd�|jjd�|jj	|�|jj
|�|jj�|_Wn"t
k
r�|jj��YnX||_d|_|dkr�tj|tjd|fdd�|_n	d|_dS)N�posixrTr�args�exitpriorityr)r*�getattr�_socketr �nameZ
setsockoptZ
SOL_SOCKETZSO_REUSEADDRr�ZbindZlistenZgetsocknamer�r>rBZ_familyr�r�Finalize�unlink�_unlink)r7r0r%r�rrrr;8s$


		$zSocketListener.__init__cCs5|jj�\}|_|jd�t|j��S)NT)r�r�r�r�r�r�)r7�srrrr�Ps
zSocketListener.acceptcCs>z|jj�Wd|j}|dk	r9d|_|�XdS)N)r�rBr�)r7r�rrrrBUs		zSocketListener.closeN)rfrgrhr�r;r�rBrrrrr�4sr�c	Cs\t|�}tjtt|���1}|jd�|j|�t|j��SWdQRXdS)zO
    Return a connection object connected to the socket given by `address`
    TN)r1r*r�r�Zconnectr�r�)r0r%r�rrrr�_s


r�c@sReZdZdZddd�Zddd�Zdd	�Zed
d��ZdS)r�z0
        Representation of a named pipe
        NcCsq||_|jdd�g|_d|_tjd|j�tj|tjd|j|jfdd�|_	dS)N�firstTz listener created with address=%rr�r�r)
r��_new_handle�
_handle_queuer�r�	sub_debugr�r��_finalize_pipe_listenerrB)r7r0r�rrrr;ss		zPipeListener.__init__Fc	CsbtjtjB}|r#|tjO}tj|j|tjtjBtjBtj	t
t
tjtj�S)N)
rlr�r�r�r�r�r�r�r�ZPIPE_UNLIMITED_INSTANCESr�r�r�)r7r��flagsrrrr�~s
	
zPipeListener._new_handlecCs�|jj|j��|jjd�}ytj|dd�}Wn:tk
r}}z|jtjkrk�WYdd}~XnbXzHytj	|j
gdt�}Wn"|j�tj
|��YnXWd|jd�\}}Xt|�S)NrrkTF)r��appendr��poprlr�r>r}Z
ERROR_NO_DATArnrorrpr�rqrj)r7r8rrr��resr�rsrrrr��s"

zPipeListener.acceptcCs2tjd|�x|D]}tj|�qWdS)Nz closing listener with address=%r)rr�rlr�)Zqueuer0r8rrrr��s
z$PipeListener._finalize_pipe_listener)	rfrgrhr�r;r�r��staticmethodr�rrrrr�os
r�cCs�t�}x�yKtj|d�tj|tjtjBdtjtjtjtj�}WnOt	k
r�}z/|j
tjtjfks�t
|�r��WYdd}~XqXPqW�tj|tjdd�t|�S)zU
        Return a connection object connected to the pipe given by `address`
        i�rN)rrlZ
WaitNamedPiper�r�r�r�r�r�r>r}ZERROR_SEM_TIMEOUTZERROR_PIPE_BUSYrr�r�rj)r0r�hr�rrrr��s"	r��s#CHALLENGE#s	#WELCOME#s	#FAILURE#cCs�ddl}tjt�}|jt|�|j||d�j�}|jd�}||krr|jt	�n|jt
�td��dS)Nr�md5�zdigest received was wrong)�hmacr �urandom�MESSAGE_LENGTHrP�	CHALLENGE�new�digestrV�WELCOME�FAILUREr	)�
connectionr�r��messager��responserrrr��s
r�cCs�ddl}|jd�}|tt�d�}|j||d�j�}|j|�|jd�}|tkr�td��dS)Nrr�r�zdigest sent was rejected)	r�rVrIr�r�r�rPr�r	)r�r�r�r�r�r�rrrr��s
r�c@s4eZdZdd�Zdd�Zdd�ZdS)�ConnectionWrappercCsO||_||_||_x-dD]%}t||�}t|||�q"WdS)NrErBr`rVrP)rErBr`rVrP)�_conn�_dumps�_loadsr��setattr)r7�connrQr\�attrrRrrrr;�s			
zConnectionWrapper.__init__cCs#|j|�}|jj|�dS)N)r�r�rP)r7rRr�rrrrS�szConnectionWrapper.sendcCs|jj�}|j|�S)N)r�rVr�)r7r�rrrr^�szConnectionWrapper.recvN)rfrgrhr;rSr^rrrrr��sr�cCs%tj|fdddd�jd�S)Nrzutf-8)�	xmlrpclibrQ�encode)rRrrr�
_xml_dumps�sr�cCs%tj|jd��\\}}|S)Nzutf-8)r�r\�decode)r�rR�methodrrr�
_xml_loads�s!r�c@seZdZdd�ZdS)�XmlListenercCs.ddljatj|�}t|tt�S)Nr)�
xmlrpc.client�clientr�rr�r�r�r�)r7rRrrrr�szXmlListener.acceptN)rfrgrhr�rrrrr��sr�cOs(ddljatt||�tt�S)Nr)r�r�r�r�rr�r�)r��kwdsrrr�	XmlClientsr�cCs�t|�}g}x�|r�tj|d|�}|tkr@Pnrt|koatt|�knrs|t8}n?t|ko�tt|�knr�|t8}ntd��|j||�||dd�}d}qW|S)NFzShould not get hererr)	�listrlrnrrrIr
r�r�)Zhandlesr�L�readyr�rrr�_exhaustive_waits	&
&

r�c
.s
|dkrt}n)|dkr*d}nt|dd�}t|�}i�g}t��t�}z�xy|D]q}yt|d�}Wn"tk
r�|�|j�<YqrXy"tj|�dd�\}}WnDt	k
r}z$d|j
}}|tkr�WYdd}~XnX|tjkrE|j
|�|�|j<qr|r�tj�dd�dkr�y|jd	�\}	}Wn.t	k
r�}z|j
}WYdd}~XnX|r�t|d
�r�d|_�j|�d}qrWt�j�|�}Wdx|D]}|j�qWx�|D]�}y|jd�\}	}Wn=t	k
r�}z|j
}|tkrn�WYdd}~XnX|tjkr"�|j}�j|�|dkr"t|d
�r"d|_q"WX�j�fdd�|D���fd
d�|D�S)z�
        Wait till an object in object_list is ready/readable.

        Returns list of those objects in object_list which are ready/readable.
        Nri�g�?rET��Frvc3s|]}�|VqdS)Nr)�.0r�)�waithandle_to_objrr�	<genexpr>rszwait.<locals>.<genexpr>cs"g|]}|�kr|�qSrr)r��o)�
ready_objectsrr�
<listcomp>ss	zwait.<locals>.<listcomp>)r�r�)r�intr��setr��AttributeErrorr3rlrzr>r}�
_ready_errorsrmr�ror'Zgetwindowsversionrqr)rv�addr��keysrpZERROR_OPERATION_ABORTED�update)
�object_listrZov_listZ
ready_handlesr�rErrrsr�r�r)r�r�rr'sh				

"
"	



	

 �PollSelectorcCs�t���}x!|D]}|j|tj�qW|dk	rLtj�|}xV|j|�}|rudd�|D�S|dk	rO|tj�}|dkrO|SqOWWdQRXdS)z�
        Wait till an object in object_list is ready/readable.

        Returns list of those objects in object_list which are ready/readable.
        NcSsg|]\}}|j�qSr)Zfileobj)r��keyZeventsrrrr�s	zwait.<locals>.<listcomp>r)�
_WaitSelector�register�	selectorsZ
EVENT_READrZselect)rrZselectorrRZdeadliner�rrrr�s
cCsm|j�}tj|tjtj��?}ddlm}|j|�}t||j	|j
ffSWdQRXdS)Nr)�resource_sharer)rEr*ZfromfdrZSOCK_STREAMrrZ	DupSocket�rebuild_connectionr9r:)r�r8r�r�dsrrr�reduce_connection�s
rcCs"|j�}t|j�||�S)N)r�r�)rr9r:Zsockrrrr�srcCs_|jrtjnd|jr'tjndB}tj|j�|�}t||j|jffS)Nr)	r9rlZFILE_GENERIC_READr:ZFILE_GENERIC_WRITErZ	DupHandlerE�rebuild_pipe_connection)r�r��dhrrr�reduce_pipe_connection�srcCs|j�}t|||�S)N)r�rj)rr9r:r8rrrr�srcCs.tj|j��}t||j|jffS)N)rZDupFdrErr9r:)r��dfrrrr�scCs|j�}t|||�S)N)r�r�)rr9r:�fdrrrr�s)G�__all__rwr r'r*r�rr�	itertoolsr�rrrr	r
rrlrr
rr�ImportErrorr(r�ZCONNECTION_TIMEOUT�countr#r�Zfamiliesr)rrr&r+r1r2rjr��objectrrrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r~ZERROR_NETNAME_DELETEDrrr
r	rZSelectSelectorrrrrrrrrr�<module>
s�&
	

�PJ8,+8
	P	

?>