Your IP : 18.119.166.34


Current Path : /lib64/python3.8/asyncio/__pycache__/
Upload File :
Current File : //lib64/python3.8/asyncio/__pycache__/windows_events.cpython-38.pyc

U

e5di��@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZddl
m
Z
ddl
mZddl
mZdd	l
mZdd
l
mZddl
mZddlmZd
ZdZdZdZdZdZdZGdd�de
j�ZGdd�de
j�ZGdd�de�ZGdd�de�Z Gdd�de!�Z"Gdd�dej#�Z$Gdd �d ej%�Z&Gd!d"�d"�Z'Gd#d$�d$ej(�Z)e$Z*Gd%d&�d&ej+�Z,Gd'd(�d(ej+�Z-e-Z.dS))z.Selector and proactor event loops for Windows.�N�)�events)�base_subprocess)�futures)�
exceptions)�proactor_events)�selector_events)�tasks)�
windows_utils)�logger)�SelectorEventLoop�ProactorEventLoop�IocpProactor�DefaultEventLoopPolicy�WindowsSelectorEventLoopPolicy�WindowsProactorEventLoopPolicy���i�i�g����MbP?g�������?cs^eZdZdZdd��fdd�
Z�fdd�Zdd	�Z�fd
d�Z�fdd
�Z�fdd�Z	�Z
S)�_OverlappedFuturez�Subclass of Future which represents an overlapped operation.

    Cancelling it will immediately cancel the overlapped operation.
    N��loopcs&t�j|d�|jr|jd=||_dS�Nr���)�super�__init__�_source_traceback�_ov)�self�ovr��	__class__��./usr/lib64/python3.8/asyncio/windows_events.pyr1sz_OverlappedFuture.__init__csHt���}|jdk	rD|jjr dnd}|�dd|�d|jjd�d��|S)N�pendingZ	completedrzoverlapped=<z, �#x�>)r�
_repr_inforr"�insert�address�r�info�staterr r!r%7s


 z_OverlappedFuture._repr_infoc
Csr|jdkrdSz|j��WnJtk
rf}z,d||d�}|jrJ|j|d<|j�|�W5d}~XYnXd|_dS)Nz&Cancelling an overlapped future failed��message�	exception�future�source_traceback)r�cancel�OSErrorr�_loop�call_exception_handler)r�exc�contextr r r!�_cancel_overlapped>s
�
z$_OverlappedFuture._cancel_overlappedcs|��t���S�N)r6rr0�rrr r!r0Nsz_OverlappedFuture.cancelcst��|�|��dSr7)r�
set_exceptionr6�rr-rr r!r9Rsz_OverlappedFuture.set_exceptioncst��|�d|_dSr7)r�
set_resultr�r�resultrr r!r;Vsz_OverlappedFuture.set_result)�__name__�
__module__�__qualname__�__doc__rr%r6r0r9r;�
__classcell__r r rr!r+srcsneZdZdZdd��fdd�
Zdd�Z�fdd	�Zd
d�Zdd
�Z�fdd�Z	�fdd�Z
�fdd�Z�ZS)�_BaseWaitHandleFuturez2Subclass of Future which represents a wait handle.Nrcs8t�j|d�|jr|jd=||_||_||_d|_dS)NrrT)rrrr�_handle�_wait_handle�_registered)rr�handle�wait_handlerrr r!r^sz_BaseWaitHandleFuture.__init__cCst�|jd�tjkS�Nr)�_winapiZWaitForSingleObjectrDZ
WAIT_OBJECT_0r8r r r!�_pollls�z_BaseWaitHandleFuture._pollcsdt���}|�d|jd���|jdk	rB|��r4dnd}|�|�|jdk	r`|�d|jd���|S)Nzhandle=r#ZsignaledZwaitingzwait_handle=)rr%�appendrDrKrEr(rr r!r%qs



z _BaseWaitHandleFuture._repr_infocCs
d|_dSr7)r�r�futr r r!�_unregister_wait_cb{sz)_BaseWaitHandleFuture._unregister_wait_cbc
Cs�|js
dSd|_|j}d|_zt�|�Wn`tk
r�}zB|jtjkrzd||d�}|jrd|j|d<|j�	|�WY�dSW5d}~XYnX|�
d�dS�NFz$Failed to unregister the wait handler+r/)rFrE�_overlappedZUnregisterWaitr1�winerror�ERROR_IO_PENDINGrr2r3rO�rrHr4r5r r r!�_unregister_wait�s$�
z&_BaseWaitHandleFuture._unregister_waitcs|��t���Sr7)rUrr0r8rr r!r0�sz_BaseWaitHandleFuture.cancelcs|��t��|�dSr7)rUrr9r:rr r!r9�sz#_BaseWaitHandleFuture.set_exceptioncs|��t��|�dSr7)rUrr;r<rr r!r;�sz _BaseWaitHandleFuture.set_result)
r>r?r@rArrKr%rOrUr0r9r;rBr r rr!rC[s
rCcsFeZdZdZdd��fdd�
Zdd�Z�fdd	�Z�fd
d�Z�ZS)�_WaitCancelFuturezoSubclass of Future which represents a wait for the cancellation of a
    _WaitHandleFuture using an event.
    Nrcst�j||||d�d|_dS)Nr)rr�_done_callback)rr�eventrHrrr r!r�sz_WaitCancelFuture.__init__cCstd��dS)Nz'_WaitCancelFuture must not be cancelled)�RuntimeErrorr8r r r!r0�sz_WaitCancelFuture.cancelcs$t��|�|jdk	r |�|�dSr7)rr;rWr<rr r!r;�s
