Mini Shell

Direktori : /lib64/python3.9/multiprocessing/__pycache__/
Upload File :
Current File : //lib64/python3.9/multiprocessing/__pycache__/connection.cpython-39.pyc

a

X�Zgp|�@sgd�ZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZm
Z
ddlmZejZz$ddlZddlmZmZmZmZWn"ey�ejdkr��dZYn0d	Zd
ZdZe��ZdZdgZe ed
�r�d
Zed
g7Zejdk�rdZedg7Zefdd�Z!dd�Z"dd�Z#dd�Z$dd�Z%Gdd�d�Z&e�rfGdd�de&�Z'Gdd�de&�Z(Gdd �d e)�Z*dQd!d"�Z+ejdk�r�dRd$d%�Z,n
dSd&d%�Z,Gd'd(�d(e)�Z-d)d*�Z.ejdk�r�Gd+d,�d,e)�Z/d-d.�Z0d/Z1d0Z2d1Z3d2Z4d3d4�Z5d5d6�Z6Gd7d8�d8e)�Z7d9d:�Z8d;d<�Z9Gd=d>�d>e*�Z:d?d@�Z;ejdk�rrdAdB�Z<ej=ej>hZ?dTdCdD�Z@n,ddlAZAe eAdE��r�eAjBZCneAjDZCdUdFdD�Z@ejdk�r�dGdH�ZEdIdJ�ZFe�Ge(eE�dKdL�ZHdMdN�ZIe�Ge'eH�ndOdH�ZEdPdJ�ZFe�Ge(eE�dS)V)�Client�Listener�Pipe�wait�N�)�util)�AuthenticationError�BufferTooShort)�	reduction)�
WAIT_OBJECT_0�WAIT_ABANDONED_0�WAIT_TIMEOUT�INFINITE�win32i g4@�sha256�AF_INET�AF_UNIX�AF_PIPEcCst��|S�N��time�	monotonic)�timeout�r�2/usr/lib64/python3.9/multiprocessing/connection.py�
_init_timeout?srcCst��|kSrr)�trrr�_check_timeoutBsrcCsX|dkrdS|dkr&tjdt��d�S|dkrLtjdt��tt�fdd�Std	��d
S)z?
    Return an arbitrary free address for the given family
    r)�	localhostrrz	listener-)�prefix�dirrz\\.\pipe\pyc-%d-%d-�zunrecognized familyN)	�tempfile�mktempr�get_temp_dir�os�getpid�next�
_mmap_counter�
ValueError��familyrrr�arbitrary_addressIs��r,cCsJtjdkr|dkrtd|��tjdkrF|dkrFtt|�sFtd|��dS)zD
    Checks if the family is valid for the current environment.
    rrzFamily %s is not recognized.rN)�sys�platformr)�hasattr�socketr*rrr�_validate_familyWs

r1cCsTt|�tkrdSt|�tur*|�d�r*dSt|�tus@t�|�rDdStd|��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�is_abstract_socket_namespacer))�addressrrr�address_typecsr8c@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>|��}|dkrtd��|s(|s(td��||_||_||_dS)Nrzinvalid handlez6at least one of `readable` and `writable` must be True)�	__index__r)�_handle�	_readable�	_writable)�self�handle�readable�writablerrr�__init__ys�z_ConnectionBase.__init__cCs|jdur|��dSr�r;�_close�r>rrr�__del__�s
z_ConnectionBase.__del__cCs|jdurtd��dS)Nzhandle is closed)r;�OSErrorrErrr�
_check_closed�s
z_ConnectionBase._check_closedcCs|jstd��dS)Nzconnection is write-only)r<rGrErrr�_check_readable�sz_ConnectionBase._check_readablecCs|jstd��dS)Nzconnection is read-only)r=rGrErrr�_check_writable�sz_ConnectionBase._check_writablecCs"|jrd|_n|��td��dS)NFzbad message length)r=r<�closerGrErrr�_bad_message_length�sz#_ConnectionBase._bad_message_lengthcCs
|jduS)z True if the connection is closedN�r;rErrr�closed�sz_ConnectionBase.closedcCs|jS)z"True if the connection is readable)r<rErrrr@�sz_ConnectionBase.readablecCs|jS)z"True if the connection is writable)r=rErrrrA�sz_ConnectionBase.writablecCs|��|jS)z+File descriptor or handle of the connection)rHr;rErrr�fileno�sz_ConnectionBase.filenocCs*|jdur&z|��Wd|_nd|_0dS)zClose the connectionNrCrErrrrK�s

