Your IP : 18.191.171.43


Current Path : /opt/alt/python35/lib64/python3.5/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/asyncio/__pycache__/windows_events.cpython-35.opt-1.pyc



��Yf.l�@sdZddlZddlZddlZddlZddlZddlZddlmZddlm	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	�S)�_OverlappedFuturez�Subclass of Future which represents an overlapped operation.

    Cancelling it will immediately cancel the overlapped operation.
    �loopNcs3t�jd|�|jr&|jd=||_dS)Nrr���)�super�__init__�_source_traceback�_ov)�self�ovr)�	__class__��;/opt/alt/python35/lib64/python3.5/asyncio/windows_events.pyr-s	
z_OverlappedFuture.__init__csZt�j�}|jdk	rV|jjr0dnd}|jdd||jjf�|S)N�pendingZ	completedrzoverlapped=<%s, %#x>)r�
_repr_inforr�insert�address)r�info�state)rrrr3s
 z_OverlappedFuture._repr_infocCs�|jdkrdSy|jj�Wnctk
r�}zCddd|d|i}|jrg|j|d<|jj|�WYdd}~XnXd|_dS)N�messagez&Cancelling an overlapped future failed�	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'Js
z_OverlappedFuture.cancelcst�j|�|j�dS)N)r�
set_exceptionr-)rr$)rrrr.Nsz_OverlappedFuture.set_exceptioncst�j|�d|_dS)N)r�
set_resultr)r�result)rrrr/Rsz_OverlappedFuture.set_result)
�__name__�
__module__�__qualname__�__doc__rrr-r'r.r/rr)rrr'srcs�eZdZdZdd�fdd�Zdd�Z�fdd	�Zd
d�Zdd
�Z�fdd�Z	�fdd�Z
�fdd�Z�S)�_BaseWaitHandleFuturez2Subclass of Future which represents a wait handle.rNcsNt�jd|�|jr&|jd=||_||_||_d|_dS)NrrTr)rrrr�_handle�_wait_handle�_registered)rr�handle�wait_handler)rrrrZs	
			z_BaseWaitHandleFuture.__init__cCstj|jd�tjkS)Nr)�_winapiZWaitForSingleObjectr6Z
WAIT_OBJECT_0)rrrr�_pollhsz_BaseWaitHandleFuture._pollcs~t�j�}|jd|j�|jdk	rW|j�rDdnd}|j|�|jdk	rz|jd|j�|S)Nz
handle=%#xZsignaledZwaitingzwait_handle=%#x)rr�appendr6r<r7)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|�Wnytk
r�}zY|jtjkr�ddd|d|i}|jr�|j|d<|jj	|�dSWYdd}~XnX|j
d�dS)NFr#z$Failed to unregister the wait handler$r%r&)r8r7r
ZUnregisterWaitr(�winerror�ERROR_IO_PENDINGrr)r*r?)rr:r+r,rrr�_unregister_wait|s"					
z&_BaseWaitHandleFuture._unregister_waitcs|j�t�j�S)N)rBrr')r)rrrr'�s
z_BaseWaitHandleFuture.cancelcs|j�t�j|�dS)N)rBrr.)rr$)rrrr.�s
z#_BaseWaitHandleFuture.set_exceptioncs|j�t�j|�dS)N)rBrr/)rr0)rrrr/�s
z _BaseWaitHandleFuture.set_result)r1r2r3r4rr<rr?rBr'r.r/rr)rrr5Ws
r5csLeZdZdZdd�fdd�Zdd�Z�fdd	�Z�S)
�_WaitCancelFuturezoSubclass of Future which represents a wait for the cancellation of a
    _WaitHandleFuture using an event.
    rNcs)t�j|||d|�d|_dS)Nr)rr�_done_callback)rr�eventr:r)rrrr�sz_WaitCancelFuture.__init__cCstd��dS)Nz'_WaitCancelFuture must not be cancelled)�RuntimeError)rrrrr'�sz_WaitCancelFuture.cancelcs3tt|�j�|jdk	r/|j|�dS)N)rrC�_schedule_callbacksrD)r)rrrrG�sz%_WaitCancelFuture._schedule_callbacks)r1r2r3r4rr'rGrr)rrrC�srCcsFeZdZdd�fdd�Z�fdd�Zdd�Z�S)	�_WaitHandleFuturerNcsVt�j|||d|�||_d|_tjdddd�|_d|_dS)NrTF)rr�	_proactorZ_unregister_proactorr
ZCreateEvent�_event�
_event_fut)rrr9r:�proactorr)rrrr�s
		z_WaitHandleFuture.__init__csa|jdk	r1tj|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�Wnytk
r�}zY|jtjkr�ddd|d|i}|jr�|j|d<|j	j
|�dSWYdd}~XnX|jj|j|j
�|_dS)NFr#z$Failed to unregister the wait handler$r%r&)r8r7r
ZUnregisterWaitExrJr(r@rArr)r*rI�_wait_cancelr?rK)rr:r+r,rrrrB�s$					
z"_WaitHandleFuture._unregister_wait)r1r2r3rr?rBrr)rrrH�srHc@sXeZdZdZdd�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	Cs�|j�rdStjtjB}|r3|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�piperrrrW�s
	
