Your IP : 18.119.117.77


Current Path : /opt/alt/python310/lib64/python3.10/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/asyncio/__pycache__/windows_events.cpython-310.opt-1.pyc

o

6��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/python310/lib64/python3.10/asyncio/windows_events.pyr6s
z_OverlappedFuture.__init__csHt���}|jdur"|jjrdnd}|�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��Wn&ty4}zd||d�}|jr$|j|d<|j�|�WYd}~nd}~wwd|_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_overlappedc�|��t�j|d�S�N)�msg)r6rr0�rr9rr r!r0S�z_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_resultr<)�__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!rcs
z_BaseWaitHandleFuture.__init__cCst�|jd�tjkS�Nr)�_winapiZWaitForSingleObjectrHZ
WAIT_OBJECT_0�rr r r!�_pollqs�z_BaseWaitHandleFuture._pollcsdt���}|�d|jd���|jdur!|��rdnd}|�|�|jdur0|�d|jd���|S)Nzhandle=r#ZsignaledZwaitingzwait_handle=)rr%�appendrHrPrIr(rr r!r%vs



z _BaseWaitHandleFuture._repr_infocCs
d|_dSr<)r�r�futr r r!�_unregister_wait_cb�s
z)_BaseWaitHandleFuture._unregister_wait_cbc
Cs�|jsdSd|_|j}d|_zt�|�Wn3tyH}z'|jtjkr>d||d�}|jr1|j|d<|j�	|�WYd}~dSWYd}~nd}~ww|�
d�dS�NFz$Failed to unregister the wait handler+r/)rJrI�_overlappedZUnregisterWaitr1�winerror�ERROR_IO_PENDINGrr2r3rT�rrLr4r5r r r!�_unregister_wait�s*�
���
z&_BaseWaitHandleFuture._unregister_waitcr7r8)rZrr0r:rr r!r0�r;z_BaseWaitHandleFuture.cancelc�|��t��|�dSr<)rZrr=r>rr r!r=��z#_BaseWaitHandleFuture.set_exceptioncr[r<)rZrr?r@rr r!r?�r\z _BaseWaitHandleFuture.set_resultr<)
rBrCrDrErrPr%rTrZr0r=r?rFr r rr!rG`s
rGcsFeZdZdZdd��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�eventrLrrr r!r�s
z_WaitCancelFuture.__init__cCstd��)Nz'_WaitCancelFuture must not be cancelled)�RuntimeErrorrOr r r!r0�sz_WaitCancelFuture.cancelc�(t��|�|jdur|�|�dSdSr<)rr?r^r@rr r!r?��
�z_WaitCancelFuture.set_resultcrar<)rr=r^r>rr r!r=�rbz_WaitCancelFuture.set_exception)	rBrCrDrErr0r?r=rFr r rr!r]�sr]cs6eZdZdd��fdd�
Z�fdd�Zdd�Z�ZS)	�_WaitHandleFutureNrcs<t�j||||d�||_d|_t�dddd�|_d|_dS)NrTF)rr�	_proactorZ_unregister_proactorrVZCreateEvent�_event�
_event_fut)rrrKrL�proactorrrr r!r�s

z_WaitHandleFuture.__init__csF|jdurt�|j�d|_d|_|j�|j�d|_t��|�dSr<)	rerN�CloseHandlerfrd�_unregisterrrrTrRrr r!rT�s
	z%_WaitHandleFuture._unregister_wait_cbc
Cs�|jsdSd|_|j}d|_z	t�||j�Wn3tyJ}z'|jtjkr@d||d�}|jr3|j|d<|j	�
|�WYd}~dSWYd}~nd}~ww|j�|j|j
�|_dSrU)rJrIrVZUnregisterWaitExrer1rWrXrr2r3rd�_wait_cancelrTrfrYr r r!rZ�s.�
���


�z"_WaitHandleFuture._unregister_wait)rBrCrDrrTrZrFr r rr!rc�srcc@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)rqrs)r�tmpr r r!�_get_unconnected_pipesz PipeServer._get_unconnected_pipec
Csr|��rdStjtjB}|r|tjO}t�|j|tjtjBtj	Btj
tjtjtj
tj�}t�|�}|j�|�|Sr<)�closedrNZPIPE_ACCESS_DUPLEXZFILE_FLAG_OVERLAPPEDZFILE_FLAG_FIRST_PIPE_INSTANCEZCreateNamedPipermZPIPE_TYPE_MESSAGEZPIPE_READMODE_MESSAGEZ	PIPE_WAITZPIPE_UNLIMITED_INSTANCESr
ZBUFSIZEZNMPWAIT_WAIT_FOREVER�NULL�
PipeHandlerp�add)r�first�flags�h�piper r r!rs
s"

��
zPipeServer._server_pipe_handlecCs
|jduSr<)rmrOr r r!rv�
zPipeServer.closedcCsV|jdur
|j��d|_|jdur)|jD]}|��qd|_d|_|j��dSdSr<)rrr0rmrp�closerq�clear)rr}r r r!r"s




�zPipeServer.closeN)
rBrCrDrErrursrvr�__del__r r r r!rk�s
rkc@seZdZdZdS)�_WindowsSelectorEventLoopz'Windows version of selector event loop.N)rBrCrDrEr r r r!r�1�r�csJeZdZdZd
�fdd�	Z�fdd�Zdd�Zd	d
�Z	d
dd�Z�Z	S)r
z2Windows version of proactor event loop using IOCP.Ncs|durt�}t��|�dSr<)rrr)rrgrr r!r8szProactorEventLoop.__init__c	s�z.|�|j�t���W|jdur-|jj}|j��|dur(|js(|j�	|�d|_dSdS|jdurM|jj}|j��|durJ|jsJ|j�	|�d|_wr<)
�	call_soonZ_loop_self_readingr�run_foreverZ_self_reading_futurerr0r"rdri�rrrr r!r�=s


�
zProactorEventLoop.run_foreverc�s:�|j�|�}|IdH}|�}|j||d|id�}||fS)N�addr��extra)rd�connect_pipe�_make_duplex_pipe_transport)r�protocol_factoryr'�fr}�protocol�transr r r!�create_pipe_connectionPs�
�z(ProactorEventLoop.create_pipe_connectionc�s0�t���d�����fdd�	������gS)Nc
sTd}z7|r'|��}�j�|����r|��WdS��}�j||d�id����}|dur2WdS�j�|�}Wnft	yT|rL|�
�dkrL|������YdSty�}z-|rq|�
�dkrq��
d||d��|��n�jr|tjd|dd�����WYd}~dSd}~wtjy�|r�|��YdSYdSw|�_|���dS)	Nr�r�rzPipe accept failed)r,r-r}zAccept pipe failed on pipe %rT)�exc_info)rArp�discardrvrr�rurd�accept_pipe�BrokenPipeError�filenor�r1r3Z_debugrZwarningr�CancelledErrorrr�add_done_callback)r�r}r�r4�r'�loop_accept_piper�rZserverr r!r�[sR
��
����z>ProactorEventLoop.start_serving_pipe.<locals>.loop_accept_piper<)rkr�)rr�r'r r�r!�start_serving_pipeXs
�
-z$ProactorEventLoop.start_serving_pipec		�sx�|��}
t||||||||f|
|d�|	��}z|
IdHW|Sttfy)�ty;|��|��IdH�w)N)�waiterr�)�
create_future�_WindowsSubprocessTransport�
SystemExit�KeyboardInterrupt�
BaseExceptionrZ_wait)rr��args�shell�stdin�stdout�stderr�bufsizer��kwargsr�Ztranspr r r!�_make_subprocess_transport�s&�
�����z,ProactorEventLoop._make_subprocess_transportr<)
rBrCrDrErr�r�r�r�rFr r rr!r
5s5�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
d=dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd<d%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd<d3d4�Zd5d6�Zd7d8�Zd9d:�ZdS)?rz#Proactor implementation using IOCP.rcCsDd|_g|_t�tjtd|�|_i|_t�	�|_
g|_t�	�|_dSrM)
r2�_resultsrV�CreateIoCompletionPort�INVALID_HANDLE_VALUErw�_iocp�_cachernrorJ�
_unregistered�_stopped_serving)rZconcurrencyr r r!r�s
�
zIocpProactor.__init__cCs|jdur	td��dS)NzIocpProactor is closed)r�r`rOr r r!�
_check_closed�s
�zIocpProactor._check_closedcCsFdt|j�dt|j�g}|jdur|�d�d|jjd�|�fS)Nzoverlapped#=%sz
result#=%srvz<%s %s>� )�lenr�r�r�rQrrB�join)rr)r r r!�__repr__�s�

zIocpProactor.__repr__cCs
||_dSr<)r2)rrr r r!�set_loop�r~zIocpProactor.set_loopNcCs.|js|�|�|j}g|_z|Wd}Sd}wr<)r�rP)r�timeoutrtr r r!�select�s
zIocpProactor.selectcCs|j��}|�|�|Sr<)r2r�r?)r�valuerSr r r!�_result��

zIocpProactor._resultrcC�||�|�t�t�}zt|tj�r|�|��||�n|�|��|�Wnt	y2|�
d�YSwdd�}|�|||�S)N�c
S�Bz|��WSty }z|jtjtjfvrt|j���d}~wwr<��	getresultr1rWrVZERROR_NETNAME_DELETEDZERROR_OPERATION_ABORTED�ConnectionResetErrorr��r��keyrr4r r r!�finish_recv��
�
��z&IocpProactor.recv.<locals>.finish_recv)�_register_with_iocprV�
Overlappedrw�
isinstance�socketZWSARecvr�ZReadFiler�r��	_register�r�conn�nbytesr{rr�r r r!�recv��

��
zIocpProactor.recvcCr�)Nrc
Sr�r<r�r�r r r!r��r�z+IocpProactor.recv_into.<locals>.finish_recv)r�rVr�rwr�r�ZWSARecvIntor�ZReadFileIntor�r�r�)rr��bufr{rr�r r r!�	recv_into�r�zIocpProactor.recv_intocCs^|�|�t�t�}z|�|��||�Wnty#|�d�YSwdd�}|�|||�S)N)r�Nc
Sr�r<r�r�r r r!r�r�z*IocpProactor.recvfrom.<locals>.finish_recv)	r�rVr�rwZWSARecvFromr�r�r�r�r�r r r!�recvfrom�s

