AlkantarClanX12

Your IP : 18.191.202.48


Current Path : /opt/alt/python37/lib64/python3.7/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/asyncio/__pycache__/windows_events.cpython-37.pyc

B

� fv�@s�dZddlZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
mZddl
mZddl
m
Z
ddl
mZddl
mZdd	l
mZdd
l
mZddlmZdZdZd
ZdZdZdZdZGdd�de
j�ZGdd�de
j�ZGdd�de�ZGdd�de�ZGdd�de �Z!Gdd�dej"�Z#Gdd�dej$�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)�proactor_events)�selector_events)�tasks)�
windows_utils)�logger)�SelectorEventLoop�ProactorEventLoop�IocpProactor�DefaultEventLoopPolicy�WindowsSelectorEventLoopPolicy�WindowsProactorEventLoopPolicyl��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)N)r���)�super�__init__�_source_traceback�_ov)�self�ovr)�	__class__��;/opt/alt/python37/lib64/python3.7/asyncio/windows_events.pyr0sz_OverlappedFuture.__init__csHt���}|jdk	rD|jjr dnd}|�dd|�d|jjd�d��|S)N�pendingZ	completedrzoverlapped=<z, z#x�>)r�
_repr_inforr�insert�address)r�info�state)rrrr6s


 z_OverlappedFuture._repr_infoc
Csr|jdkrdSy|j��WnJtk
rf}z,d||d�}|jrJ|j|d<|j�|�Wdd}~XYnXd|_dS)Nz&Cancelling an overlapped future failed)�message�	exception�future�source_traceback)r�cancel�OSErrorr�_loop�call_exception_handler)r�exc�contextrrr�_cancel_overlapped=s