z_WaitCancelFuture.set_resultcs$t��|�|jdk	r |�|�dSr7)rr9rWr:rr r!r9�s
z_WaitCancelFuture.set_exception)	r>r?r@rArr0r;r9rBr r rr!rV�s
rVcs6eZdZdd��fdd�
Z�fdd�Zdd�Z�ZS)	�_WaitHandleFutureNrcs<t�j||||d�||_d|_t�dddd�|_d|_dS)NrTF)rr�	_proactorZ_unregister_proactorrQZCreateEvent�_event�
_event_fut)rrrGrH�proactorrrr r!r�s
z_WaitHandleFuture.__init__csF|jdk	r"t�|j�d|_d|_|j�|j�d|_t��|�dSr7)	r\rJ�CloseHandler]r[�_unregisterrrrOrMrr r!rO�s
	z%_WaitHandleFuture._unregister_wait_cbc
Cs�|js
dSd|_|j}d|_zt�||j�Wn`tk
r�}zB|jtjkr~d||d�}|jrh|j|d<|j	�
|�WY�dSW5d}~XYnX|j�|j|j
�|_dSrP)rFrErQZUnregisterWaitExr\r1rRrSrr2r3r[�_wait_cancelrOr]rTr r r!rU�s(�

�z"_WaitHandleFuture._unregister_wait)r>r?r@rrOrUrBr r rr!rZ�srZc@s<eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZeZ	dS)
�
PipeServerzXClass representing a pipe server.

    This is much like a bound, listening socket.
    cCs,||_t��|_d|_d|_|�d�|_dS�NT)�_address�weakref�WeakSet�_free_instances�_pipe�_accept_pipe_future�_server_pipe_handle)rr'r r r!r�s

zPipeServer.__init__cCs|j|�d�}|_|S)NF)rhrj)r�tmpr r r!�_get_unconnected_pipesz PipeServer._get_unconnected_pipec
Csr|��rdStjtjB}|r&|tjO}t�|j|tjtjBtj	Btj
tjtjtj
tj�}t�|�}|j�|�|Sr7)�closedrJZPIPE_ACCESS_DUPLEXZFILE_FLAG_OVERLAPPEDZFILE_FLAG_FIRST_PIPE_INSTANCEZCreateNamedPiperdZPIPE_TYPE_MESSAGEZPIPE_READMODE_MESSAGEZ	PIPE_WAITZPIPE_UNLIMITED_INSTANCESr
ZBUFSIZEZNMPWAIT_WAIT_FOREVER�NULL�
PipeHandlerg�add)r�first�flags�h�piper r r!rjs(

��
zPipeServer._server_pipe_handlecCs
|jdkSr7)rdr8r r r!rmszPipeServer.closedcCsR|jdk	r|j��d|_|jdk	rN|jD]}|��q*d|_d|_|j��dSr7)rir0rdrg�closerh�clear)rrtr r r!rus




zPipeServer.closeN)
r>r?r@rArrlrjrmru�__del__r r r r!rb�s
rbc@seZdZdZdS)�_WindowsSelectorEventLoopz'Windows version of selector event loop.N)r>r?r@rAr r r r!rx,srxcsHeZdZdZd
�fdd�	Z�fdd�Zdd�Zd	d
�Zddd�Z�Z	S)r
z2Windows version of proactor event loop using IOCP.Ncs|dkrt�}t��|�dSr7)rrr)rr^rr r!r3szProactorEventLoop.__init__c	sfz(|jdkst�|�|j�t��	�W5|jdk	r`|jj}|j��|dk	rZ|j�|�d|_XdSr7)
Z_self_reading_futurerr0r[r`�AssertionError�	call_soonZ_loop_self_readingr�run_forever�rrrr r!r{8s

zProactorEventLoop.run_foreverc�s8|j�|�}|IdH}|�}|j||d|id�}||fS)N�addr��extra)r[�connect_pipe�_make_duplex_pipe_transport)r�protocol_factoryr'�frt�protocol�transr r r!�create_pipe_connectionKs
�z(ProactorEventLoop.create_pipe_connectionc�s.t���d�����fdd�	������gS)Nc
sd}zn|rN|��}�j�|����r4|��WdS��}�j||d�id����}|dkrdWdS�j�|�}Wn�t	k
r�}zF|r�|�
�dkr���d||d��|��n�jr�t
jd|dd�W5d}~XYn2tjk
r�|r�|��YnX|�_|���dS)	Nr}r~rzPipe accept failed)r,r-rtzAccept pipe failed on pipe %rT)�exc_info)r=rg�discardrmrur�rlr[�accept_piper1�filenor3Z_debugrZwarningr�CancelledErrorri�add_done_callback)r�rtr�r4�r'�loop_accept_piper�rZserverr r!r�VsH��
�z>ProactorEventLoop.start_serving_pipe.<locals>.loop_accept_pipe)N)rbrz)rr�r'r r�r!�start_serving_pipeSs(
z$ProactorEventLoop.start_serving_pipec		�s�|��}
t||||||||f|
|d�|	��}z|
IdHWnDttfk
rT�Yn,tk
r~|��|��IdH�YnX|S)N)�waiterr)�
create_future�_WindowsSubprocessTransport�
SystemExit�KeyboardInterrupt�
BaseExceptionruZ_wait)rr��args�shell�stdin�stdout�stderr�bufsizer�kwargsr�Ztranspr r r!�_make_subprocess_transport�s*
���z,ProactorEventLoop._make_subprocess_transport)N)N)
r>r?r@rArr{r�r�r�rBr r rr!r
0s0�r
c@s�eZdZdZd;dd�Zdd�Zdd�Zd	d
�Zd<dd
�Zdd�Z	d=dd�Z
d>dd�Zd?dd�Zd@dd�Z
dAdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZdBd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�ZdCd3d4�Zd5d6�Zd7d8�Zd9d:�ZdS)Drz#Proactor implementation using IOCP.rcCsDd|_g|_t�tjtd|�|_i|_t�	�|_
g|_t�	�|_dSrI)
r2�_resultsrQ�CreateIoCompletionPort�INVALID_HANDLE_VALUErn�_iocp�_cachererfrF�
_unregistered�_stopped_serving)rZconcurrencyr r r!r�s�
zIocpProactor.__init__cCs|jdkrtd��dS)NzIocpProactor is closed)r�rYr8r r r!�
_check_closed�s
zIocpProactor._check_closedcCsFdt|j�dt|j�g}|jdkr0|�d�d|jjd�|�fS)Nzoverlapped#=%sz
result#=%srmz<%s %s>� )�lenr�r�r�rLrr>�join)rr)r r r!�__repr__�s�

zIocpProactor.__repr__cCs
||_dSr7)r2)rrr r r!�set_loop�szIocpProactor.set_loopNcCs |js|�|�|j}g|_|Sr7)r�rK)r�timeoutrkr r r!�select�s

zIocpProactor.selectcCs|j��}|�|�|Sr7)r2r�r;)r�valuerNr r r!�_result�s

zIocpProactor._resultrcCs~|�|�t�t�}z4t|tj�r6|�|��||�n|�|��|�Wnt	k
rf|�
d�YSXdd�}|�|||�S)N�c
SsRz
|��WStk
rL}z$|jtjtjfkr:t|j��n�W5d}~XYnXdSr7��	getresultr1rRrQZERROR_NETNAME_DELETEDZERROR_OPERATION_ABORTED�ConnectionResetErrorr��r��keyrr4r r r!�finish_recv�s
�z&IocpProactor.recv.<locals>.finish_recv)�_register_with_iocprQ�
Overlappedrn�
isinstance�socketZWSARecvr�ZReadFile�BrokenPipeErrorr��	_register�r�conn�nbytesrrrr�r r r!�recv�s


zIocpProactor.recvcCs~|�|�t�t�}z4t|tj�r6|�|��||�n|�|��|�Wnt	k
rf|�
d�YSXdd�}|�|||�S)Nrc
SsRz
|��WStk
rL}z$|jtjtjfkr:t|j��n�W5d}~XYnXdSr7r�r�r r r!r��s
�z+IocpProactor.recv_into.<locals>.finish_recv)r�rQr�rnr�r�ZWSARecvIntor�ZReadFileIntor�r�r�)rr��bufrrrr�r r r!�	recv_into�s


zIocpProactor.recv_intocCs`|�|�t�t�}z|�|��||�Wntk
rH|�d�YSXdd�}|�|||�S)N)r�Nc
SsRz
|��WStk
rL}z$|jtjtjfkr:t|j��n�W5d}~XYnXdSr7r�r�r r r!r��s
�z*IocpProactor.recvfrom.<locals>.finish_recv)	r�rQr�rnZWSARecvFromr�r�r�r�r�r r r!�recvfrom�s


