Hacked By AnonymousFox

Current Path : /opt/alt/python36/lib64/python3.6/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python36/lib64/python3.6/asyncio/__pycache__/windows_events.cpython-36.opt-1.pyc

3

� f�l�@s�dZddlZddlZddlZddlZddlZddlZddlmZddlm	Z	ddlm
Z
ddlmZddlmZdd	lm
Z
dd
lmZddlmZddlmZdd
lmZddddgZdZdZdZdZdZdZGdd�de
j�ZGdd�de
j�ZGdd�de�ZGdd�de�ZGdd �d e �Z!Gd!d"�d"ej"�Z#Gd#d�dej$�Z%Gd$d�d�Z&Gd%d&�d&e	j'�Z(e#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)�_overlapped)�	coroutine)�logger�SelectorEventLoop�ProactorEventLoop�IocpProactor�DefaultEventLoopPolicyl��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)rr���)�super�__init__�_source_traceback�_ov)�self�ovr)�	__class__��;/opt/alt/python36/lib64/python3.6/asyncio/windows_events.pyr-sz_OverlappedFuture.__init__cs@t�j�}|jdk	r<|jjr dnd}|jdd||jjf�|S)N�pendingZ	completedrzoverlapped=<%s, %#x>)r�
_repr_inforr�insert�address)r�info�state)rrrr3s


z_OverlappedFuture._repr_infocCsr|jdkrdSy|jj�WnJtk
rf}z.d||d�}|jrJ|j|d<|jj|�WYdd}~XnXd|_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|j�t�j�S)N)r-rr')r)rrrr'Jsz_OverlappedFuture.cancelcst�j|�|j�dS)N)r�
set_exceptionr-)rr$)rrrr.Nsz_OverlappedFuture.set_exceptioncst�j|�d|_dS)N)r�
set_resultr)r�result)rrrr/Rsz_OverlappedFuture.set_result)�__name__�
__module__�__qualname__�__doc__rrr-r'r.r/�
__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)rrTr)rrrr�_handle�_wait_handle�_registered)rr�handle�wait_handler)rrrrZsz_BaseWaitHandleFuture.__init__cCstj|jd�tjkS)Nr)�_winapiZWaitForSingleObjectr7Z
WAIT_OBJECT_0)rrrr�_pollhsz_BaseWaitHandleFuture._pollcs\t�j�}|jd|j�|jdk	r>|j�r0dnd}|j|�|jdk	rX|jd|j�|S)Nz
handle=%#xZsignaledZwaitingzwait_handle=%#x)rr�appendr7r=r8)rr!r")rrrrms



z _BaseWaitHandleFuture._repr_infocCs
d|_dS)N)r)r�futrrr�_unregister_wait_cbwsz)_BaseWaitHandleFuture._unregister_wait_cbcCs�|js
dSd|_|j}d|_ytj|�WnZtk
r�}z>|jtjkrtd||d�}|jrd|j|d<|jj	|�dSWYdd}~XnX|j
d�dS)NFz$Failed to unregister the wait handle)r#r$r%r&)r9r8r
ZUnregisterWaitr(�winerror�ERROR_IO_PENDINGrr)r*r@)rr;r+r,rrr�_unregister_wait|s"
z&_BaseWaitHandleFuture._unregister_waitcs|j�t�j�S)N)rCrr')r)rrrr'�sz_BaseWaitHandleFuture.cancelcs|j�t�j|�dS)N)rCrr.)rr$)rrrr.�sz#_BaseWaitHandleFuture.set_exceptioncs|j�t�j|�dS)N)rCrr/)rr0)rrrr/�sz _BaseWaitHandleFuture.set_result)
r1r2r3r4rr=rr@rCr'r.r/r5rr)rrr6Ws
r6csFeZdZdZdd��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�j|�|jdk	r |j|�dS)N)rr/rE)rr0)rrrr/�s
z_WaitCancelFuture.set_resultcs$t�j|�|jdk	r |j|�dS)N)rr.rE)rr$)rrrr.�s
z_WaitCancelFuture.set_exception)	r1r2r3r4rr'r/r.r5rr)rrrD�s
rDcs6eZdZdd��fdd�
Z�fdd�Zdd�Z�ZS)	�_WaitHandleFutureN)rcs<t�j||||d�||_d|_tjdddd�|_d|_dS)N)rTF)rr�	_proactorZ_unregister_proactorr
ZCreateEvent�_event�
_event_fut)rrr:r;�proactorr)rrrr�s
z_WaitHandleFuture.__init__csF|jdk	r"tj|j�d|_d|_|jj|j�d|_t�j|�dS)N)	rJr<�CloseHandlerKrI�_unregisterrrr@)rr?)rrrr@�s
	z%_WaitHandleFuture._unregister_wait_cbcCs�|js