z$_OverlappedFuture._cancel_overlappedcs|��t���S)N)r.rr()r)rrrr(Msz_OverlappedFuture.cancelcst��|�|��dS)N)r�
set_exceptionr.)rr%)rrrr/Qsz_OverlappedFuture.set_exceptioncst��|�d|_dS)N)r�
set_resultr)r�result)rrrr0Usz_OverlappedFuture.set_result)�__name__�
__module__�__qualname__�__doc__rrr.r(r/r0�
__classcell__rr)rrr*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.N)rcs8t�j|d�|jr|jd=||_||_||_d|_dS)N)rrT)rrrr�_handle�_wait_handle�_registered)rr�handle�wait_handler)rrrr]sz_BaseWaitHandleFuture.__init__cCst�|jd�tjkS)Nr)�_winapiZWaitForSingleObjectr8Z
WAIT_OBJECT_0)rrrr�_pollksz_BaseWaitHandleFuture._pollcsdt���}|�d|jd���|jdk	rB|��r4dnd}|�|�|jdk	r`|�d|jd���|S)Nzhandle=z#xZsignaledZwaitingzwait_handle=)rr�appendr8r>r9)rr"r#)rrrrps



z _BaseWaitHandleFuture._repr_infocCs
d|_dS)N)r)r�futrrr�_unregister_wait_cbzsz)_BaseWaitHandleFuture._unregister_wait_cbc
Cs�|js
dSd|_|j}d|_yt�|�WnZtk
r�}z<|jtjkrtd||d�}|jrd|j|d<|j�	|�dSWdd}~XYnX|�
d�dS)NFz$Failed to unregister the wait handle)r$r%r&r')r:r9�_overlappedZUnregisterWaitr)�winerror�ERROR_IO_PENDINGrr*r+rA)rr<r,r-rrr�_unregister_waits"
z&_BaseWaitHandleFuture._unregister_waitcs|��t���S)N)rErr()r)rrrr(�sz_BaseWaitHandleFuture.cancelcs|��t��|�dS)N)rErr/)rr%)rrrr/�sz#_BaseWaitHandleFuture.set_exceptioncs|��t��|�dS)N)rErr0)rr1)rrrr0�sz _BaseWaitHandleFuture.set_result)
r2r3r4r5rr>rrArEr(r/r0r6rr)rrr7Zs
r7csFeZdZdZdd��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.
    N)rcst�j||||d�d|_dS)N)r)rr�_done_callback)rr�eventr<r)rrrr�sz_WaitCancelFuture.__init__cCstd��dS)Nz'_WaitCancelFuture must not be cancelled)�RuntimeError)rrrrr(�sz_WaitCancelFuture.cancelcs$t��|�|jdk	r |�|�dS)N)rr0rG)rr1)rrrr0�s
z_WaitCancelFuture.set_resultcs$t��|�|jdk	r |�|�dS)N)rr/rG)rr%)rrrr/�s
z_WaitCancelFuture.set_exception)	r2r3r4r5rr(r0r/r6rr)rrrF�s
rFcs6eZdZdd��fdd�
Z�fdd�Zdd�Z�ZS)	�_WaitHandleFutureN)rcs<t�j||||d�||_d|_t�dddd�|_d|_dS)N)rTF)rr�	_proactorZ_unregister_proactorrBZCreateEvent�_event�
_event_fut)rrr;r<�proactorr)rrrr�s
z_WaitHandleFuture.__init__csF|jdk	r"t�|j�d|_d|_|j�|j�d|_t��|�dS)N)	rLr=�CloseHandlerMrK�_unregisterrrrA)rr@)rrrrA�s
	z%_WaitHandleFuture._unregister_wait_cbc
Cs�|js
dSd|_|j}d|_yt�||j�WnZtk
r�}z<|jtjkrxd||d�}|jrh|j|d<|j	�
|�dSWdd}~XYnX|j�|j|j
�|_dS)NFz$Failed to unregister the wait handle)r$r%r&r')r:r9rBZUnregisterWaitExrLr)rCrDrr*r+rK�_wait_cancelrArM)rr<r,r-rrrrE�s$

z"_WaitHandleFuture._unregister_wait)r2r3r4rrArEr6rr)rrrJ�srJc@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!rrrr�s

zPipeServer.__init__cCs|j|�d�}|_|S)NF)rWrY)r�tmprrr�_get_unconnected_pipe�sz PipeServer._get_unconnected_pipec
Csr|��rdStjtjB}|r&|tjO}t�|j|tjtjBtj	Btj
tjtjtj
tj�}t�|�}|j�|�|S)N)�closedr=ZPIPE_ACCESS_DUPLEXZFILE_FLAG_OVERLAPPEDZFILE_FLAG_FIRST_PIPE_INSTANCEZCreateNamedPiperSZPIPE_TYPE_MESSAGEZPIPE_READMODE_MESSAGEZ	PIPE_WAITZPIPE_UNLIMITED_INSTANCESr	ZBUFSIZEZNMPWAIT_WAIT_FOREVER�NULL�
PipeHandlerV�add)r�first�flags�h�piperrrrYs


zPipeServer._server_pipe_handlecCs
|jdkS)N)rS)rrrrr\szPipeServer.closedcCsV|jdk	r|j��d|_|jdk	rRx|jD]}|��q,Wd|_d|_|j��dS)N)rXr(rSrV�closerW�clear)rrcrrrrds


zPipeServer.closeN)
r2r3r4r5rr[rYr\rd�__del__rrrrrR�s
rRc@seZdZdZdS)�_WindowsSelectorEventLoopz'Windows version of selector event loop.N)r2r3r4r5rrrrrg+srgcs<eZdZdZd�fdd�	Zdd�Zdd�Zdd	d
�Z�ZS)
rz2Windows version of proactor event loop using IOCP.Ncs|dkrt�}t��|�dS)N)r
rr)rrN)rrrr2szProactorEventLoop.__init__c�s8|j�|�}|IdH}|�}|j||d|id�}||fS)N�addr)�extra)rK�connect_pipe�_make_duplex_pipe_transport)r�protocol_factoryr!�frc�protocol�transrrr�create_pipe_connection7s
z(ProactorEventLoop.create_pipe_connectionc�s.t���d�����fdd�	������gS)Nc
sd}yj|rL|��}�j�|����r2|��dS��}�j||d�id����}|dkr`dS�j�|�}Wn�t	k
r�}zF|r�|�
�dkr���d||d��|��n�jr�t
jd|dd�Wdd}~XYn2tjk
r�|r�|��YnX|�_|���dS)	Nrh)rirzPipe accept failed)r$r%rczAccept pipe failed on pipe %rT)�exc_info)r1rV�discardr\rdrkr[rK�accept_piper)�filenor+Z_debugr
Zwarningr�CancelledErrorrX�add_done_callback)rmrcrnr,)r!�loop_accept_piperlr�serverrrrwBs<