zIocpProactor.recvfromcCs>|�|�t�t�}|�|��|||�dd�}|�|||�S)Nc
SsRz
|��WStk
rL}z$|jtjtjfkr:t|j��n�W5d}~XYnXdSr7r�r�r r r!�finish_sends
�z(IocpProactor.sendto.<locals>.finish_send)r�rQr�rnZ	WSASendTor�r�)rr�r�rrr}rr�r r r!�sendto�s



zIocpProactor.sendtocCsZ|�|�t�t�}t|tj�r4|�|��||�n|�|��|�dd�}|�	|||�S)Nc
SsRz
|��WStk
rL}z$|jtjtjfkr:t|j��n�W5d}~XYnXdSr7r�r�r r r!r�s
�z&IocpProactor.send.<locals>.finish_send)
r�rQr�rnr�r�ZWSASendr�Z	WriteFiler�)rr�r�rrrr�r r r!�sends


zIocpProactor.sendcsv|���|��j��t�t�}|����������fdd�}dd�}|�|�|�}||��}t	j
||jd�|S)NcsD|��t�d����}��tjtj|���	��
������fS)Nz@P)r��structZpackr��
setsockoptr��
SOL_SOCKETrQZSO_UPDATE_ACCEPT_CONTEXT�
settimeoutZ
gettimeoutZgetpeername)r�r�rr��r��listenerr r!�
finish_accept*s�z*IocpProactor.accept.<locals>.finish_acceptc�s4z|IdHWn tjk
r.|���YnXdSr7)rr�ru)r.r�r r r!�accept_coro3s
z(IocpProactor.accept.<locals>.accept_coror)r��_get_accept_socket�familyrQr�rnZAcceptExr�r�r	Z
ensure_futurer2)rr�rr�r�r.�coror r�r!�accept$s

	
zIocpProactor.acceptc
s��jtjkr4t����|�|j��}|�d�|S|�	��zt�
����j�WnBtk
r�}z$|j
tjkrt����ddkr��W5d}~XYnXt�t�}|����|��fdd�}|�|�|�S)Nrrcs|����tjtjd��SrI)r�r�r�r�rQZSO_UPDATE_CONNECT_CONTEXT�r�r�r�r�r r!�finish_connectVs�z,IocpProactor.connect.<locals>.finish_connect)�typer�Z
SOCK_DGRAMrQZ
WSAConnectr�r2r�r;r�Z	BindLocalr�r1rR�errnoZ	WSAEINVALZgetsocknamer�rnZ	ConnectExr�)rr�r'rN�err�r r�r!�connect@s"