z_ConnectionBase.closercCs�|��|��t|�}|jdkr.tt|��}t|�}|dkrFtd��||krVtd��|durh||}n&|dkrztd��n|||kr�td��|�||||��dS)z,Send the bytes data from a bytes-like objectrrzoffset is negativezbuffer length < offsetNzsize is negativezbuffer length < offset + size)rHrJ�
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)rHrJrT�_ForkingPickler�dumps�r>�objrrr�send�sz_ConnectionBase.sendcCsJ|��|��|dur(|dkr(td��|�|�}|durB|��|��S)z7
        Receive bytes data as a bytes object.
        Nrznegative maxlength)rHrIr)�_recv_bytesrL�getvalue)r>�	maxlengthrUrrr�
recv_bytes�s
z_ConnectionBase.recv_bytescCs�|��|��t|���}|j}|t|�}|dkr>td��n||krNtd��|��}|��}|||krvt|�	���|�
d�|�||||||��|Wd�S1s�0YdS)zq
        Receive bytes data into a writeable bytes-like object.
        Return the number of bytes read.
        rznegative offsetzoffset too largeN)rHrIrPrQrSr)r`�tellr	ra�seek�readinto)r>rUrVrXrQ�bytesize�resultrWrrr�recv_bytes_into�s$



�z_ConnectionBase.recv_bytes_intocCs&|��|��|��}t�|���S)zReceive a (picklable) object)rHrIr`r[�loads�	getbuffer)r>rUrrr�recv�sz_ConnectionBase.recv�cCs|��|��|�|�S)z/Whether there is any input available to be read)rHrI�_poll�r>rrrr�pollsz_ConnectionBase.pollcCs|SrrrErrr�	__enter__sz_ConnectionBase.__enter__cCs|��dSr�rK�r>�exc_type�	exc_value�exc_tbrrr�__exit__
sz_ConnectionBase.__exit__)TT)rN)N)r)rm)�__name__�
__module__�__qualname__r;rBrFrHrIrJrL�propertyrNr@rArOrKrZr_rcrirlrprqrwrrrrr9vs.








r9c@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.
        FcCs||j�dSrrM)r>Z_CloseHandlerrrrDszPipeConnection._closec	Cs�tj|j|dd�\}}zVz,|tjkrBt�|jgdt�}|tksBJ�Wn|���Yn0W|�	d�\}}n|�	d�\}}0|dks�J�|t
|�ks�J�dS)NT��
overlappedFr)�_winapiZ	WriteFiler;�ERROR_IO_PENDING�WaitForMultipleObjects�eventrr�cancel�GetOverlappedResultrS)r>rU�ov�err�waitresZnwrittenrrrrTs

�
 zPipeConnection._send_bytesNc	
Cs�|jrd|_t��S|dur dnt|d�}�ztj|j|dd�\}}z�z,|tjkrpt�|j	gdt
�}|tkspJ�Wn|���Yn0W|�
d�\}}|dkr�t��}|�|���|WS|tjkr�|�||�WSnh|�
d�\}}|dk�rt��}|�|���|YWS|tjk�r>|�||�YWS0Wn<t�y~}z"|jtjk�rht�n�WYd}~n
d}~00td��dS)NF�Tr}rz.shouldn't get here; expected KeyboardInterrupt)�_got_empty_message�io�BytesIO�minr�ReadFiler;r�r�r�rrr�r��writerkZERROR_MORE_DATA�_get_more_datarG�winerror�ERROR_BROKEN_PIPE�EOFError�RuntimeError)	r>�maxsizeZbsizer�r�r�Znread�f�errrr`*sH
�


�

�
 zPipeConnection._recv_bytescCs.|jst�|j�ddkrdStt|g|��S)NrT)r�r�
PeekNamedPiper;�boolrrorrrrnJs
�zPipeConnection._pollcCs�|��}t��}|�|�t�|j�d}|dks6J�|durVt|�||krV|��tj	|j|dd�\}}|�
d�\}}|dks�J�||ks�J�|�|���|S)NrrTr})rkr�r�r�rr�r;rSrLr�r�)r>r�r�rUr��leftr�Zrbytesrrrr�Ps
zPipeConnection._get_more_data)N)rxryrz�__doc__r�r�CloseHandlerDrTr`rnr�rrrrr|s
 r|c@s|eZdZdZer,ejfdd�ZejZ	ej
Zne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).
    cCs||j�dSrrM�r>rDrrrrDgszConnection._closecCs||j�dSrrMr�rrrrDlscCs8t|�}||j|�}||8}|dkr&q4||d�}qdS�Nr)rSr;)r>rUr��	remainingrYrrr�_sendqszConnection._sendcCsbt��}|j}|}|dkr^|||�}t|�}|dkrJ||krBt�ntd��|�|�||8}q|S)Nrzgot end of file during message)r�r�r;rSr�rGr�)r>rW�readrUr?r��chunkrYrrr�_recvzs


zConnection._recvcCs�t|�}|dkrHt�dd�}t�d|�}|�|�|�|�|�|�n8t�d|�}|dkrr|�|�|�|�n|�||�dS)Ni����!i����!Qi@)rS�struct�packr�)r>rUrY�
pre_header�headerrrrrT�s


zConnection._send_bytesNcCs^|�d�}t�d|���\}|dkr@|�d�}t�d|���\}|durT||krTdS|�|�S)N�r�r��r�)r�r��unpackra)r>r�rUrWrrrr`�s

zConnection._recv_bytescCst|g|�}t|�Sr)rr�)r>r�rrrrrn�szConnection._poll)N)rxryrzr�r�_multiprocessingZclosesocketrDr_�_writerl�_readr%rKr�r�r�r�rTr`rnrrrrr�`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|�pt}|pt|�}t|�|dkr>t||�|_nt|||�|_|durft|t�sft	d��||_
dS)Nr�authkey should be a byte string)r8�default_familyr,r1�PipeListener�	_listener�SocketListener�
isinstancerR�	TypeError�_authkey)r>r7r+�backlog�authkeyrrrrB�s�zListener.__init__cCs>|jdurtd��|j��}|jr:t||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�rG�acceptr��deliver_challenge�answer_challenge)r>�crrrr��s

zListener.acceptcCs |j}|durd|_|��dS)zA
        Close the bound socket or named pipe of `self`.
        N)r�rK)r>�listenerrrrrK�szListener.closecCs|jjSr)r��_addressrErrrr7�szListener.addresscCs|jjSr)r��_last_acceptedrErrr�
last_accepted�szListener.last_acceptedcCs|SrrrErrrrq�szListener.__enter__cCs|��dSrrrrsrrrrw�szListener.__exit__)NNrN)rxryrzr�rBr�rKr{r7r�rqrwrrrrr�s
	

rcCsh|p
t|�}t|�|dkr&t|�}nt|�}|durHt|t�sHtd��|durdt||�t||�|S)z=
    Returns a connection to the address of a `Listener`
    rNr�)	r8r1�
PipeClient�SocketClientr�rRr�r�r�)r7r+r�r�rrrr�s


rTcCsj|r>t��\}}|�d�|�d�t|���}t|���}n$t��\}}t|dd�}t|dd�}||fS)�L
        Returns pair of connection objects at either end of a pipe
        TF�rA�r@)r0�
socketpair�setblockingr��detachr%�pipe)�duplex�s1�s2�c1�c2�fd1�fd2rrrrs

rc