z>ProactorEventLoop.start_serving_pipe.<locals>.loop_accept_pipe)N)rRZ	call_soon)rrlr!r)r!rwrlrrxr�start_serving_pipe?s(
z$ProactorEventLoop.start_serving_pipec		�sl|��}
t||||||||f|
|d�|	��}y|
IdHWn,tk
rf|��|��IdH�YnX|S)N)�waiterri)�
create_future�_WindowsSubprocessTransport�	ExceptionrdZ_wait)rrn�args�shell�stdin�stdout�stderr�bufsizeri�kwargsrzZtransprrr�_make_subprocess_transportms

z,ProactorEventLoop._make_subprocess_transport)N)N)	r2r3r4r5rrpryr�r6rr)rrr/s
0rc@s�eZdZdZd7dd�Zdd�Zdd�Zd	d
�Zd8dd
�Zdd�Z	d9dd�Z
d:dd�Zd;dd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd<d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd=d/d0�Zd1d2�Zd3d4�Zd5d6�ZdS)>r
z#Proactor implementation using IOCP.���cCsDd|_g|_t�tjtd|�|_i|_t�	�|_
g|_t�	�|_dS)Nr)
r*�_resultsrB�CreateIoCompletionPort�INVALID_HANDLE_VALUEr]�_iocp�_cacherTrUr:�
_unregistered�_stopped_serving)rZconcurrencyrrrr�s
zIocpProactor.__init__cCs|jdkrtd��dS)NzIocpProactor is closed)r�rI)rrrr�
_check_closed�s
zIocpProactor._check_closedcCsFdt|j�dt|j�g}|jdkr0|�d�d|jjd�|�fS)Nzoverlapped#=%sz
result#=%sr\z<%s %s>� )�lenr�r�r�r?rr2�join)rr"rrr�__repr__�s


zIocpProactor.__repr__cCs
||_dS)N)r*)rrrrr�set_loop�szIocpProactor.set_loopNcCs |js|�|�|j}g|_|S)N)r�r>)r�timeoutrZrrr�select�s

zIocpProactor.selectcCs|j��}|�|�|S)N)r*r{r0)r�valuer@rrr�_result�s

zIocpProactor._resultrcCsz|�|�t�t�}y4t|tj�r6|�|��||�n|�|��|�Wnt	k
rb|�
d�SXdd�}|�|||�S)N�c
SsPy|��Stk
rJ}z$|jtjtjfkr8t|j��n�Wdd}~XYnXdS)N)�	getresultr)rCrB�ERROR_NETNAME_DELETED�ERROR_OPERATION_ABORTED�ConnectionResetErrorr~)ro�keyrr,rrr�finish_recv�s
z&IocpProactor.recv.<locals>.finish_recv)�_register_with_iocprB�
Overlappedr]�
isinstance�socketZWSARecvrtZReadFile�BrokenPipeErrorr��	_register)r�conn�nbytesrarr�rrr�recv�s


zIocpProactor.recvcCsz|�|�t�t�}y4t|tj�r6|�|��||�n|�|��|�Wnt	k
rb|�
d�SXdd�}|�|||�S)Nr�c
SsPy|��Stk
rJ}z$|jtjtjfkr8t|j��n�Wdd}~XYnXdS)N)r�r)rCrBr�r�r�r~)ror�rr,rrrr��s
z+IocpProactor.recv_into.<locals>.finish_recv)r�rBr�r]r�r�ZWSARecvIntortZReadFileIntor�r�r�)rr��bufrarr�rrr�	recv_into�s


