Your IP : 18.224.51.49


Current Path : /opt/alt/python39/lib64/python3.9/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python39/lib64/python3.9/asyncio/__pycache__/windows_events.cpython-39.pyc

a

R�f��@s�dZddlZejdkred��ddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlZddlZddl
mZddl
mZddl
mZdd	l
mZdd
l
mZddl
mZddl
mZdd
l
mZddlmZdZdZdZdZdZdZdZGdd�dej�Z Gdd�dej�Z!Gdd�de!�Z"Gdd�de!�Z#Gdd�de$�Z%Gdd �d ej&�Z'Gd!d"�d"ej(�Z)Gd#d$�d$�Z*Gd%d&�d&ej+�Z,e'Z-Gd'd(�d(ej.�Z/Gd)d*�d*ej.�Z0e0Z1dS)+z.Selector and proactor event loops for Windows.�NZwin32z
win32 only�)�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	�Zd�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__��;/opt/alt/python39/lib64/python3.9/asyncio/windows_events.pyr6sz_OverlappedFuture.__init__csHt���}|jdurD|jjr dnd}|�dd|�d|jjd�d��|S)N�pendingZ	completedrzoverlapped=<z, �#x�>)r�
_repr_inforr"�insert�address�r�info�staterr r!r%<s


 z_OverlappedFuture._repr_infoc
Cst|jdurdSz|j��WnLtyh}z4d||d�}|jrH|j|d<|j�|�WYd}~n
d}~00d|_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_overlappedCs
�
"z$_OverlappedFuture._cancel_overlappedcs|��t�j|d�S�N)�msg)r6rr0�rr8rr r!r0Ssz_OverlappedFuture.cancelcst��|�|��dS�N)r�
set_exceptionr6�rr-rr r!r;Wsz_OverlappedFuture.set_exceptioncst��|�d|_dSr:)r�
set_resultr�r�resultrr r!r=[sz_OverlappedFuture.set_result)N)�__name__�
__module__�__qualname__�__doc__rr%r6r0r;r=�
__classcell__r r rr!r0srcspeZdZdZdd��fdd�
Zdd�Z�fdd	�Zd
d�Zdd
�Zd�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!rcsz_BaseWaitHandleFuture.__init__cCst�|jd�tjkS�Nr)�_winapiZWaitForSingleObjectrFZ
WAIT_OBJECT_0�rr r r!�_pollqs�z_BaseWaitHandleFuture._pollcsdt���}|�d|jd���|jdurB|��r4dnd}|�|�|jdur`|�d|jd���|S)Nzhandle=r#ZsignaledZwaitingzwait_handle=)rr%�appendrFrNrGr(rr r!r%vs



z _BaseWaitHandleFuture._repr_infocCs
d|_dSr:)r�r�futr r r!�_unregister_wait_cb�sz)_BaseWaitHandleFuture._unregister_wait_cbc
Cs�|js
dSd|_|j}d|_zt�|�Wnfty�}zN|jtjkr|d||d�}|jrb|j|d<|j�	|�WYd}~dSWYd}~n
d}~00|�
d�dS�NFz$Failed to unregister the wait handler+r/)rHrG�_overlappedZUnregisterWaitr1�winerror�ERROR_IO_PENDINGrr2r3rR�rrJr4r5r r r!�_unregister_wait�s$�
$z&_BaseWaitHandleFuture._unregister_waitcs|��t�j|d�Sr7)rXrr0r9rr r!r0�sz_BaseWaitHandleFuture.cancelcs|��t��|�dSr:)rXrr;r<rr r!r;�sz#_BaseWaitHandleFuture.set_exceptioncs|��t��|�dSr:)rXrr=r>rr r!r=�sz _BaseWaitHandleFuture.set_result)N)
r@rArBrCrrNr%rRrXr0r;r=rDr r rr!rE`s
rEcsFeZdZdZdd��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�eventrJrrr r!r�sz_WaitCancelFuture.__init__cCstd��dS)Nz'_WaitCancelFuture must not be cancelled)�RuntimeErrorrMr r r!r0�sz_WaitCancelFuture.cancelcs$t��|�|jdur |�|�dSr:)rr=rZr>rr r!r=�s
z_WaitCancelFuture.set_resultcs$t��|�|jdur |�|�dSr:)rr;rZr<rr r!r;�s
z_WaitCancelFuture.set_exception)	r@rArBrCrr0r=r;rDr r rr!rY�s
rYcs6eZdZdd��fdd�
Z�fdd�Zdd�Z�ZS)	�_WaitHandleFutureNrcs<t�j||||d�||_d|_t�dddd�|_d|_dS)NrTF)rr�	_proactorZ_unregister_proactorrTZCreateEvent�_event�
_event_fut)rrrIrJ�proactorrrr r!r�s
z_WaitHandleFuture.__init__csF|jdur"t�|j�d|_d|_|j�|j�d|_t��|�dSr:)	r_rL�CloseHandler`r^�_unregisterrrrRrPrr r!rR�s
	z%_WaitHandleFuture._unregister_wait_cbc