zIocpProactor.connectc		Csb|�|�t�t�}|d@}|d?d@}|�|��t�|���|||dd�dd�}|�|||�S)Nr� rc
SsRz
|��WStk
rL}z$|jtjtjfkr:t|j��n�W5d}~XYnXdSr7r�r�r r r!�finish_sendfileis
�z.IocpProactor.sendfile.<locals>.finish_sendfile)	r�rQr�rnZTransmitFiler��msvcrtZ
get_osfhandler�)	rZsock�file�offset�countrZ
offset_lowZoffset_highr�r r r!�sendfile_s


�	zIocpProactor.sendfilecsJ|���t�t�}|�����}|r0|���S�fdd�}|�|�|�S)Ncs|���Sr7)r�r��rtr r!�finish_accept_pipesz4IocpProactor.accept_pipe.<locals>.finish_accept_pipe)r�rQr�rnZConnectNamedPiper�r�r�)rrtrZ	connectedr�r r�r!r�ts


zIocpProactor.accept_pipec
�srt}zt�|�}WqhWn0tk
rF}z|jtjkr6�W5d}~XYnXt|dt�}t�	|�IdHqt
�|�S)N�)�CONNECT_PIPE_INIT_DELAYrQZConnectPiper1rRZERROR_PIPE_BUSY�min�CONNECT_PIPE_MAX_DELAYr	�sleepr
ro)rr'ZdelayrGr4r r r!r��s
zIocpProactor.connect_pipecCs|�||d�S)z�Wait for a handle.

        Return a Future object. The result of the future is True if the wait
        completed, or False if the wait did not complete (on timeout).
        F)�_wait_for_handle)rrGr�r r r!�wait_for_handle�szIocpProactor.wait_for_handlecCs|�|dd�}||_|Src)r�rW)rrXZ