dSd|_|j}d|_ytj||j�WnZtk
r�}z>|jtjkrxd||d�}|jrh|j|d<|j	j
|�dSWYdd}~XnX|jj|j|j
�|_dS)NFz$Failed to unregister the wait handle)r#r$r%r&)r9r8r
ZUnregisterWaitExrJr(rArBrr)r*rI�_wait_cancelr@rK)rr;r+r,rrrrC�s$

z"_WaitHandleFuture._unregister_wait)r1r2r3rr@rCr5rr)rrrH�srHc@s<eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�ZeZ	dS)
�
PipeServerzXClass representing a pipe server.

    This is much like a bound, listening socket.
    cCs,||_tj�|_d|_d|_|jd�|_dS)NT)�_address�weakref�WeakSet�_free_instances�_pipe�_accept_pipe_future�_server_pipe_handle)rr rrrr�s

zPipeServer.__init__cCs|j|jd�}|_|S)NF)rUrW)r�tmprrr�_get_unconnected_pipe�sz PipeServer._get_unconnected_pipec	Csr|j�rdStjtjB}|r&|tjO}tj|j|tjtjBtj	Btj
tjtjtj
tj�}tj|�}|jj|�|S)N)�closedr<ZPIPE_ACCESS_DUPLEXZFILE_FLAG_OVERLAPPEDZFILE_FLAG_FIRST_PIPE_INSTANCEZCreateNamedPiperQZPIPE_TYPE_MESSAGEZPIPE_READMODE_MESSAGEZ	PIPE_WAITZPIPE_UNLIMITED_INSTANCESr	ZBUFSIZEZNMPWAIT_WAIT_FOREVER�NULL�
PipeHandlerT�add)r�first�flags�h�piperrrrWs


zPipeServer._server_pipe_handlecCs
|jdkS)N)rQ)rrrrrZszPipeServer.closedcCsV|jdk	r|jj�d|_|jdk	rRx|jD]}|j�q,Wd|_d|_|jj�dS)N)rVr'rQrT�closerU�clear)rrarrrrbs


zPipeServer.closeN)
r1r2r3r4rrYrWrZrb�__del__rrrrrP�s
rPc@seZdZdZdd�ZdS)�_WindowsSelectorEventLoopz'Windows version of selector event loop.cCstj�S)N)r	�
socketpair)rrrr�_socketpair+sz%_WindowsSelectorEventLoop._socketpairN)r1r2r3r4rgrrrrre(srecsPeZdZdZd
�fdd�	Zdd�Zedd��Zed	d
��Zeddd��Z	�Z
S)rz2Windows version of proactor event loop using IOCP.Ncs|dkrt�}t�j|�dS)N)rrr)rrL)rrrr2szProactorEventLoop.__init__cCstj�S)N)r	rf)rrrrrg7szProactorEventLoop._socketpairccs8|jj|�}|EdH}|�}|j||d|id�}||fS)N�addr)�extra)rI�connect_pipe�_make_duplex_pipe_transport)r�protocol_factoryr �fra�protocol�transrrr�create_pipe_connection:s
z(ProactorEventLoop.create_pipe_connectioncs.t���d�����fdd�	��j���gS)Ncsd}yj|rL|j�}�jj|��j�r2|j�dS��}�j||d�id��j�}|dkr`dS�jj|�}Wn�t	k
r�}zH|r�|j
�d	kr��jd||d��|j�n�jr�t
jd|dd�WYdd}~Xn2tjk
r�|r�|j�YnX|�_|j��dS)
Nrh)rirzPipe accept failed)r#r$razAccept pipe failed on pipe %rT)�exc_infor)r0rT�discardrZrbrkrYrI�accept_piper(�filenor*Z_debugrZwarningr�CancelledErrorrV�add_done_callback)rmrarnr+)r �loop_accept_piperlr�serverrrrwGs<

z>ProactorEventLoop.start_serving_pipe.<locals>.loop_accept_pipe)N)rPZ	call_soon)rrlr r)r rwrlrrxr�start_serving_pipeCs(
z$ProactorEventLoop.start_serving_pipec	ks�|j�}
t||||||||f|
|d�|	��}y|
EdHWn&tk
r`}z
|}
WYdd}~XnXd}
|
dk	r�|j�|j�EdH|
�|S)N)�waiterri)�
create_future�_WindowsSubprocessTransport�	ExceptionrbZ_wait)rrn�args�shell�stdin�stdout�stderr�bufsizeri�kwargsrzZtranspr+�errrrr�_make_subprocess_transportrs