Cs�td�}|r*tj}tjtjB}tt}}ntj}tj}dt}}t�||tjBtj	Btj
tjBtjBd||tj
tj�}t�||dtjtjtjtj�}t�|tjdd�tj|dd�}|�d�\}	}
|
dks�J�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�r7Zopenmode�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|��|_zRtjdkr2|j�tjtjd�|j�d�|j�	|�|j�
|�|j��|_Wnt
y�|j���Yn0||_d|_|dkr�t�|�s�tj|tj|fdd�|_nd|_dS)N�posixrTrr��args�exitpriority)r0�getattr�_socketr%�name�
setsockopt�
SOL_SOCKET�SO_REUSEADDRr��bind�listen�getsocknamer�rGrK�_familyr�rr6�Finalize�unlink�_unlink)r>r7r+r�rrrrBKs(

�
�
zSocketListener.__init__cCs&|j��\}|_|�d�t|���S)NT)r�r�r�r�r�r��r>�srrrr�ds
zSocketListener.acceptcCsJz(|j��W|j}|durFd|_|�n|j}|durDd|_|�0dSr)r�rKr�)r>r�rrrrKis�zSocketListener.closeN)r)rxryrzr�rBr�rKrrrrr�Gs
r�cCs\t|�}t�tt|���0}|�d�|�|�t|���Wd�S1sN0YdS)zO
    Return a connection object connected to the socket given by `address`
    TN)r8r0r�r��connectr�r�)r7r+r�rrrr�ss


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_listenerrK)r>r7r�rrrrB�s�zPipeListener.__init__Fc
CsHtjtjB}|r|tjO}t�|j|tjtjBtjBtj	t
t
tjtj�Sr)
rr�r�r�r�r�r�r�r�ZPIPE_UNLIMITED_INSTANCESr�r�r�)r>r��flagsrrrr��s

