Your IP : 3.22.42.25


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-2.pyc



���].l�@sddlZddlZddlZddlZddlZddlZddlmZddlmZddlm	Z	ddlm
Z
ddlmZddlmZdd	lm
Z
dd
lmZddlmZddlmZd
dddgZdZdZdZdZdZdZGdd�de	j�ZGdd�de	j�ZGdd�de�ZGdd�de�ZGdd�de�Z Gd d!�d!ej!�Z"Gd"d�de
j#�Z$Gd#d�d�Z%Gd$d%�d%ej&�Z'e"Z(Gd&d'�d'ej)�Z*e*Z+dS)(�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|eZdZdd�fdd�Z�fdd�Zdd�Z�fd	d
�Z�fdd�Z�fd
d�Z�S)�_OverlappedFuture�loopNcs3t�jd|�|jr&|jd=||_dS)Nrr���)�super�__init__�_source_traceback�_ov)�self�ovr)�	__class__��3/opt/alt/python35/lib64/python3.5/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__rrr-r'r.r/rr)rrr'srcs�eZdZdd�fdd�Zdd�Z�fdd�Zd	d
�Zdd�Z�fd
d�Z�fdd�Z	�fdd�Z
�S)�_BaseWaitHandleFuturerNcsNt�jd|�|jr&|jd=||_||_||_d|_dS)NrrTr)rrrr�_handle�_wait_handle�_registered)rr�handle�wait_handler)rrrrZs	
			z_BaseWaitHandleFuture.__init__cCstj|jd�tjkS)Nr)�_winapiZWaitForSingleObjectr5Z
WAIT_OBJECT_0)rrrr�_pollhsz_BaseWaitHandleFuture._pollcs~t�j�}|jd|j�|jdk	rW|j�rDdnd}|j|�|jdk	rz|jd|j�|S)Nz
handle=%#x�signaledZwaitingzwait_handle=%#x)rr�appendr5r;r6)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&)r7r6r
ZUnregisterWaitr(�winerror�ERROR_IO_PENDINGrr)r*r?)rr9r+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)r1r2r3rr;rr?rBr'r.r/rr)rrr4Ws
r4csFeZdZdd�fdd�Zdd�Z�fdd�Z�S)	�_WaitCancelFuturerNcs)t�j|||d|�d|_dS)Nr)rr�_done_callback)rr�eventr9r)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)r1r2r3rr'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)rrr8r9�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&)r7r6r
ZUnregisterWaitExrJr(r@rArr)r*rI�_wait_cancelr?rK)rr9r+r,rrrrB�s$					
z"_WaitHandleFuture._unregister_wait)r1r2r3rr?rBrr)rrrH�srHc@sReZdZdd�Zdd�Zdd�Zdd�Zd	d
�ZeZdS)�
PipeServercCs@||_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	�BUFSIZEZNMPWAIT_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)rrbrrrrcs
			zPipeServer.closeN)	r1r2r3rrYrWrZrc�__del__rrrrrP�s
rPc@seZdZdd�ZdS)�_WindowsSelectorEventLoopcCs
tj�S)N)r	�
socketpair)rrrr�_socketpair&sz%_WindowsSelectorEventLoop._socketpairN)r1r2r3rhrrrrrf#srfcsjeZdZd�fdd�Zdd�Zedd��Zedd	��Zedd
d��Z�S)rNcs)|dkrt�}t�j|�dS)N)rrr)rrL)rrrr-s	zProactorEventLoop.__init__cCs
tj�S)N)r	rg)rrrrrh2szProactorEventLoop._socketpairccsN|jj|�}|EdH}|�}|j||dd|i�}||fS)N�extra�addr)rI�connect_pipe�_make_duplex_pipe_transport)r�protocol_factoryr �frb�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)Nrirjrr#zPipe accept failedr$rbzAccept pipe failed on pipe %r�exc_infoTr)r0rT�discardrZrcrlrYrI�accept_piper(�filenor*Z_debugr�warningr�CancelledErrorrV�add_done_callback)rnrbror+)r �loop_accept_pipermr�serverrrryBs<
	

			z>ProactorEventLoop.start_serving_pipe.<locals>.loop_accept_pipe)rPZ	call_soon)rrmr r)r ryrmrrzr�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�waiterri)�
create_future�_WindowsSubprocessTransport�	Exceptionrc�_wait)rro�args�shell�stdin�stdout�stderr�bufsizeri�kwargsr|Ztranspr+�errrrr�_make_subprocess_transportms		

