Your IP : 18.222.179.96


Current Path : /opt/alt/python310/lib64/python3.10/multiprocessing/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/multiprocessing/__pycache__/connection.cpython-310.pyc

o

6��f�{�@s�gd�ZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZm
Z
ddlmZejZzddlZddlmZmZmZmZWneybejdkr^�dZYnwd	Zd
Ze��ZdZdgZeed�r|dZedg7Zejdkr�d
Zed
g7Zefdd�Z dd�Z!dd�Z"dd�Z#dd�Z$Gdd�d�Z%er�Gdd�de%�Z&Gdd�de%�Z'Gdd�de(�Z)dPd d!�Z*ejdkr�dQd#d$�Z+ndQd%d$�Z+Gd&d'�d'e(�Z,d(d)�Z-ejdkr�Gd*d+�d+e(�Z.d,d-�Z/d.Z0d/Z1d0Z2d1Z3d2d3�Z4d4d5�Z5Gd6d7�d7e(�Z6d8d9�Z7d:d;�Z8Gd<d=�d=e)�Z9d>d?�Z:ejdk�r3d@dA�Z;ej<ej=hZ>dRdBdC�Z?nddl@Z@ee@dD��rAe@jAZBne@jCZBdRdEdC�Z?ejdk�rmdFdG�ZDdHdI�ZEe�Fe'eD�dJdK�ZGdLdM�ZHe�Fe&eG�dSdNdG�ZDdOdI�ZEe�Fe'eD�dS)S)�Client�Listener�Pipe�wait�N�)�util)�AuthenticationError�BufferTooShort)�	reduction)�
WAIT_OBJECT_0�WAIT_ABANDONED_0�WAIT_TIMEOUT�INFINITE�win32i g4@�AF_INET�AF_UNIX�AF_PIPEcCst��|S�N��time�	monotonic)�timeout�r�A/opt/alt/python310/lib64/python3.10/multiprocessing/connection.py�
_init_timeout;�rcCst��|kSrr)�trrr�_check_timeout>rrcCsT|dkrdS|dkrtjdt��d�S|dkr&tjdt��tt�fdd�Std	��)
z?
    Return an arbitrary free address for the given family
    r)Z	localhostrrz	listener-)�prefix�dirrz\\.\pipe\pyc-%d-%d-�zunrecognized family)	�tempfileZmktemprZget_temp_dir�os�getpid�next�
_mmap_counter�
ValueError��familyrrr�arbitrary_addressEs��r)cCsRtjdkr|dkrtd|��tjdkr#|dkr%tt|�s'td|��dSdSdS)zD
    Checks if the family is valid for the current environment.
    rrzFamily %s is not recognized.rN)�sys�platformr&�hasattr�socketr'rrr�_validate_familySs
�r.cCsPt|�tkrdSt|�tur|�d�rdSt|�tus t�|�r"dStd|��)z]
    Return the types of the address

    This can be 'AF_INET', 'AF_UNIX', or 'AF_PIPE'
    rz\\rrzaddress type of %r unrecognized)�type�tuple�str�
startswithr�is_abstract_socket_namespacer&)�addressrrr�address_type_sr5c@s�eZdZdZd+dd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	e
dd��Ze
dd��Ze
dd��Z
dd�Zdd�Zd,dd�Zdd�Zd-dd�Zd.d d!�Zd"d#�Zd/d%d&�Zd'd(�Zd)d*�ZdS)0�_ConnectionBaseNTcCs>|��}|dkrtd��|s|std��||_||_||_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|jdur|��dSdSr�r8�_close�r;rrr�__del__�s
�z_ConnectionBase.__del__cCs|jdur	td��dS)Nzhandle is closed)r8�OSErrorrBrrr�
_check_closed�s
�z_ConnectionBase._check_closedcC�|jstd��dS)Nzconnection is write-only)r9rDrBrrr�_check_readable���z_ConnectionBase._check_readablecCrF)Nzconnection is read-only)r:rDrBrrr�_check_writable�rHz_ConnectionBase._check_writablecCs$|jr
d|_td��|��td��)NFzbad message length)r:r9�closerDrBrrr�_bad_message_length�s
�z#_ConnectionBase._bad_message_lengthcCs
|jduS)z True if the connection is closedN�r8rBrrr�closed�s
z_ConnectionBase.closedcC�|jS)z"True if the connection is readable)r9rBrrrr=��z_ConnectionBase.readablecCrN)z"True if the connection is writable)r:rBrrrr>�rOz_ConnectionBase.writablecCs|��|jS)z+File descriptor or handle of the connection)rEr8rBrrr�fileno�sz_ConnectionBase.filenocCs,|jdurz
|��Wd|_dSd|_wdS)zClose the connectionNr@rBrrrrJ�s