��zPipeListener._new_handlec
Cs�|j�|���|j�d�}ztj|dd�}Wn2ty`}z|jtjkrL�WYd}~n~d}~00zVzt�	|j
gdt�}Wn |��t�
|��Yn0W|�d�\}}|dks�J�n|�d�\}}|dks�J�0t|�S)NrTr}F)r��appendr��poprr�rGr�Z
ERROR_NO_DATAr�r�rr�r�r�r|)r>r?r�r��resr�r�rrrr��s(
�

�zPipeListener.acceptcCs$t�d|�|D]}t�|�qdS)Nz closing listener with address=%r)rr�rr�)�queuer7r?rrrr��sz$PipeListener._finalize_pipe_listener)N)F)	rxryrzr�rBr�r��staticmethodr�rrrrr��s

r�c
Cs�t�}z6t�|d�t�|tjtjBdtjtjtjtj�}Wq�t	y|}z(|j
tjtjfvsft
|�rh�WYd}~qd}~00q�q�t�|tjdd�t|�S)zU
        Return a connection object connected to the pipe given by `address`
        ��rN)rrZ
WaitNamedPiper�r�r�r�r�r�rGr�ZERROR_SEM_TIMEOUTZERROR_PIPE_BUSYrr�r�r|)r7r�hr�rrrr��s*
���
�r��s#CHALLENGE#s	#WELCOME#s	#FAILURE#cCs�ddl}t|t�s$td�t|����t�t�}|�	t
|�|�||t��
�}|�d�}||krl|�	t�n|�	t�td��dS)Nr� Authkey must be bytes, not {0!s}�zdigest received was wrong)�hmacr�rRr)�formatr2r%�urandom�MESSAGE_LENGTHrZ�	CHALLENGE�new�HMAC_DIGEST_NAME�digestrc�WELCOME�FAILUREr��
connectionr�r
�messager�responserrrr��s
�


r�cCs�ddl}t|t�s$td�t|����|�d�}|dtt��tksNJd|��|tt�d�}|�	||t
���}|�|�|�d�}|t
kr�td��dS)Nrrr	zmessage = %rzdigest sent was rejected)r
r�rRr)rr2rcrSrrrrrZrrrrrrr��s
�
 

r�c@s$eZdZdd�Zdd�Zdd�ZdS)�ConnectionWrappercCs6||_||_||_dD]}t||�}t|||�qdS)N)rOrKrprcrZ)�_conn�_dumps�_loadsr��setattr)r>�connr\rj�attrr^rrrrBs
zConnectionWrapper.__init__cCs|�|�}|j�|�dSr)rrrZ)r>r^r�rrrr_	s
zConnectionWrapper.sendcCs|j��}|�|�Sr)rrcrr�rrrrls
zConnectionWrapper.recvN)rxryrzrBr_rlrrrrrsrcCst�|fdddd��d�S)Nr�utf-8)�	xmlrpclibr\�encode)r^rrr�
_xml_dumpssr"cCst�|�d��\\}}|S)Nr)r rj�decode)r�r^�methodrrr�
_xml_loadssr%c@seZdZdd�ZdS)�XmlListenercCs"ddlmat�|�}t|tt�Sr�)�
xmlrpc.client�clientr rr�rr"r%r]rrrr�s
zXmlListener.acceptN)rxryrzr�rrrrr&sr&cOs"ddlmatt|i|��tt�Sr�)r'r(r rrr"r%)r��kwdsrrr�	XmlClientsr*cCs�t|�}g}|r�t�|d|�}|tkr*q�n\t|krFtt|�krTnn
|t8}n2t|krptt|�kr~nn
|t8}ntd��|�||�||dd�}d}q|S)NFzShould not get hererr)	�listrr�r
rrSrr�r)Zhandlesr�L�readyrrrr�_exhaustive_wait)s 
 
r.c
s
|durt}n|dkrd}nt|dd�}t|�}i�g}t��t�}�z�|D�](}zt|d�}Wnty�|�|��<YqP0zt�|�dd�\}}Wn:t	y�}z"d|j
}}|tvr‚WYd}~n
d}~00|tjkr�|�
|�|�|j<qP|�rlt��dd�dk�rlz|�d	�\}	}Wn,t	�yR}z|j
}WYd}~n
d}~00|�slt|d
��rld|_��|�d}qPt���|�}W|D]}|���q�|D]�}z|�d�\}	}Wn8t	�y�}z|j
}|tv�rނWYd}~n
d}~00|tjk�r��|j}��|�|dk�r�t|d
��r�d|_�q�n�|D]}|���q:|D]�}z|�d�\}	}Wn8t	�y�}z|j
}|tv�r��WYd}~n
d}~00|tjk�rN�|j}��|�|dk�rNt|d
��rNd|_�qN0���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.
        Nrrg�?rOT�)�r0Fr�c3s|]}�|VqdSrr)�.0r)�waithandle_to_objrr�	<genexpr>��zwait.<locals>.<genexpr>csg|]}|�vr|�qSrr)r2�o)�
ready_objectsrr�
<listcomp>�r5�wait.<locals>.<listcomp>)r�intr+�setr��AttributeErrorr:rr�rGr��
_ready_errorsr�rr�r-Zgetwindowsversionr�r/r��addr.�keysr�ZERROR_OPERATION_ABORTED�update)
�object_listrZov_listZ
ready_handlesr6rOr�r�r�r�r)r7r3rr?s�







�



r�PollSelectorcCs�t���}|D]}|�|tj�q|dur4t��|}|�|�}|r^dd�|D�Wd�S|dur4|t��}|dkr4|Wd�Sq4Wd�n1s�0YdS)r/NcSsg|]\}}|j�qSr)�fileobj)r2�key�eventsrrrr8�r5r9r)�
_WaitSelector�register�	selectors�
EVENT_READrr�select)rAr�selectorr^�deadliner-rrrr�s
cCsf|��}t�|tjtj��8}ddlm}|�|�}t||j	|j
ffWd�S1sX0YdS)Nr)�resource_sharer)rOr0�fromfdr�SOCK_STREAMr!rMZ	DupSocket�rebuild_connectionr@rA)rr?r�rM�dsrrr�reduce_connection�s

rRcCs|��}t|��||�Sr�r�r�)rQr@rA�sockrrrrP�srPcCsB|jrtjnd|jrtjndB}t�|��|�}t||j|jffSr�)	r@rZFILE_GENERIC_READrAZFILE_GENERIC_WRITEr
Z	DupHandlerO�rebuild_pipe_connection)rr��dhrrr�reduce_pipe_connection�s
�rWcCs|��}t|||�Sr)r�r|)rVr@rAr?rrrrU�srUcCs t�|���}t||j|jffSr)r
�DupFdrOrPr@rA)r�dfrrrrR�scCs|��}t|||�SrrS)rYr@rA�fdrrrrP�s)NN)T)T)N)N)J�__all__r�r%r-r0r�rr"�	itertoolsr�r!rrr	�contextr
�ForkingPicklerr[rrrr
r�ImportErrorr.r��CONNECTION_TIMEOUTr�countr(r��familiesr/rrr,r1r8r9r|r��objectrrrr�r�r�r�r
rrrr�r�rr"r%r&r*r.r�ZERROR_NETNAME_DELETEDr=rrHrBrF�SelectSelectorrRrPrGrWrUrrrr�<module>
s�




PT=

,,8	P


Zerion Mini Shell 1.0