z,ProactorEventLoop._make_subprocess_transport)	r1r2r3rrhrrqr{r�rr)rrr*s	/c@s0eZdZddd�Zdd�Zdd�Zdd	d
�Zdd�Zd
dd�Zd
dd�Z	dd�Z
dd�Zdd�Ze
dd��Zddd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zdd(d)�Zd*d+�Zd,d-�Zd.d/�ZdS)0rl��cCsdd|_g|_tjtjtd|�|_i|_tj	�|_
g|_tj	�|_dS)Nr)
r)�_resultsr
�CreateIoCompletionPort�INVALID_HANDLE_VALUEr\�_iocp�_cacherRrSr7�
_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�)rp�keyrr+rrr�finish_recv�sz&IocpProactor.recv.<locals>.finish_recv)�_register_with_iocpr
�
Overlappedr\�
isinstance�socketZWSARecvruZReadFile�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�)rpr�rr+rrr�finish_send�sz&IocpProactor.send.<locals>.finish_send)
r�r
r�r\r�r�ZWSASendruZ	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��struct�packru�
setsockoptr��
SOL_SOCKETr
ZSO_UPDATE_ACCEPT_CONTEXT�
settimeout�
gettimeout�getpeername)rpr�rr�)r��listenerrr�
finish_accept�s

z*IocpProactor.accept.<locals>.finish_acceptcss6y
|EdHWn"tjk
r1|j��YnXdS)N)rrwrc)r%r�rrr�accept_coro�s


z(IocpProactor.accept.<locals>.accept_coror)
r��_get_accept_socket�familyr
r�r\ZAcceptExrurr�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)rpr�r)r�rr�finish_connect�s

z,IocpProactor.connect.<locals>.finish_connect)r�r
Z	BindLocalrur�r(r@�errnoZ	WSAEINVAL�getsocknamer�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�)rpr�r)rbrr�finish_accept_pipes
z4IocpProactor.accept_pipe.<locals>.finish_accept_pipe)r�r
r�r\ZConnectNamedPiperur�r�)rrbrZ	connectedr�r)rbrrts

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_DELAYr�sleepr)r	r])rr �delayr8r+rrrrkszIocpProactor.connect_pipecCs|j||d�S)NF)�_wait_for_handle)rr8r�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;)rpr�r)rnrr�finish_wait_for_handleMsz=IocpProactor._wait_for_handle.<locals>.finish_wait_for_handlerr)r:�INFINITE�math�ceilr
r�r\ZRegisterWaitWithQueuer�r rCr)rHrr�)rr8r�Z
_is_cancel�msrr9r�r)rnrr�9s	
	zIocpProactor._wait_for_handlecCsB||jkr>|jj|�tj|j�|jdd�dS)Nr)r7r^r
r�rur�)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��callbackrnr�r�rrrr�cs	
	 
zIocpProactor._registercCs|jj|�dS)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 rd)rr�r�r�r�Ztransferredr�r rnrr�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��items�	cancelledr�rCr'r(r)rr*r;r�debugr�r�r:rM)rr r>rr�r�r+r,rrrrc�s,.	
'	zIocpProactor.closecCs|j�dS)N)rc)rrrrre�szIocpProactor.__del__)r1r2r3rr�r�r�r�r�r�r�r�rtrrkr�rOr�r�r�rNr�r;r�rcrerrrrr�s,
 
	7 c@seZdZdd�ZdS)r~c

swtj|d|d|d|d|d||��_�fdd�}�jjjt�jj��}	|	j|�dS)Nr�r�r�r�r�cs �jj�}�j|�dS)N)�_proc�pollZ_process_exited)rn�
returncode)rrrr��sz4_WindowsSubprocessTransport._start.<locals>.callback)	r	�Popenr�r)rIr��intr5rx)
rr�r�r�r�r�r�r�r�rnr)rr�_start�s!z"_WindowsSubprocessTransport._startN)r1r2r3r�rrrrr~�sr~c@seZdZeZdS)�_WindowsDefaultEventLoopPolicyN)r1r2r3r
Z
_loop_factoryrrrrr�sr�),r:r�r�r�r�rR�rrrrrrr	r
Z
coroutinesr�logr�__all__r\r�ZERROR_CONNECTION_REFUSEDZERROR_CONNECTION_ABORTEDr�r��Futurerr4rCrH�objectrPZBaseSelectorEventLooprfZBaseProactorEventLooprrZBaseSubprocessTransportr~r
ZBaseDefaultEventLoopPolicyr�rrrrr�<module>sH		0J4;]�j

?>