z,ProactorEventLoop._make_subprocess_transport)N)N)r1r2r3r4rrgrrpryr�r5rr)rrr/s	/c@s�eZdZdZd1dd�Zdd�Zdd�Zd2d
d�Zdd
�Zd3dd�Z	d4dd�Z
dd�Zdd�Zdd�Z
edd��Zd5dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd6d)d*�Zd+d,�Zd-d.�Zd/d0�Zd	S)7rz#Proactor implementation using IOCP.���cCsDd|_g|_tjtjtd|�|_i|_tj	�|_
g|_tj	�|_dS)Nr)
r)�_resultsr
�CreateIoCompletionPort�INVALID_HANDLE_VALUEr[�_iocp�_cacherRrSr9�
_unregistered�_stopped_serving)rZconcurrencyrrrr�s
zIocpProactor.__init__cCsd|jjt|j�t|j�fS)Nz<%s overlapped#=%s result#=%s>)rr1�lenr�r�)rrrr�__repr__�szIocpProactor.__repr__cCs
||_dS)N)r))rrrrr�set_loop�szIocpProactor.set_loopNcCs |js|j|�|j}g|_|S)N)r�r=)r�timeoutrXrrr�select�s

zIocpProactor.selectcCs|jj�}|j|�|S)N)r)r{r/)r�valuer?rrr�_result�s

zIocpProactor._resultrcCsz|j|�tjt�}y4t|tj�r6|j|j�||�n|j|j�|�Wnt	k
rb|j
d�SXdd�}|j|||�S)N�cSsJy|j�Stk
rD}z |jtjkr2t|j��n�WYdd}~XnXdS)N)�	getresultr(rAr
�ERROR_NETNAME_DELETED�ConnectionResetErrorr~)ro�keyrr+rrr�finish_recv�sz&IocpProactor.recv.<locals>.finish_recv)�_register_with_iocpr
�
Overlappedr[�
isinstance�socketZWSARecvrtZReadFile�BrokenPipeErrorr��	_register)r�conn�nbytesr_rr�rrr�recv�s

	zIocpProactor.recvcCsZ|j|�tjt�}t|tj�r4|j|j�||�n|j|j�|�dd�}|j	|||�S)NcSsJy|j�Stk
rD}z |jtjkr2t|j��n�WYdd}~XnXdS)N)r�r(rAr
r�r�r~)ror�rr+rrr�finish_send�sz&IocpProactor.send.<locals>.finish_send)
r�r
r�r[r�r�ZWSASendrtZ	WriteFiler�)rr��bufr_rr�rrr�send�s

	zIocpProactor.sendcsz|j��|j�j��tjt�}|j�j��j����fdd�}tdd��}|j	|�|�}||��}t
j||jd�|S)NcsD|j�tjd�j��}�jtjtj|��j	�j
����j�fS)Nz@P)r��structZpackrt�
setsockoptr��
SOL_SOCKETr
ZSO_UPDATE_ACCEPT_CONTEXT�
settimeoutZ
gettimeoutZgetpeername)ror�rr�)r��listenerrr�
finish_accept�s
z*IocpProactor.accept.<locals>.finish_acceptcss4y|EdHWn tjk
r.|j��YnXdS)N)rrurb)r%r�rrr�accept_coro�s
z(IocpProactor.accept.<locals>.accept_coro)r)
r��_get_accept_socket�familyr
r�r[ZAcceptExrtrr�rZ
ensure_futurer))rr�rr�r�r%�coror)r�r�r�accept�s

		
zIocpProactor.acceptcs�|j��ytj�j��j�WnBtk
rb}z&|jtjkr@��j	�ddkrR�WYdd}~XnXtj
t�}|j�j�|��fdd�}|j
|�|�S)Nrrcs|j��jtjtjd��S)Nr)r�r�r�r�r
ZSO_UPDATE_CONNECT_CONTEXT)ror�r)r�rr�finish_connects
z,IocpProactor.connect.<locals>.finish_connect)r�r
Z	BindLocalrtr�r(rA�errnoZ	WSAEINVALZgetsocknamer�r[Z	ConnectExr�)rr�r �err�r)r�r�connect�s

zIocpProactor.connectcsJ|j��tjt�}|j�j��}|r0|j��S�fdd�}|j|�|�S)Ncs|j��S)N)r�)ror�r)rarr�finish_accept_pipesz4IocpProactor.accept_pipe.<locals>.finish_accept_pipe)r�r
r�r[ZConnectNamedPipertr�r�)rrarZ	connectedr�r)rarrs
s