�z_ConnectionBase.closercCs�|��|��t|�}|jdkrtt|��}t|�}|dkr#td��||kr+td��|dur4||}n|dkr<td��|||krFtd��|�||||��dS)z,Send the bytes data from a bytes-like objectrrzoffset is negativezbuffer length < offsetNzsize is negativezbuffer length < offset + size)rErI�
memoryview�itemsize�bytes�lenr&�_send_bytes)r;�buf�offset�size�m�nrrr�
send_bytes�s"

z_ConnectionBase.send_bytescCs$|��|��|�t�|��dS)zSend a (picklable) objectN)rErIrU�_ForkingPickler�dumps�r;�objrrr�send�sz_ConnectionBase.sendcCsJ|��|��|dur|dkrtd��|�|�}|dur!|��|��S)z7
        Receive bytes data as a bytes object.
        Nrznegative maxlength)rErGr&�_recv_bytesrK�getvalue)r;Z	maxlengthrVrrr�
recv_bytes�s
z_ConnectionBase.recv_bytescCs�|��|��t|��K}|j}|t|�}|dkrtd��||kr&td��|��}|��}|||kr:t|�	���|�
d�|�||||||��|Wd�S1sZwYdS)zq
        Receive bytes data into a writeable bytes-like object.
        Return the number of bytes read.
        rznegative offsetzoffset too largeN)rErGrQrRrTr&ra�tellr	rb�seek�readinto)r;rVrWrYrRZbytesize�resultrXrrr�recv_bytes_into�s&


�$�z_ConnectionBase.recv_bytes_intocCs&|��|��|��}t�|���S)zReceive a (picklable) object)rErGrar\�loads�	getbuffer)r;rVrrr�recv�sz_ConnectionBase.recv�cCs|��|��|�|�S)z/Whether there is any input available to be read)rErG�_poll�r;rrrr�poll�s
z_ConnectionBase.pollcC�|SrrrBrrr�	__enter__�z_ConnectionBase.__enter__cC�|��dSr�rJ�r;�exc_type�	exc_valueZexc_tbrrr�__exit__rz_ConnectionBase.__exit__)TT)rNr)r)rl)�__name__�
__module__�__qualname__r8r?rCrErGrIrK�propertyrMr=r>rPrJr[r`rcrhrkrorqrxrrrrr6rs0









r6c@sDeZdZdZdZejfdd�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.
        FcC�||j�dSrrL)r;Z_CloseHandlerrrrA�zPipeConnection._closec	Cs�tj|j|dd�\}}z(z|tjkr!t�|jgdt�}|tks!J�Wn|���W|�	d�\}}n|�	d�\}}w|dksBJ�|t
|�ksJJ�dS)NT��
overlappedFr)�_winapiZ	WriteFiler8�ERROR_IO_PENDING�WaitForMultipleObjects�eventrr�cancel�GetOverlappedResultrT)r;rV�ov�err�waitresZnwrittenrrrrUs

��� zPipeConnection._send_bytesNc	
Csh|jr
d|_t��S|durdnt|d�}z�tj|j|dd�\}}zFz|tjkr7t�|j	gdt
�}|tks7J�Wn|���W|�
d�\}}|dkr[t��}|�|���|WS|tjkrg|�||�WSn2|�
d�\}}|dkr�t��}|�|���|YWS|tjkr�|�||�YWSwWtd��ty�}z	|jtjkr�t��d}~ww)NF�Tr�rz.shouldn't get here; expected KeyboardInterrupt)�_got_empty_message�io�BytesIO�minr��ReadFiler8r�r�r�rrr�r��writerjZERROR_MORE_DATA�_get_more_datarD�winerror�ERROR_BROKEN_PIPE�EOFError�RuntimeError)	r;�maxsizeZbsizer�r�r�Znread�f�errrra&sT

�

���
��
����zPipeConnection._recv_bytescCs.|js
t�|j�ddkrdStt|g|��S)NrT)r�r��
PeekNamedPiper8�boolrrnrrrrmFszPipeConnection._pollcCs�|��}t��}|�|�t�|j�d}|dksJ�|dur+t|�||kr+|��tj	|j|dd�\}}|�
d�\}}|dksCJ�||ksIJ�|�|���|S)NrrTr�)rjr�r�r�r�r�r8rTrKr�r�)r;r�r�rVr��leftr�Zrbytesrrrr�Ls
zPipeConnection._get_more_datar)ryrzr{�__doc__r�r��CloseHandlerArUrarmr�rrrrr}s
 r}c@s|eZdZdZerejfdd�ZejZ	ej
Zn
ej
fdd�ZejZ	ejZe	fdd�Zefdd�Zd	d
�Zddd
�Zdd�ZdS)�
Connectionzo
    Connection class based on an arbitrary file descriptor (Unix only), or
    a socket handle (Windows).
    cCr~rrL�r;rArrrrAcrzConnection._closecCr~rrLr�rrrrAhrcCs8t|�}	||j|�}||8}|dkrdS||d�}q)NTr)rTr8)r;rVr��	remainingrZrrr�_sendms�zConnection._sendcCsft��}|j}|}|dkr1|||�}t|�}|dkr$||kr t�td��|�|�||8}|dks
|S)Nrzgot end of file during message)r�r�r8rTr�rDr�)r;rX�readrVr<r��chunkrZrrr�_recvvs

�
zConnection._recvcCs�t|�}|dkr%t�dd�}t�d|�}|�|�|�|�|�|�dSt�d|�}|dkr;|�|�|�|�dS|�||�dS)Ni����!i����!Qi@)rT�structZpackr�)r;rVrZZ
pre_header�headerrrrrU�s


zConnection._send_bytesNcCs^|�d�}t�d|���\}|dkr |�d�}t�d|���\}|dur*||kr*dS|�|�S)N�r�r��r�)r�r�Zunpackrb)r;r�rVrXrrrra�s


zConnection._recv_bytescCst|g|�}t|�Sr)rr�)r;r�rrrrrm�szConnection._pollr)ryrzr{r�r��_multiprocessingZclosesocketrAr`Z_writerkZ_readr"rJr�r�r�r�rUrarmrrrrr�\s	

r�c@sReZdZdZddd�Zdd�Zdd	�Zed
d��Zedd
��Z	dd�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.
    NrcCsp|p	|rt|�p	t}|pt|�}t|�|dkrt||�|_nt|||�|_|dur3t|t�s3t	d��||_