zPipeServer._server_pipe_handlecCs
|jdkS)N)rQ)rrrrrZszPipeServer.closedcCsu|jdk	r%|jj�d|_|jdk	rqx|jD]}|j�q>Wd|_d|_|jj�dS)N)rVr'rQrT�closerU�clear)rrarrrrbs
			zPipeServer.closeN)
r1r2r3r4rrYrWrZrb�__del__rrrrrP�s
rPc@s"eZdZdZdd�ZdS)�_WindowsSelectorEventLoopz'Windows version of selector event loop.cCs
tj�S)N)r	�
socketpair)rrrr�_socketpair&sz%_WindowsSelectorEventLoop._socketpairN)r1r2r3r4rgrrrrre#srecspeZdZdZd�fdd�Zdd�Zedd��Zed	d
��Zeddd��Z	�S)
rz2Windows version of proactor event loop using IOCP.Ncs)|dkrt�}t�j|�dS)N)rrr)rrL)rrrr-s	zProactorEventLoop.__init__cCs
tj�S)N)r	rf)rrrrrg2szProactorEventLoop._socketpairccsN|jj|�}|EdH}|�}|j||dd|i�}||fS)N�extra�addr)rI�connect_pipe�_make_duplex_pipe_transport)r�protocol_factoryr �fra�protocol�transrrr�create_pipe_connection5s	z(ProactorEventLoop.create_pipe_connectioncsAt���d�����fdd���j���gS)Ncsbd}y�|rj|j�}�jj|��j�rE|j�dS��}�j||dd�i��j�}|dkr�dS�jj|�}Wn�t	k
r#}zh|r�|j
�dkr��jddd|d|i�|j�n�jrt
jd|d	d
�WYdd}~Xn;tjk
rG|rC|j�YnX|�_|j��dS)Nrhrirr#zPipe accept failedr$razAccept pipe failed on pipe %r�exc_infoTr)r0rT�discardrZrbrkrYrI�accept_piper(�filenor*Z_debugrZwarningr�CancelledErrorrV�add_done_callback)rmrarnr+)r �loop_accept_piperlr�serverrrrwBs<
	

			z>ProactorEventLoop.start_serving_pipe.<locals>.loop_accept_pipe)rPZ	call_soon)rrlr r)r rwrlrrxr�start_serving_pipe>s!(
z$ProactorEventLoop.start_serving_pipec	ks�|j�}
t||||||||d|
d||	�}y
|
EdHWn+tk
rv}z|}
WYdd}~XnXd}
|
dk	r�|j�|j�EdH|
�|S)N�waiterrh)�
create_future�_WindowsSubprocessTransport�	ExceptionrbZ_wait)rrn�args�shell�stdin�stdout�stderr�bufsizerh�kwargsrzZtranspr+�errrrr�_make_subprocess_transportms		

z,ProactorEventLoop._make_subprocess_transport)
r1r2r3r4rrgrrpryr�rr)rrr*s	/c@s6eZdZdZddd�Zdd�Zdd�Zd	d
d�Zdd
�Zddd�Z	ddd�Z
dd�Zdd�Zdd�Z
edd��Zd	dd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd	d)d*�Zd+d,�Zd-d.�Zd/d0�Zd	S)1rz#Proactor implementation using IOCP.l��cCsdd|_g|_tjtjtd|�|_i|_tj	�|_
g|_tj	�|_dS)Nr)
r)�_resultsr
�CreateIoCompletionPort�INVALID_HANDLE_VALUEr[�_iocp�_cacherRrSr8�
_unregistered�_stopped_serving)rZconcurrencyrrrr�s				zIocpProactor.__init__cCs)d|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Cs�|j|�tjt�}yHt|tj�rM|j|j�||�n|j|j�|�Wnt	k
r�|j
d�SYnXdd�}|j|||�S)N�cSsay|j�SWnLtk
r\}z,|jtjkrGt|j��n�WYdd}~XnXdS)N)�	getresultr(r@r
�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.recvcCs|j|�tjt�}t|tj�rJ|j|j�||�n|j|j�|�dd�}|j	|||�S)NcSsay|j�SWnLtk
r\}z,|jtjkrGt|j��n�WYdd}~XnXdS)N)r�r(r@r
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.sendcs�|j��|j�j��tjt�}|j�j��j����fdd�}tdd��}|j	|�|�}||��}t
j|d|j�|S)Ncs^|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_acceptcss6y
|EdHWn"tjk
r1|j��YnXdS)N)rrurb)r%r�rrr�accept_coro�s


z(IocpProactor.accept.<locals>.accept_coror)
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�WnStk
r}z3|jtjkrT��j	�ddkrm�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_connect�s