zIocpProactor.recv_intocCsZ|�|�t�t�}t|tj�r4|�|��||�n|�|��|�dd�}|�	|||�S)Nc
SsPy|��Stk
rJ}z$|jtjtjfkr8t|j��n�Wdd}~XYnXdS)N)r�r)rCrBr�r�r�r~)ror�rr,rrr�finish_send�s
z&IocpProactor.send.<locals>.finish_send)
r�rBr�r]r�r�ZWSASendrtZ	WriteFiler�)rr�r�rarr�rrr�send�s


zIocpProactor.sendcsv|���|��j��t�t�}|����������fdd�}dd�}|�|�|�}||��}t	j
||jd�|S)NcsD|��t�d����}��tjtj|���	��
������fS)Nz@P)r��structZpackrt�
setsockoptr��
SOL_SOCKETrBZSO_UPDATE_ACCEPT_CONTEXT�
settimeoutZ
gettimeoutZgetpeername)ror�rr�)r��listenerrr�
finish_accept�s
z*IocpProactor.accept.<locals>.finish_acceptc�s4y|IdHWn tjk
r.|���YnXdS)N)rrurd)r&r�rrr�accept_coro�s
z(IocpProactor.accept.<locals>.accept_coro)r)r��_get_accept_socket�familyrBr�r]ZAcceptExrtr�rZ
ensure_futurer*)rr�rr�r�r&�coror)r�r�r�accept�s

	
zIocpProactor.acceptc
s�|���yt�����j�WnBtk
rb}z$|jtjkr@���	�ddkrR�Wdd}~XYnXt�
t�}|����|��fdd�}|�
|�|�S)Nrrcs|����tjtjd��S)Nr)r�r�r�r�rBZSO_UPDATE_CONNECT_CONTEXT)ror�r)r�rr�finish_connects
z,IocpProactor.connect.<locals>.finish_connect)r�rBZ	BindLocalrtr�r)rC�errnoZ	WSAEINVALZgetsocknamer�r]Z	ConnectExr�)rr�r!�err�r)r�r�connects

zIocpProactor.connectc		Csb|�|�t�t�}|d@}|d?d@}|�|��t�|���|||dd�dd�}|�|||�S)Nl��� rc
SsPy|��Stk
rJ}z$|jtjtjfkr8t|j��n�Wdd}~XYnXdS)N)r�r)rCrBr�r�r�r~)ror�rr,rrr�finish_sendfile%s
z.IocpProactor.sendfile.<locals>.finish_sendfile)	r�rBr�r]ZTransmitFilert�msvcrtZ
get_osfhandler�)	rZsock�file�offset�countrZ
offset_lowZoffset_highr�rrr�sendfiles



	zIocpProactor.sendfilecsJ|���t�t�}|�����}|r0|���S�fdd�}|�|�|�S)Ncs|���S)N)r�)ror�r)rcrr�finish_accept_pipe;sz4IocpProactor.accept_pipe.<locals>.finish_accept_pipe)r�rBr�r]ZConnectNamedPipertr�r�)rrcrZ	connectedr�r)rcrrs0s


zIocpProactor.accept_pipec
�szt}xjyt�|�}PWn0tk
rF}z|jtjkr6�Wdd}~XYnXt|dt�}tj	||j
d�IdHqWt�|�S)N�)r)
�CONNECT_PIPE_INIT_DELAYrBZConnectPiper)rCZERROR_PIPE_BUSY�min�CONNECT_PIPE_MAX_DELAYrZsleepr*r	r^)rr!Zdelayr;r,rrrrjAs
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)rr;r�rrr�wait_for_handleTszIocpProactor.wait_for_handlecCs|�|dd�}||_|S)NT)r�rG)rrHZ
done_callbackr@rrrrQ\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)Ng@�@)rrcs���S)N)r>)ror�r)rmrr�finish_wait_for_handleysz=IocpProactor._wait_for_handle.<locals>.finish_wait_for_handler)r�r=�INFINITE�math�ceilrBr�r]ZRegisterWaitWithQueuer�r!rFr*rJrr�)rr;r�Z
_is_cancel�msrr<r�r)rmrr�cs 


	zIocpProactor._wait_for_handlecCs0||jkr,|j�|�t�|��|jdd�dS)Nr)r:r_rBr�rtr�)r�objrrrr��s