Cs�|js
dSd|_|j}d|_zt�||j�Wnfty�}zN|jtjkr�d||d�}|jrf|j|d<|j	�
|�WYd}~dSWYd}~n
d}~00|j�|j|j
�|_dSrS)rHrGrTZUnregisterWaitExr_r1rUrVrr2r3r^�_wait_cancelrRr`rWr r r!rX�s(�
$
�z"_WaitHandleFuture._unregister_wait)r@rArBrrRrXrDr r rr!r]�sr]c@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)rkrm)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�|�|Sr:)�closedrLZPIPE_ACCESS_DUPLEXZFILE_FLAG_OVERLAPPEDZFILE_FLAG_FIRST_PIPE_INSTANCEZCreateNamedPipergZPIPE_TYPE_MESSAGEZPIPE_READMODE_MESSAGEZ	PIPE_WAITZPIPE_UNLIMITED_INSTANCESr
ZBUFSIZEZNMPWAIT_WAIT_FOREVER�NULL�
PipeHandlerj�add)r�first�flags�h�piper r r!rm
s"

��
zPipeServer._server_pipe_handlecCs
|jduSr:)rgrMr r r!rpszPipeServer.closedcCsR|jdur|j��d|_|jdurN|jD]}|��q*d|_d|_|j��dSr:)rlr0rgrj�closerk�clear)rrwr r r!rx"s




zPipeServer.closeN)
r@rArBrCrrormrprx�__del__r r r r!re�s
rec@seZdZdZdS)�_WindowsSelectorEventLoopz'Windows version of selector event loop.N)r@rArBrCr r r r!r{1sr{csHeZdZdZd
�fdd�	Z�fdd�Zdd�Zd	d
�Zddd�Z�Z	S)r
z2Windows version of proactor event loop using IOCP.Ncs|durt�}t��|�dSr:)rrr)rrarr r!r8szProactorEventLoop.__init__c	s�zd|jdusJ�|�|j�t���W|jdur�|jj}|j��|dur^|js^|j�	|�d|_n>|jdur�|jj}|j��|dur�|js�|j�	|�d|_0dSr:)
Z_self_reading_future�	call_soonZ_loop_self_readingr�run_foreverrr0r"r^rc�rrrr r!r}=s 

�

zProactorEventLoop.run_foreverc�s8|j�|�}|IdH}|�}|j||d|id�}||fS)N�addr��extra)r^�connect_pipe�_make_duplex_pipe_transport)r�protocol_factoryr'�frw�protocol�transr r r!�create_pipe_connectionPs
�z(ProactorEventLoop.create_pipe_connectionc�s.t���d�����fdd�	������gS)Nc
sd}zn|rN|��}�j�|����r4|��WdS��}�j||d�id����}|durdWdS�j�|�}Wn�t	y�}zN|r�|�
�dkr���d||d��|��n�jr�t
jd|dd�WYd}~n8d}~0tjy�|r�|��Yn0|�_|���dS)	Nrr�rzPipe accept failed)r,r-rwzAccept pipe failed on pipe %rT)�exc_info)r?rj�discardrprxr�ror^�accept_piper1�filenor3Z_debugrZwarningr�CancelledErrorrl�add_done_callback)r�rwr�r4�r'�loop_accept_piper�rZserverr r!r�[sB
��
�z>ProactorEventLoop.start_serving_pipe.<locals>.loop_accept_pipe)N)rer|)rr�r'r r�r!�start_serving_pipeXs(
z$ProactorEventLoop.start_serving_pipec		�s�|��}
t||||||||f|
|d�|	��}z|
IdHWn@ttfyR�Yn*tyz|��|��IdH�Yn0|S)N)�waiterr�)�
create_future�_WindowsSubprocessTransport�
SystemExit�KeyboardInterrupt�
BaseExceptionrxZ_wait)rr��args�shell�stdin�stdout�stderr�bufsizer��kwargsr�Ztranspr r r!�_make_subprocess_transport�s"
���z,ProactorEventLoop._make_subprocess_transport)N)N)
r@rArBrCrr}r�r�r�rDr r rr!r
5s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�	�|_dSrK)
r2�_resultsrT�CreateIoCompletionPort�INVALID_HANDLE_VALUErq�_iocp�_cacherhrirH�
_unregistered�_stopped_serving)rZconcurrencyr r r!r�s
�
zIocpProactor.__init__cCs|jdurtd��dS)NzIocpProactor is closed)r�r\rMr r r!�
_check_closed�s
zIocpProactor._check_closedcCsFdt|j�dt|j�g}|jdur0|�d�d|jjd�|�fS)Nzoverlapped#=%sz
result#=%srpz<%s %s>� )�lenr�r�r�rOrr@�join)rr)r r r!�__repr__�s�

zIocpProactor.__repr__cCs
||_dSr:)r2)rrr r r!�set_loop�szIocpProactor.set_loopNcCs |js|�|�|j}g|_|Sr:)r�rN)r�timeoutrnr r r!�select�s

zIocpProactor.selectcCs|j��}|�|�|Sr:)r2r�r=)r�valuerQr r r!�_result�s

zIocpProactor._resultrcCs||�|�t�t�}z4t|tj�r6|�|��||�n|�|��|�Wnt	yd|�
d�YS0dd�}|�|||�S)N�c
SsTz
|��WStyN}z,|jtjtjfvr8t|j��n�WYd}~n
d}~00dSr:��	getresultr1rUrTZERROR_NETNAME_DELETEDZERROR_OPERATION_ABORTED�ConnectionResetErrorr��r��keyrr4r r r!�finish_recv�s
�z&IocpProactor.recv.<locals>.finish_recv)�_register_with_iocprT�
Overlappedrq�
isinstance�socketZWSARecvr�ZReadFile�BrokenPipeErrorr��	_register�r�conn�nbytesrurr�r r r!�recv�s


zIocpProactor.recvcCs||�|�t�t�}z4t|tj�r6|�|��||�n|�|��|�Wnt	yd|�
d�YS0dd�}|�|||�S)Nrc
SsTz
|��WStyN}z,|jtjtjfvr8t|j��n�WYd}~n
d}~00dSr:r�r�r r r!r��s
�z+IocpProactor.recv_into.<locals>.finish_recv)r�rTr�rqr�r�ZWSARecvIntor�ZReadFileIntor�r�r�)rr��bufrurr�r r r!�	recv_into�s


zIocpProactor.recv_intocCs^|�|�t�t�}z|�|��||�WntyF|�d�YS0dd�}|�|||�S)N)r�Nc
SsTz
|��WStyN}z,|jtjtjfvr8t|j��n�WYd}~n
d}~00dSr:r�r�r r r!r��s
�z*IocpProactor.recvfrom.<locals>.finish_recv)	r�rTr�rqZWSARecvFromr�r�r�r�r�r r r!�recvfrom�s


zIocpProactor.recvfromcCs>|�|�t�t�}|�|��|||�dd�}|�|||�S)Nc
SsTz
|��WStyN}z,|jtjtjfvr8t|j��n�WYd}~n
d}~00dSr:r�r�r r r!�finish_send	s
�z(IocpProactor.sendto.<locals>.finish_send)r�rTr�rqZ	WSASendTor�r�)rr�r�rurrr�r r r!�sendtos



zIocpProactor.sendtocCsZ|�|�t�t�}t|tj�r4|�|��||�n|�|��|�dd�}|�	|||�S)Nc
SsTz
|��WStyN}z,|jtjtjfvr8t|j��n�WYd}~n
d}~00dSr:r�r�r r r!r�s
�z&IocpProactor.send.<locals>.finish_send)
r�rTr�rqr�r�ZWSASendr�Z	WriteFiler�)rr�r�rurr�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_SOCKETrTZSO_UPDATE_ACCEPT_CONTEXT�
settimeoutZ
gettimeoutZgetpeername)r�r�rr��r��listenerr r!�
finish_accept/s�z*IocpProactor.accept.<locals>.finish_acceptc�s2z|IdHWntjy,|���Yn0dSr:)rr�rx)r.r�r r r!�accept_coro8s
z(IocpProactor.accept.<locals>.accept_coror)r��_get_accept_socket�familyrTr�rqZAcceptExr�r�r	Z
ensure_futurer2)rr�rr�r�r.�coror r�r!�accept)s

	
zIocpProactor.acceptc
s��jtjkr4t����|�|j��}|�d�|S|�	��zt�
����j�WnDty�}z,|j
tjkrr����ddkr��WYd}~n
d}~00t�t�}|����|��fdd�}|�|�|�S)Nrrcs|����tjtjd��SrK)r�r�r�r�rTZSO_UPDATE_CONNECT_CONTEXT�r�r�r�r�r r!�finish_connect[s
�z,IocpProactor.connect.<locals>.finish_connect)�typer�Z
SOCK_DGRAMrTZ
WSAConnectr�r2r�r=r�Z	BindLocalr�r1rU�errnoZ	WSAEINVALZgetsocknamer�rqZ	ConnectExr�)rr�r'rQ�err�r r�r!�connectEs"



zIocpProactor.connectc		Csb|�|�t�t�}|d@}|d?d@}|�|��t�|���|||dd�dd�}|�|||�S)Nr� rc
SsTz
|��WStyN}z,|jtjtjfvr8t|j��n�WYd}~n
d}~00dSr:r�r�r r r!�finish_sendfilens
�z.IocpProactor.sendfile.<locals>.finish_sendfile)	r�rTr�rqZTransmitFiler��msvcrtZ
get_osfhandler�)	rZsock�file�offset�countrZ
offset_lowZoffset_highr�r r r!�sendfileds


�	zIocpProactor.sendfilecsJ|���t�t�}|�����}|r0|���S�fdd�}|�|�|�S)Ncs|���Sr:)r�r��rwr r!�finish_accept_pipe�sz4IocpProactor.accept_pipe.<locals>.finish_accept_pipe)r�rTr�rqZConnectNamedPiper�r�r�)rrwrZ	connectedr�r r�r!r�ys


zIocpProactor.accept_pipec
�stt}zt�|�}WqjWn2tyH}z|jtjkr4�WYd}~n
d}~00t|dt�}t�	|�IdHqt
�|�S)N�)�CONNECT_PIPE_INIT_DELAYrTZConnectPiper1rUZERROR_PIPE_BUSY�min�CONNECT_PIPE_MAX_DELAYr	�sleepr
rr)rr'ZdelayrIr4r 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)rrIr�r r r!�wait_for_handle�szIocpProactor.wait_for_handlecCs|�|dd�}||_|Srf)r�rZ)rr[Z
done_callbackrQr r r!rd�szIocpProactor._wait_cancelcs�|��|durtj}nt�|d�}t�t�}t�||j	|j
|�}|r\t||||jd��nt
|||||jd���jr~�jd=�fdd�}�|d|f|j|j
<�S)N�@�@rrcs���Sr:)rNr��r�r r!�finish_wait_for_handle�sz=IocpProactor._wait_for_handle.<locals>.finish_wait_for_handler)r�rL�INFINITE�math�ceilrTr�rqZRegisterWaitWithQueuer�r'rYr2r]rr�)rrIr�Z
_is_cancel�msrrJr�r r�r!r��s$
�
�	zIocpProactor._wait_for_handlecCs0||jvr,|j�|�t�|��|jdd�dSrK)rHrsrTr�r�r��r�objr r r!r��s
z IocpProactor._register_with_iocpc
Cs�|��t||jd�}|jr$|jd=|jstz|dd|�}Wn.tyh}z|�|�WYd}~nd}~00|�|�||||f|j|j	<|Sr)
r�rr2rr"r1r;r=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�rOr~r r r!rc�szIocpProactor._unregistercCst�|�}|�d�|SrK)r�r�)rr��sr r r!r�s

zIocpProactor._get_accept_socketcCs�|durt}n0|dkr td��nt�|d�}|tkr>td��t�|j|�}|durX�qZd}|\}}}}z|j�|�\}}	}
}WnVt	y�|j
��r�|j
�dd||||fd��|dtj
fvr�t�|�Yq>Yn0|
|jvr�|��q>|��s>z||||	�}Wn<t�y@}
z"|�|
�|j�|�WYd}
~
q>d}
~
00|�|�|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�rTZGetQueuedCompletionStatusr�r��pop�KeyErrorr2Z	get_debugr3r�rLrbr�r0Zdoner1r;r�rOr=r�r'ry)rr�r�r��errZtransferredr�r'r�rr�r�r�r�r r r!rNsL


��	




"

zIocpProactor._pollcCs|j�|�dSr:)r�rsr�r r r!�
_stop_serving>szIocpProactor._stop_servingcCs|jdurdSt|j���D]�\}\}}}}|��r6qt|t�rBqz|��Wqty�}z>|j	dur�d||d�}|j
r�|j
|d<|j	�|�WYd}~qd}~00qd}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�rYr0r1r2rr3�time�	monotonicr�debugrNr�rLrb)rr'rQrr�r�r4r5Z
msg_updateZ
start_timeZnext_msgr r r!rxDs>


�
$�zIocpProactor.closecCs|��dSr:)rxrMr r r!rzsszIocpProactor.__del__)r)N)r)r)r)rN)r)N)N)r@rArBrCrr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rdr�r�r�rcr�rNr�rxrzr 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��}��|�dSr:)�_procZpollZ_process_exited)r��
returncoderMr r!r�~s
z4_WindowsSubprocessTransport._start.<locals>.callback)	r
�Popenrr2r^r��intrFr�)
rr�r�r�r�r�r�r�r�r�r rMr!�_startys���z"_WindowsSubprocessTransport._startN)r@rArBrr r r r!r�wsr�c@seZdZeZdS)rN)r@rArBr�
_loop_factoryr r r r!r�src@seZdZeZdS)rN)r@rArBr
rr r r r!r�sr)2rC�sys�platform�ImportErrorrTrLr�r�r�r�r�r�rh�rrrrrrr	r
�logr�__all__rqr�ZERROR_CONNECTION_REFUSEDZERROR_CONNECTION_ABORTEDr�r�ZFuturerrErYr]�objectreZBaseSelectorEventLoopr{ZBaseProactorEventLoopr
rZBaseSubprocessTransportr�rZBaseDefaultEventLoopPolicyrrrr r r r!�<module>sX
0J4;e`

?>