done_callbackrNr r r!ra�szIocpProactor._wait_cancelcs�|��|dkrtj}nt�|d�}t�t�}t�||j	|j
|�}|r\t||||jd��nt
|||||jd���jr~�jd=�fdd�}�|d|f|j|j
<�S)N�@�@rrcs���Sr7)rKr��r�r r!�finish_wait_for_handle�sz=IocpProactor._wait_for_handle.<locals>.finish_wait_for_handler)r�rJ�INFINITE�math�ceilrQr�rnZRegisterWaitWithQueuer�r'rVr2rZrr�)rrGr�Z
_is_cancel�msrrHr�r r�r!r��s*
�
�	zIocpProactor._wait_for_handlecCs0||jkr,|j�|�t�|��|jdd�dSrI)rFrprQr�r�r��r�objr r r!r��s
z IocpProactor._register_with_iocpc
Cs�|��t||jd�}|jr$|jd=|jsrz|dd|�}Wn,tk
rf}z|�|�W5d}~XYnX|�|�||||f|j|j	<|Sr)
r�rr2rr"r1r9r;r�r')rrr��callbackr�r�r�r r r!r��s

zIocpProactor._registercCs|��|j�|�dS)a
Unregister an overlapped object.

        Call this method when its future has been cancelled. The event can
        already be signalled (pending in the proactor event queue). It is also
        safe if the event is never signalled (because it was cancelled).
        N)r�r�rLr|r r r!r`�szIocpProactor._unregistercCst�|�}|�d�|SrI)r�r�)rr��sr r r!r��s

zIocpProactor._get_accept_socketcCs�|dkrt}n0|dkr td��nt�|d�}|tkr>td��t�|j|�}|dkrX�qZd}|\}}}}z|j�|�\}}	}
}WnXt	k
r�|j
��r�|j
�dd||||fd��|dtj
fkr�t�|�Yq>YnX|
|jkr�|��q>|��s>z||||	�}Wn:tk
�r@}
z|�|
�|j�|�W5d}
~
XYq>X|�|�|j�|�q>|jD]}	|j�|	jd��q`|j��dS)Nrznegative timeoutr�ztimeout too bigz8GetQueuedCompletionStatus() returned an unexpected eventz)err=%s transferred=%s key=%#x address=%#x)r,�status)r��
ValueErrorr�r�rQZGetQueuedCompletionStatusr�r��pop�KeyErrorr2Z	get_debugr3r�rJr_r�r0Zdoner1r9r�rLr;r�r'rv)rr�r�r��errZtransferredr�r'r�rr�r�r�r�r r r!rKsL