z IocpProactor._register_with_iocpc
Cs�|��t||jd�}|jr$|jd=|jsry|dd|�}Wn,tk
rf}z|�|�Wdd}~XYnX|�|�||||f|j|j	<|S)N)rr)
r�rr*rrr)r/r0r�r!)rrr��callbackrmr�r�rrrr��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�r?)rrrrrrP�szIocpProactor._unregistercCst�|�}|�d�|S)Nr)r�r�)rr��srrrr��s

zIocpProactor._get_accept_socketcCs�|dkrt}n0|dkr td��nt�|d�}|tkr>td���xt�|j|�}|dkrZPd}|\}}}}y|j�|�\}}	}
}WnVt	k
r�|j
��r�|j
�dd||||fd��|dtj
fkr�t�|�wBYnX|
|jkr�|��qB|��sBy||||	�}Wn:tk
�r@}
z|�|
�|j�|�Wdd}
~
XYqBX|�|�|j�|�qBWx |jD]}	|j�|	jd��qdW|j��dS)Nrznegative timeoutg@�@ztimeout too bigz8GetQueuedCompletionStatus() returned an unexpected eventz)err=%s transferred=%s key=%#x address=%#x)r$�status)r��
ValueErrorr�r�rBZGetQueuedCompletionStatusr�r��pop�KeyErrorr*Z	get_debugr+r�r=rOr�r(Zdoner)r/r�r?r0r�r!re)rr�r�r��errZtransferredr�r!rmrr�r�r�r�rrrr>�sJ






zIocpProactor._pollcCs|j�|�dS)N)r�r_)rr�rrr�
_stop_serving�szIocpProactor._stop_servingcCs |jdkrdSx�t|j���D]�\}\}}}}|��r8qt|t�rDqy|��Wqtk
r�}z6|j	dk	r�d||d�}|j
r�|j
|d<|j	�|�Wdd}~XYqXqWd}t�
�}	|	|}
xD|j�r|
t�
�kr�t�d|t�
�|	�t�
�|}
|�|�q�Wg|_t�|j�d|_dS)NzCancelling a future failed)r$r%r&r'g�?z,%r is running after closing for %.1f seconds)r��listr��itemsZ	cancelledr�rFr(r)r*rr+�timeZ	monotonicr
�debugr>r�r=rO)rr!r@rr�r�r,r-Z
msg_updateZ
start_timeZnext_msgrrrrd�s:
 


"
zIocpProactor.closecCs|��dS)N)rd)rrrrrf*szIocpProactor.__del__)r�)N)r)r)r)N)N)r2r3r4r5rr�r�r�r�r�r�r�r�r�r�r�rsrjr�rQr�r�r�rPr�r>r�rdrfrrrrr
s4






"
 

7/r
c@seZdZdd�ZdS)r|c
sPtj|f|||||d�|���_�fdd�}�jj�t�jj��}	|	�|�dS)N)rr�r�r�r�cs�j��}��|�dS)N)�_procZpollZ_process_exited)rm�
returncode)rrrr�5s
z4_WindowsSubprocessTransport._start.<locals>.callback)	r	�Popenr�r*rKr��intr8rv)
rr~rr�r�r�r�r�r�rmr)rr�_start0sz"_WindowsSubprocessTransport._startN)r2r3r4r�rrrrr|.sr|c@seZdZeZdS)rN)r2r3r4r�
_loop_factoryrrrrr@src@seZdZeZdS)rN)r2r3r4rr�rrrrrDsr).r5rBr=r�r�r�r�r�r�rT�rrrrrrr	�logr
�__all__r]r�ZERROR_CONNECTION_REFUSEDZERROR_CONNECTION_ABORTEDr�r�ZFuturerr7rFrJ�objectrRZBaseSelectorEventLooprgZBaseProactorEventLooprr
ZBaseSubprocessTransportr|rZBaseDefaultEventLoopPolicyrrrrrrr�<module>sP0J4;P2