z,IocpProactor.connect.<locals>.finish_connect)r�r
Z	BindLocalrtr�r(r@�errnoZ	WSAEINVALZgetsocknamer�r[Z	ConnectExr�)rr�r �err�r)r�r�connect�s
zIocpProactor.connectcsi|j��tjt�}|j�j��}|rD|j��S�fdd�}|j|�|�S)Ncs|j��S)N)r�)ror�r)rarr�finish_accept_pipes
z4IocpProactor.accept_pipe.<locals>.finish_accept_pipe)r�r
r�r[ZConnectNamedPipertr�r�)rrarZ	connectedr�r)rarrss

zIocpProactor.accept_pipeccs�t}x�ytj|�}PWn:tk
rY}z|jtjkrG�WYdd}~XnXt|dt�}tj	|d|j
�EdHq	Wtj|�S)N�r)
�CONNECT_PIPE_INIT_DELAYr
ZConnectPiper(r@ZERROR_PIPE_BUSY�min�CONNECT_PIPE_MAX_DELAYrZsleepr)r	r\)rr Zdelayr9r+rrrrjszIocpProactor.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)rr9r�rrr�wait_for_handle*szIocpProactor.wait_for_handlecCs"|j|dd�}||_|S)NT)r�rD)rrEZ
done_callbackr>rrrrO2s	zIocpProactor._wait_cancelcs�|dkrtj}ntj|d�}tjt�}tj||j|j	|�}|r|t
|||d|j��nt||||d|j���j
r��j
d=�fdd�}�|d|f|j|j	<�S)Ng@�@rrcs
�j�S)N)r<)ror�r)rmrr�finish_wait_for_handleMsz=IocpProactor._wait_for_handle.<locals>.finish_wait_for_handlerr)r;�INFINITE�math�ceilr
r�r[ZRegisterWaitWithQueuer�r rCr)rHrr�)rr9r�Z
_is_cancel�msrr:r�r)rmrr�9s	
	zIocpProactor._wait_for_handlecCsB||jkr>|jj|�tj|j�|jdd�dS)Nr)r8r]r
r�rtr�)r�objrrrr�Ysz IocpProactor._register_with_iocpcCs�t|d|j�}|jr(|jd=|js�y|dd|�}Wn2tk
r{}z|j|�WYdd}~XnX|j|�||||f|j|j<|S)Nrrr)	rr)rrr(r.r/r�r )rrr��callbackrmr�r�rrrr�cs	
	 
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._unregistercCs tj|�}|jd�|S)Nr)r�r�)rr��srrrr��s
zIocpProactor._get_accept_socketcCs|dkrt}nF|dkr0td��n+tj|d�}|tkr[td��xutj|j|�}|dkr�Pd}|\}}}}y"|jj|�\}}	}
}Wnrt	k
r.|j
j�r|j
jdddd||||fi�|dtj
fkr'tj|�w^YnX|
|jkrK|j�q^|j�s^y||||	�}WnBtk
r�}
z"|j|
�|jj|�WYdd}
~
Xq^X|j|�|jj|�q^Wx'|jD]}	|jj|	jd�q�W|jj�dS)	Nrznegative timeoutg@�@ztimeout too bigr#z8GetQueuedCompletionStatus() returned an unexpected event�statusz)err=%s transferred=%s key=%#x address=%#x)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_servingcCs7x�t|jj��D]�\}\}}}}|j�r=qt|t�rOqy|j�Wqtk
r�}zR|jdk	r�ddd|d|i}|j	r�|j	|d<|jj
|�WYdd}~XqXqWx)|jr|jd�s�tj
d�q�Wg|_|jdk	r3tj|j�d|_dS)Nr#zCancelling a future failedr$r%r&rz"taking long time to close proactor)�listr��itemsZ	cancelledr�rCr'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__)r1r2r3r4rr�r�r�r�r�r�r�r�rsrrjr�rOr�r�r�rNr�r<r�rbrdrrrrr�s.
 
	7 c@seZdZdd�ZdS)r|c

swtj|d|d|d|d|d||��_�fdd�}�jjjt�jj��}	|	j|�dS)Nrr�r�r�r�cs �jj�}�j|�dS)N)�_procZpollZ_process_exited)rm�
returncode)rrrr��sz4_WindowsSubprocessTransport._start.<locals>.callback)	r	�Popenr�r)rIr��intr6rv)
rr~rr�r�r�r�r�r�rmr)rr�_start�s!z"_WindowsSubprocessTransport._startN)r1r2r3r�rrrrr|�sr|c@seZdZeZdS)�_WindowsDefaultEventLoopPolicyN)r1r2r3r
Z
_loop_factoryrrrrr�sr�)-r4r;r�r�r�r�rR�rrrrrrr	r
Z
coroutinesr�logr�__all__r[r�ZERROR_CONNECTION_REFUSEDZERROR_CONNECTION_ABORTEDr�r�ZFuturerr5rCrH�objectrPZBaseSelectorEventLoopreZBaseProactorEventLooprrZBaseSubprocessTransportr|r
ZBaseDefaultEventLoopPolicyr�rrrrr�<module>sJ		0J4;]�j

?>