��	






zIocpProactor._pollcCs|j�|�dSr7)r�rpr�r r r!�
_stop_serving9szIocpProactor._stop_servingcCs|jdkrdSt|j���D]�\}\}}}}|��r6qt|t�rBqz|��Wqtk
r�}z6|j	dk	r�d||d�}|j
r�|j
|d<|j	�|�W5d}~XYqXqd}t�
�}	|	|}
|jr�|
t�
�kr�t�d|t�
�|	�t�
�|}
|�|�q�g|_t�|j�d|_dS)NzCancelling a future failedr+r/g�?z,%r is running after closing for %.1f seconds)r��listr��itemsZ	cancelledr�rVr0r1r2rr3�time�	monotonicr�debugrKr�rJr_)rr'rNrr�r�r4r5Z
msg_updateZ
start_timeZnext_msgr r r!ru?s@


�
 
�zIocpProactor.closecCs|��dSr7)rur8r r r!rwnszIocpProactor.__del__)r)N)r)r)r)rN)r)N)N)r>r?r@rArr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rar�r�r�r`r�rKr�rurwr r r r!r�s8








"
 

7/rc@seZdZdd�ZdS)r�c
sPtj|f|||||d�|���_�fdd�}�jj�t�jj��}	|	�|�dS)N)r�r�r�r�r�cs�j��}��|�dSr7)�_procZpollZ_process_exited)r��
returncoder8r r!r�ys
z4_WindowsSubprocessTransport._start.<locals>.callback)	r
�Popenr�r2r[r��intrDr�)
rr�r�r�r�r�r�r�r�r�r r8r!�_startts���z"_WindowsSubprocessTransport._startN)r>r?r@rr r r r!r�rsr�c@seZdZeZdS)rN)r>r?r@r�
_loop_factoryr r r r!r�src@seZdZeZdS)rN)r>r?r@r
rr r r r!r�sr)/rArQrJr�r�r�r�r�r�re�rrrrrrr	r
�logr�__all__rnr�ZERROR_CONNECTION_REFUSEDZERROR_CONNECTION_ABORTEDr�r�ZFuturerrCrVrZ�objectrbZBaseSelectorEventLooprxZBaseProactorEventLoopr
rZBaseSubprocessTransportr�rZBaseDefaultEventLoopPolicyrrrr r r r!�<module>sR0J4;e`

?>