dS)Nr�authkey should be a byte string)r5�default_familyr)r.�PipeListener�	_listener�SocketListener�
isinstancerS�	TypeError�_authkey)r;r4r(�backlog�authkeyrrrr?�s�
zListener.__init__cCs>|jdur	td��|j��}|jrt||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�rD�acceptr��deliver_challenge�answer_challenge)r;�crrrr��s

zListener.acceptcCs$|j}|durd|_|��dSdS)zA
        Close the bound socket or named pipe of `self`.
        N)r�rJ)r;ZlistenerrrrrJ�s
�zListener.closecC�|jjSr)r��_addressrBrrrr4��zListener.addresscCr�r)r��_last_acceptedrBrrr�
last_accepted�r�zListener.last_acceptedcCrprrrBrrrrq�rrzListener.__enter__cCrsrrtrurrrrx�rzListener.__exit__)NNrN)ryrzr{r�r?r�rJr|r4r�rqrxrrrrr�s
	

rcCsh|pt|�}t|�|dkrt|�}nt|�}|dur$t|t�s$td��|dur2t||�t||�|S)z=
    Returns a connection to the address of a `Listener`
    rNr�)	r5r.�
PipeClient�SocketClientr�rSr�r�r�)r4r(r�r�rrrr�s


rTcCsp|r"t��\}}|�d�|�d�t|���}t|���}||fSt��\}}t|dd�}t|dd�}||fS)�L
        Returns pair of connection objects at either end of a pipe
        TF�r>�r=)r-Z
socketpair�setblockingr��detachr"�pipe)�duplex�s1�s2�c1�c2Zfd1Zfd2rrrrs

�rc

Cs�td�}|rtj}tjtjB}tt}}ntj}tj}dt}}t�||tjBtj	Btj
tjBtjBd||tj
tj�}t�||dtjtjtjtj�}t�|tjdd�tj|dd�}|�d�\}	}
|
dksgJ�t||d�}t||d�}||fS)	r�rrrNTr�r�r�)r)r��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�ConnectNamedPiper�r})
r�r4Zopenmode�accessZobsizeZibsizeZh1Zh2r��_r�r�r�rrrrs>

�
�
�	�
�c@s*eZdZdZd
dd�Zdd�Zdd�Zd	S)r�zO
    Representation of a socket which is bound to an address and listening
    rcCs�t�tt|��|_z)tjdkr|j�tjtjd�|j�d�|j�	|�|j�
|�|j��|_Wn
t
y?|j���w||_d|_|dkr]t�|�s]tj|tj|fdd�|_dSd|_dS)N�posixrTrr��argsZexitpriority)r-�getattr�_socketr"�nameZ
setsockoptZ
SOL_SOCKETZSO_REUSEADDRr�ZbindZlistenZgetsocknamer�rDrJZ_familyr�rr3�Finalize�unlink�_unlink)r;r4r(r�rrrr?Gs*

�
��
zSocketListener.__init__cCs&|j��\}|_|�d�t|���S)NT)r�r�r�r�r�r��r;�srrrr�`s
zSocketListener.acceptcCsNz|j��W|j}|durd|_|�dSdS|j}|dur&d|_|�wwr)r�rJr�)r;r�rrrrJes
���zSocketListener.closeN)r)ryrzr{r�r?r�rJrrrrr�Cs

r�cCs\t|�}t�tt|���}|�d�|�|�t|���Wd�S1s'wYdS)zO
    Return a connection object connected to the socket given by `address`
    TN)r5r-r�r�Zconnectr�r�)r4r(r�rrrr�os


$�r�c@s8eZdZdZddd�Zd
dd�Zdd	�Zed
d��ZdS)r�z0
        Representation of a named pipe
        NcCsL||_|jdd�g|_d|_t�d|j�tj|tj|j|jfdd�|_	dS)NT)�firstz listener created with address=%rrr�)
r��_new_handle�
_handle_queuer�r�	sub_debugr�r��_finalize_pipe_listenerrJ)r;r4r�rrrr?�s�zPipeListener.__init__Fc
CsHtjtjB}|r
|tjO}t�|j|tjtjBtjBtj	t
t
tjtj�Sr)
r�r�r�r�r�r�r�r�r�ZPIPE_UNLIMITED_INSTANCESr�r�r�)r;r��flagsrrrr��s

��zPipeListener._new_handlec
Cs�|j�|���|j�d�}z	tj|dd�}Wnty3}z|jtjkr&�WYd}~t|�Sd}~wwz+zt�	|j
gdt�}Wn
|��t�
|��W|�d�\}}|dks\J�t|�S|�d�\}}|dksmJ�w)NrTr�F)r��appendr��popr�r�rDr�Z
ERROR_NO_DATAr�r�rr�r�r�r})r;r<r�r��resr�r�rrrr��s2
���
�
��zPipeListener.acceptcCs$t�d|�|D]}t�|�qdS)Nz closing listener with address=%r)rr�r�r�)�queuer4r<rrrr��s�z$PipeListener._finalize_pipe_listenerr)F)	ryrzr{r�r?r�r��staticmethodr�rrrrr�s

r�c
Cs�t�}	zt�|d�t�|tjtjBdtjtjtjtj�}Wn t	y?}z|j
tjtjfvs4t
|�r5�WYd}~nd}~wwnqt�|tjdd�t|�S)zU
        Return a connection object connected to the pipe given by `address`
        r��rN)rr�Z
WaitNamedPiper�r�r�r�r�r�rDr�ZERROR_SEM_TIMEOUTZERROR_PIPE_BUSYrr�r�r})r4r�hr�rrrr��s2
�������
�r��s#CHALLENGE#s	#WELCOME#s	#FAILURE#cCs�ddl}t|t�std�t|����t�t�}|�	t
|�|�||d���}|�
d�}||kr7|�	t�dS|�	t�td��)Nr� Authkey must be bytes, not {0!s}�md5�zdigest received was wrong)�hmacr�rSr&�formatr/r"�urandom�MESSAGE_LENGTHr[�	CHALLENGE�new�digestrc�WELCOME�FAILUREr�Z
connectionr�r��messagerZresponserrrr��s
�


r�cCs�ddl}t|t�std�t|����|�d�}|dtt��tks'Jd|��|tt�d�}|�	||d��
�}|�|�|�d�}|tkrJt
d��dS)Nrr�r�zmessage = %rr�zdigest sent was rejected)r�r�rSr&r�r/rcrTrrrr[rrrrrrr��s
�
 

�r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ConnectionWrappercCs6||_||_||_dD]
}t||�}t|||�qdS)N)rPrJrorcr[)�_conn�_dumps�_loadsr��setattr)r;�connr]ri�attrr_rrrr?�s
�zConnectionWrapper.__init__cCs|�|�}|j�|�dSr)r
r	r[)r;r_r�rrrr`s
zConnectionWrapper.sendcCs|j��}|�|�Sr)r	rcrr�rrrrks