zIocpProactor.accept_pipeccszt}xjytj|�}PWn0tk
rF}z|jtjkr6�WYdd}~XnXt|dt�}tj	||j
d�EdHqWtj|�S)N�)r)
�CONNECT_PIPE_INIT_DELAYr
ZConnectPiper(rAZERROR_PIPE_BUSY�min�CONNECT_PIPE_MAX_DELAYrZsleepr)r	r\)rr Zdelayr:r+rrrrjs
zIocpProactor.connect_pipecCs|j||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_handle/szIocpProactor.wait_for_handlecCs|j|dd�}||_|S)NT)r�rE)rrFZ
done_callbackr?rrrrO7szIocpProactor._wait_cancelcs�|dkrtj}ntj|d�}tjt�}tj||j|j	|�}|rTt
||||jd��nt|||||jd���j
rv�j
d=�fdd�}�|d|f|j|j	<�S)Ng@�@)rrcs�j�S)N)r=)ror�r)rmrr�finish_wait_for_handleRsz=IocpProactor._wait_for_handle.<locals>.finish_wait_for_handlerr)r<�INFINITE�math�ceilr
r�r[ZRegisterWaitWithQueuer�r rDr)rHrr�)rr:r�Z
_is_cancel�msrr;r�r)rmrr�>s


	zIocpProactor._wait_for_handlecCs0||jkr,|jj|�tj|j�|jdd�dS)Nr)r9r]r
r�rtr�)r�objrrrr�^s
z IocpProactor._register_with_iocpcCs�t||jd�}|jr|jd=|jsjy|dd|�}Wn,tk
r^}z|j|�WYdd}~XnX|j|�||||f|j|j<|S)N)rrr)	rr)rrr(r.r/r�r )rrr��callbackrmr�r�rrrr�hs

zIocpProactor._registercCs|jj|�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>)rrrrrrN�szIocpProactor._unregistercCstj|�}|jd�|S)Nr)r�r�)rr��srrrr��s

zIocpProactor._get_accept_socketcCs�|dkrt}n0|dkr td��ntj|d�}|tkr>td���xtj|j|�}|dkrZPd}|\}}}}y|jj|�\}}	}
}WnVt	k
r�|j
j�r�|j
jdd||||fd��|dtj
fkr�tj|�wBYnX|
|jkr�|j�qB|j�sBy||||	�}Wn:tk
�r@}
z|j|
�|jj|�WYdd}
~
XqBX|j|�|jj|�qBWx |jD]}	|jj|	jd��qdW|jj�dS)Nrznegative timeoutg@�@ztimeout too bigz8GetQueuedCompletionStatus() returned an unexpected eventz)err=%s transferred=%s key=%#x address=%#x)r#�status)r��
ValueErrorr�r�r
ZGetQueuedCompletionStatusr�r��pop�KeyErrorr)Z	get_debugr*r�r<rMr�r'�doner(r.r�r>r/r�r rc)rr�r�r�r�Ztransferredr�r rmrr�r�r�r�rrrr=�sJ






zIocpProactor._pollcCs|jj|�dS)N)r�r])rr�rrr�
_stop_serving�szIocpProactor._stop_servingcCs�x�t|jj��D]�\}\}}}}|j�r*qt|t�r6qy|j�Wqtk
r�}z8|jdk	r�d||d�}|j	rz|j	|d<|jj
|�WYdd}~XqXqWx|jr�|jd�s�tj
d�q�Wg|_|jdk	r�tj|j�d|_dS)NzCancelling a future failed)r#r$r%r&rz"taking long time to close proactor)�listr��itemsZ	cancelledr�rDr'r(r)rr*r=r�debugr�r�r<rM)rr r?rr�r�r+r,rrrrb�s, 


"

zIocpProactor.closecCs|j�dS)N)rb)rrrrrd�szIocpProactor.__del__)r�)N)r)r)N)N)r1r2r3r4rr�r�r�r�r�r�r�r�rsrrjr�rOr�r�r�rNr�r=r�rbrdrrrrr�s.





 
	
7 c@seZdZdd�ZdS)r|c
sPtj|f|||||d�|���_�fdd�}�jjjt�jj��}	|	j|�dS)N)rr�r�r�r�cs�jj�}�j|�dS)N)�_procZpollZ_process_exited)rm�
returncode)rrrr��s
z4_WindowsSubprocessTransport._start.<locals>.callback)	r	�Popenr�r)rIr��intr7rv)
rr~rr�r�r�r�r�r�rmr)rr�_start�sz"_WindowsSubprocessTransport._startN)r1r2r3r�rrrrr|�sr|c@seZdZeZdS)�_WindowsDefaultEventLoopPolicyN)r1r2r3r
Z
_loop_factoryrrrrr�sr�)-r4r<r�r�r�r�rR�rrrrrrr	r
Z
coroutinesr�logr�__all__r[r�ZERROR_CONNECTION_REFUSEDZERROR_CONNECTION_ABORTEDr�r�ZFuturerr6rDrH�objectrPZBaseSelectorEventLoopreZBaseProactorEventLooprrZBaseSubprocessTransportr|r
ZBaseDefaultEventLoopPolicyr�rrrrr�<module>sL0J4;]k

Hacked By AnonymousFox1.0, Coded By AnonymousFox