�
zIocpProactor.recvfromcCs>|�|�t�t�}|�|��|||�dd�}|�|||�S)Nc
Sr�r<r�r�r r r!�finish_sendr�z(IocpProactor.sendto.<locals>.finish_send)r�rVr�rwZ	WSASendTor�r�)rr�r�r{r�rr�r r r!�sendtos



zIocpProactor.sendtocCsZ|�|�t�t�}t|tj�r|�|��||�n|�|��|�dd�}|�	|||�S)Nc
Sr�r<r�r�r r r!r�&r�z&IocpProactor.send.<locals>.finish_send)
r�rVr�rwr�r�ZWSASendr�Z	WriteFiler�)rr�r�r{rr�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_SOCKETrVZSO_UPDATE_ACCEPT_CONTEXT�
settimeoutZ
gettimeoutZgetpeername)r�r�rr��r��listenerr r!�
finish_accept8s�z*IocpProactor.accept.<locals>.finish_acceptc�s.�z|IdHWdStjy|���wr<)rr�r)r.r�r r r!�accept_coroAs��z(IocpProactor.accept.<locals>.accept_coror)r��_get_accept_socket�familyrVr�rwZAcceptExr�r�r	Z
ensure_futurer2)rr�rr�r�r.�coror r�r!�accept2s

	
zIocpProactor.acceptc
s��jtjkrt����|�|j��}|�d�|S|�	��zt�
����j�Wn"tyL}z|j
tjkr9����ddkrB�WYd}~nd}~wwt�t�}|����|��fdd�}|�|�|�S)Nrrcs|����tjtjd��SrM)r�r�r�r�rVZSO_UPDATE_CONNECT_CONTEXT�r�r�r�r�r r!�finish_connectds
�z,IocpProactor.connect.<locals>.finish_connect)�typer�Z
SOCK_DGRAMrVZ
WSAConnectr�r2r�r?r�Z	BindLocalr�r1rW�errnoZ	WSAEINVALZgetsocknamer�rwZ	ConnectExr�)rr�r'rS�err�r r�r!�connectNs(


���
zIocpProactor.connectc		Csb|�|�t�t�}|d@}|d?d@}|�|��t�|���|||dd�dd�}|�|||�S)Nr� rc
Sr�r<r�r�r r r!�finish_sendfilewr�z.IocpProactor.sendfile.<locals>.finish_sendfile)	r�rVr�rwZTransmitFiler��msvcrtZ
get_osfhandler�)	rZsock�file�offset�countrZ
offset_lowZoffset_highr�r r r!�sendfilems


�	zIocpProactor.sendfilecsJ|���t�t�}|�����}|r|���S�fdd�}|�|�|�S)Ncs|���Sr<)r�r��r}r r!�finish_accept_pipe�sz4IocpProactor.accept_pipe.<locals>.finish_accept_pipe)r�rVr�rwZConnectNamedPiper�r�r�)rr}rZ	connectedr�r r�r!r��s