zConnectionWrapper.recvN)ryrzr{r?r`rkrrrrr�srcCst�|fdddd��d�S)Nr�utf-8)�	xmlrpclibr]�encode)r_rrr�
_xml_dumpssrcCst�|�d��\\}}|S)Nr)rri�decode)r�r_�methodrrr�
_xml_loadssrc@seZdZdd�ZdS)�XmlListenercCs"ddlmat�|�}t|tt�S�Nr)�
xmlrpc.client�clientrrr�rrrr^rrrr�s
zXmlListener.acceptN)ryrzr{r�rrrrrsrcOs"ddlmatt|i|��tt�Sr)rrrrrrr)r��kwdsrrr�	XmlClientsrcCs�t|�}g}|rZt�|d|�}|tkr	|St|kr$tt|�kr+nn|t8}nt|kr9tt|�krCntd��|t8}ntd��|�||�||dd�}d}|s|S)NFzShould not get hererr)	�listr�r�r
rrTrr�r�)Zhandlesr�L�readyr�rrr�_exhaustive_wait%s$
 �

��
rc
s�|durt}n|dkrd}nt|dd�}t|�}i�g}t��t�}z�|D]�}zt|d�}Wnty?|�|��<Yq'wzt�|�dd�\}}Wnt	yi}zd|j
}}|tvr_�WYd}~nd}~ww|tjkrz|�
|�|�|j<q'|r�t��dd�dkr�z	|�d	�\}	}Wnt	y�}z	|j
}WYd}~nd}~ww|s�t|d
�r�d|_��|�d}q't���|�}W|D]}|��q�|D]D}z	|�d�\}	}Wnt	y�}z|j
}|tvr�WYd}~nd}~ww|tjk�r�|j}��|�|dk�rt|d
��rd|_q�nU|D]}|���q|D]G}z	|�d�\}	}Wnt	�yC}z|j
}|tv�r9�WYd}~nd}~ww|tjk�rb�|j}��|�|dk�rbt|d
��rbd|_�qw���fdd�|D���fd
d�|D�S)��
        Wait till an object in object_list is ready/readable.

        Returns list of those objects in object_list which are ready/readable.
        Nrr�g�?rPT�)�r!Fr�c3s�|]}�|VqdSrr)�.0r�)�waithandle_to_objrr�	<genexpr>�s�zwait.<locals>.<genexpr>csg|]}|�vr|�qSrr)r#�o)�
ready_objectsrr�
<listcomp>�s�wait.<locals>.<listcomp>)r�intr�setr��AttributeErrorr7r�r�rDr��
_ready_errorsr�r�r�r*Zgetwindowsversionr�r,r��addr�keysr�ZERROR_OPERATION_ABORTED�update)
�object_listrZov_listZ
ready_handlesr&rPr�r�r�r�r)r'r$rr;s�����

��

���


���
���


��r�PollSelectorcCs�t��E}|D]	}|�|tj�q|durt��|}	|�|�}|r0dd�|D�Wd�S|durG|t��}|dkrG|Wd�Sq1sKwYdS)r NTcSsg|]\}}|j�qSr)Zfileobj)r#�keyZeventsrrrr(�sr)r)�
_WaitSelector�register�	selectorsZ
EVENT_READrrZselect)r1rZselectorr_Zdeadlinerrrrr�s"
���cCsf|��}t�|tjtj��}ddlm}|�|�}t||j	|j
ffWd�S1s,wYdS)Nr)�resource_sharer)rPr-ZfromfdrZSOCK_STREAMr r7Z	DupSocket�rebuild_connectionr=r>)r
r<r�r7�dsrrr�reduce_connection�s
$�r:cCs|��}t|��||�Sr�r�r�)r9r=r>Zsockrrrr8�sr8cCsB|jrtjnd|jr
tjndB}t�|��|�}t||j|jffSr)	r=r�ZFILE_GENERIC_READr>ZFILE_GENERIC_WRITEr
Z	DupHandlerP�rebuild_pipe_connection)r
r��dhrrr�reduce_pipe_connection�s
�r>cC�|��}t|||�Sr)r�r})r=r=r>r<rrrr<��r<cCs t�|���}t||j|jffSr)r
ZDupFdrPr8r=r>)r
�dfrrrr:�scCr?rr;)rAr=r>�fdrrrr8�r@)NN)Tr)I�__all__r�r"r*r-r�rr!�	itertoolsr�r rrr	�contextr
ZForkingPicklerr\r�rrr
r�ImportErrorr+r�ZCONNECTION_TIMEOUT�countr%r�Zfamiliesr,rrr)r.r5r6r}r��objectrrrr�r�r�r�rrrrr�r�rrrrrrr�ZERROR_NETNAME_DELETEDr-rr6r2r4ZSelectSelectorr:r8r5r>r<rrrr�<module>s�	
�	



PT
=

,,
8	P


?>