Your IP : 3.149.255.239


Current Path : /opt/alt/python34/lib64/python3.4/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/multiprocessing/__pycache__/connection.cpython-34.pyo

�
e fz�@sXddddgZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZdd	l
m
Z
mZdd
lmZy2ddlZddlmZmZmZmZWn-ek
r%ejdkr�ndZYnXd
ZdZej�ZdZdgZeed�rrdZedg7Znejdkr�dZedg7Znedd�Zdd�Zdd�Z dd�Z!dd�Z"Gdd�d�Z#erGdd�de#�Z$nGd d!�d!e#�Z%Gd"d�de&�Z'ddd#d�Z(ejdkrgd$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-nd/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kr,dFdG�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/python34/lib64/python3.4/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&cCsrtjdkr.|dkr.td|��ntjdkrn|dkrntt|�sntd|��qnndS)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)+�_ConnectionBaseNTcCsc|j�}|dkr'td��n|rD|rDtd��n||_||_||_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�ndS)N)r4�_close)r7rrr�__del__�sz_ConnectionBase.__del__cCs"|jdkrtd��ndS)Nzhandle is closed)r4�OSError)r7rrr�
_check_closed�sz_ConnectionBase._check_closedcCs|jstd��ndS)Nzconnection is write-only)r5r>)r7rrr�_check_readable�s	z_ConnectionBase._check_readablecCs|jstd��ndS)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.filenocCs1|jdk	r-z|j�Wdd|_XndS)zClose the connectionN)r4r<)r7rrrrB�sz_ConnectionBase.closercCs�|j�|j�t|�}|jdkrDtt|��}nt|�}|dkrktd��n||kr�td��n|dkr�||}n:|dkr�td��n|||kr�td��n|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.sendcCsm|j�|j�|dk	r;|dkr;td��n|j|�}|dkrc|j�n|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||krrtd��n|j�}|j�}|||kr�t|j	���n|j
d�|j||||||��|SWdQXdS)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�\}}zMy1|tjkrTtj|jgdt�}nWn|j��YnXWd|jd�\}}XdS)N�
overlappedTF)	�_winapiZ	WriteFiler4�ERROR_IO_PENDING�WaitForMultipleObjects�eventr�cancel�GetOverlappedResult)r7rK�ov�err�waitresZnwrittenrrrrJs!
zPipeConnection._send_bytesNc	Csl|jrd|_tj�S|dkr.dnt|d�}y�tj|j|dd�\}}zMy1|tjkr�tj|j	gdt
�}nWn|j��YnXWd|jd�\}}|dkr�tj�}|j
|j��|S|tjkr|j||�SXWnCtk
r[}z#|jtjkrFt�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	rjt|�||krj|j�ntj	|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<hscCsot|�}x\y||j|�}Wntk
r<wYnX||8}|dkrWPn||d�}qWdS)Nr)rIr4�InterruptedError)r7rKr{�	remainingrOrrr�_sendms

zConnection._sendcCs�tj�}|j}|}x�|dkr�y|||�}Wntk
rTwYnXt|�}|dkr�||kr�t�q�td��n|j|�||8}qW|S)Nrzgot end of file during message)rwrxr4r�rIrr>r{)r7rM�readrKr8r��chunkrOrrr�_recvys 	
	
zConnection._recvcCs�t|�}tjd|�}|dkr9||g}n%|dkrU||g}n	|g}x|D]}|j|�qeWdS)Nz!ii@r)rI�structZpackr�)r7rKrO�headerZchunksr�rrrrJ�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��n||_
dS)Nrzauthkey should be a byte string)r1�default_familyr&r+�PipeListener�	_listener�SocketListener�
isinstancerH�	TypeError�_authkey)r7r0r%�backlog�authkeyrrrr;�s
zListener.__init__cCs]|jdkrtd��n|jj�}|jrYt||j�t||j�n|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�ndS)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	rnt|t�rntd��n|dk	r�t||�t||�n|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
    rcCs	tjtt|��|_yttjdkrL|jjtjtjd�n|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;As$

		$zSocketListener.__init__cCsVx6y|jj�\}|_Wntk
r3YqXPqW|jd�t|j��S)NT)r�r�r�r�r�r�r�)r7�srrrr�Ys

zSocketListener.acceptcCsAz|jj�Wd|j}|dk	r<d|_|�nXdS)N)r�rBr�)r7r�rrrrBds		zSocketListener.closeN)rfrgrhr�r;r�rBrrrrr�=sr�c	Cs[t|�}tjtt|���1}|jd�|j|�t|j��SWdQXdS)zO
    Return a connection object connected to the socket given by `address`
    TN)r1r*r�r�Zconnectr�r�)r0r%r�rrrr�ns


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;�s		zPipeListener.__init__Fc	CsetjtjB}|r&|tjO}ntj|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|jtjkrn�nWYdd}~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�~s
r�cCs�t�}x�yKtj|d�tj|tjtjBdtjtjtjtj�}WnRt	k
r�}z2|j
tjtjfks�t
|�r��nWYdd}~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��ndS)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)zfilenozclosezpollz
recv_bytesz
send_bytes)�_conn�_dumps�_loadsr��setattr)r7�connrQr\�attrrRrrrr;�s			
zConnectionWrapper.__init__cCs#|j|�}|jj|�dS)N)r�r�rP)r7rRr�rrrrSszConnectionWrapper.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_dumpssr�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_wait s	&
&

r�c
.s|dkrt}n)|dkr*d}nt|dd�}t|�}i�g}t��t�}z�x�|D]z}yt|d�}Wn"tk
r�|�|j�<YqrXy"tj|�dd�\}}WnGt	k
r}z'd|j
}}|tkr	�nWYdd}~XnX|tjkrH|j
|�|�|j<qr|r�tj�dd�dkr�y|jd	�\}	}Wn.t	k
r�}z|j
}WYdd}~XnX|r�t|d
�r�d|_q�n�j|�d}qrWt�j�|�}Wdx|D]}|j�qWx�|D]�}y|jd�\}	}Wn@t	k
r�}z |j
}|tkrz�nWYdd}~XnX|tjkr+�|j}�j|�|dkr�t|d
�r�d|_q�q�q+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>�szwait.<locals>.<genexpr>cs"g|]}|�kr|�qSrr)r��o)�
ready_objectsrr�
<listcomp>�s	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)rr�rr6sh				

"
"



	

 �PollSelectorcCs�t���}x!|D]}|j|tj�qW|dk	rOtj�|}nxY|j|�}|rxdd�|D�S|dk	rR|tj�}|dkr�|SqRqRWWdQXdS)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)r	rZselectorrRZdeadliner�rrrr�s
cCsl|j�}tj|tjtj��?}ddlm}|j|�}t||j	|j
ffSWdQXdS)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_DELETEDrrrr
rZSelectSelectorrrr
rrrrrr�<module>
s�&
	�PS8,18
	P	

?>