zIocpProactor.accept_pipec
�st�t}	zt�|�}Wn)ty$}z
|jtjkr�WYd}~nd}~wwt|dt�}t�	|�IdHqt
�|�S)NT�)�CONNECT_PIPE_INIT_DELAYrVZConnectPiper1rWZERROR_PIPE_BUSY�min�CONNECT_PIPE_MAX_DELAYr	�sleepr
rx)rr'ZdelayrKr4r 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)rrKr�r r r!�wait_for_handle�szIocpProactor.wait_for_handlecCs|�|dd�}||_|Srl)r�r^)rr_Z
done_callbackrSr r r!rj�szIocpProactor._wait_cancelcs�|��|durtj}nt�|d�}t�t�}t�||j	|j
|�}|r.t||||jd��n
t
|||||jd���jr?�jd=�fdd�}�|d|f|j|j
<�S)N�@�@rrcs���Sr<)rPr��r�r r!�finish_wait_for_handle�sz=IocpProactor._wait_for_handle.<locals>.finish_wait_for_handler)r�rN�INFINITE�math�ceilrVr�rwZRegisterWaitWithQueuer�r'r]r2rcrr�)rrKr�Z
_is_cancel�msrrLr�r r�r!r��s$
�
�	zIocpProactor._wait_for_handlecCs4||jvr|j�|�t�|��|jdd�dSdSrM)rJryrVr�r�r��r�objr r r!r��s
�z IocpProactor._register_with_iocpc
Cs�|��t||jd�}|jr|jd=|js:z|dd|�}Wnty4}z|�|�WYd}~n
d}~ww|�|�||||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�rQr�r r r!riszIocpProactor._unregistercCst�|�}|�d�|SrM)r�r�)rr��sr r r!r�r�zIocpProactor._get_accept_socketcCs�|durt}n|dkrtd��t�|d�}|tkrtd��	t�|j|�}|dur+n�d}|\}}}}z|j�|�\}}	}
}Wn)t	yh|j
��rZ|j
�dd||||fd��|dtj
fvrft�|�Yqw|
|jvrs|��n=|��s�z5z||||	�}Wnty�}
z|�|
�|j�|�WYd}
~
nd}
~
ww|�|�|j�|�Wd}nd}wq|jD]
}	|j�|	jd�q�|j��dS)	Nrznegative timeoutr�ztimeout too bigTz8GetQueuedCompletionStatus() returned an unexpected eventz)err=%s transferred=%s key=%#x address=%#x)r,�status)r��
ValueErrorr�r�rVZGetQueuedCompletionStatusr�r��pop�KeyErrorr2Z	get_debugr3r�rNrhr�r0Zdoner1r=r�rQr?r�r'r�)rr�r�r�errZtransferredr�r'r�rrrr�r�r r r!rPsZ

��	
�


��
��
)zIocpProactor._pollcCs|j�|�dSr<)r�ryr�r r r!�
_stop_servingIszIocpProactor._stop_servingcCs|jdurdSt|j���D]D\}\}}}}|��rqt|t�r!qz|��WqtyR}z|j	durHd||d�}|j
rB|j
|d<|j	�|�WYd}~qd}~wwd}t�
�}	|	|}
|jr|
t�
�krwt�d|t�
�|	�t�
�|}
|�|�|js`g|_t�|j�d|_dS)NzCancelling a future failedr+r/g�?z,%r is running after closing for %.1f seconds)r��listr��itemsZ	cancelledr�r]r0r1r2rr3�time�	monotonicr�debugrPr�rNrh)rr'rSrrrr4r5Z
msg_updateZ
start_timeZnext_msgr r r!rOsD


�
���
�	
zIocpProactor.closecCs|��dSr<)rrOr r r!r�~szIocpProactor.__del__)rr<)r)rN)rBrCrDrErr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rjr�r�r�rir�rPrrr�r r r r!r�s:








"
 

9/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��
returncoderOr r!r�s
z4_WindowsSubprocessTransport._start.<locals>.callback)	r
�Popenrr2rdr��intrHr�)
rr�r�r�r�r�r�r�rr�r rOr!�_start�s���z"_WindowsSubprocessTransport._startN)rBrCrDrr r r r!r��sr�c@�eZdZeZdS)rN)rBrCrDr�
_loop_factoryr r r r!r�r�rc@r)rN)rBrCrDr
rr r r r!r�r�r)2rE�sys�platform�ImportErrorrVrNr�r�r�r�r�rrn�rrrrrrr	r
�logr�__all__rwr�ZERROR_CONNECTION_REFUSEDZERROR_CONNECTION_ABORTEDr�r�ZFuturerrGr]rc�objectrkZBaseSelectorEventLoopr�ZBaseProactorEventLoopr
rZBaseSubprocessTransportr�rZBaseDefaultEventLoopPolicyrrrr r r r!�<module>sZ
0J4;jf

?>