Your IP : 3.21.244.34


Current Path : /opt/alt/python38/lib64/python3.8/asyncio/__pycache__/
Upload File :
Current File : //opt/alt/python38/lib64/python3.8/asyncio/__pycache__/selector_events.cpython-38.pyc

U

i�fT��@s.dZdZddlZddlZddlZddlZddlZddlZddlZzddl	Z	Wne
k
rddZ	YnXddlmZddlm
Z
ddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZdd�Zdd�ZGdd�dej�ZGdd�dejej�ZGdd�de�ZGdd�de�ZdS)z�Event loop using a selector and related classes.

A selector is a "notify-when-ready" multiplexer.  For a subclass which
also includes support for signal handling, see the unix_events sub-module.
)�BaseSelectorEventLoop�N�)�base_events)�	constants)�events)�futures)�	protocols)�sslproto)�
transports)�trsock)�loggercCs8z|�|�}Wntk
r$YdSXt|j|@�SdS�NF)�get_key�KeyError�boolr)�selector�fdZevent�key�r�</opt/alt/python38/lib64/python3.8/asyncio/selector_events.py�_test_selector_event s
rcCs tdk	rt|tj�rtd��dS)Nz"Socket cannot be of type SSLSocket)�ssl�
isinstanceZ	SSLSocket�	TypeError)�sockrrr�_check_ssl_socket+srcs�eZdZdZdS�fdd�	ZdTddd�dd�ZdUddddejd	�d
d�ZdVdd
�Z	�fdd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdddejfdd�Zdddejfdd�Zddejfdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�Zd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+�Z,S)WrzJSelector event loop.

    See events.EventLoop for API specification.
    NcsFt���|dkrt��}t�d|jj�||_|�	�t
��|_dS)NzUsing selector: %s)
�super�__init__�	selectorsZDefaultSelectorr�debug�	__class__�__name__�	_selector�_make_self_pipe�weakrefZWeakValueDictionary�_transports)�selfr�r rrr6s
zBaseSelectorEventLoop.__init__��extra�servercCst||||||�S�N)�_SelectorSocketTransport)r&r�protocol�waiterr)r*rrr�_make_socket_transport@s
�z,BaseSelectorEventLoop._make_socket_transportF)�server_side�server_hostnamer)r*�ssl_handshake_timeoutc	Cs0tj|||||||	d�}
t|||
||d�|
jS)N)r2r()r	ZSSLProtocolr,Z_app_transport)r&Zrawsockr-�
sslcontextr.r0r1r)r*r2Zssl_protocolrrr�_make_ssl_transportEs��z)BaseSelectorEventLoop._make_ssl_transportcCst||||||�Sr+)�_SelectorDatagramTransport)r&rr-�addressr.r)rrr�_make_datagram_transportRs
�z.BaseSelectorEventLoop._make_datagram_transportcsL|��rtd��|��rdS|��t���|jdk	rH|j��d|_dS)Nz!Cannot close a running event loop)Z
is_running�RuntimeError�	is_closed�_close_self_piper�closer"�r&r'rrr;Ws


zBaseSelectorEventLoop.closecCsB|�|j���|j��d|_|j��d|_|jd8_dS)Nr)�_remove_reader�_ssock�filenor;�_csock�
_internal_fdsr<rrrr:bs

z&BaseSelectorEventLoop._close_self_pipecCsNt��\|_|_|j�d�|j�d�|jd7_|�|j��|j�dS)NFr)	�socketZ
socketpairr>r@�setblockingrA�_add_readerr?�_read_from_selfr<rrrr#js
z%BaseSelectorEventLoop._make_self_pipecCsdSr+r�r&�datarrr�_process_self_datarsz(BaseSelectorEventLoop._process_self_datacCsXz"|j�d�}|sWqT|�|�Wqtk
r:YqYqtk
rPYqTYqXqdS)Ni)r>�recvrH�InterruptedError�BlockingIOErrorrFrrrrEusz%BaseSelectorEventLoop._read_from_selfcCsN|j}|dkrdSz|�d�Wn(tk
rH|jrDtjddd�YnXdS)N�z3Fail to write a null byte into the self-pipe socketT��exc_info)r@�send�OSError�_debugrr)r&Zcsockrrr�_write_to_self�s�z$BaseSelectorEventLoop._write_to_self�dc
Cs"|�|��|j||||||�dSr+)rDr?�_accept_connection)r&�protocol_factoryrr3r*�backlogr2rrr�_start_serving�s�z$BaseSelectorEventLoop._start_servingc
Cst|�D]�}z0|��\}}	|jr0t�d||	|�|�d�Wn�tttfk
rZYdSt	k
r�}
zd|
j
t
jt
jt
j
t
jfkr�|�d|
t�|�d��|�|���|�tj|j||||||�n�W5d}
~
XYqXd|	i}|�||||||�}|�|�qdS)Nz#%r got a new connection from %r: %rFz&socket.accept() out of system resource)�message�	exceptionrB�peername)�range�acceptrQrrrCrKrJ�ConnectionAbortedErrorrP�errnoZEMFILEZENFILEZENOBUFSZENOMEM�call_exception_handlerr�TransportSocketr=r?Z
call_laterrZACCEPT_RETRY_DELAYrW�_accept_connection2Zcreate_task)
r&rUrr3r*rVr2�_�conn�addr�excr)r\rrrrT�sV�����z(BaseSelectorEventLoop._accept_connectionc
�s�d}d}zt|�}|��}	|r8|j||||	d|||d�}n|j|||	||d�}z|	IdHWntk
rx|���YnXWntttfk
r��Yn\tk
r�}
z>|jr�d|
d�}|dk	r�||d<|dk	r�||d<|�|�W5d}
~
XYnXdS)NT)r.r0r)r*r2)r.r)r*z3Error on transport creation for incoming connection)rXrYr-�	transport)	�
create_futurer4r/�
BaseExceptionr;�
SystemExit�KeyboardInterruptrQr_)r&rUrcr)r3r*r2r-rfr.re�contextrrrra�sP���z)BaseSelectorEventLoop._accept_connection2c
Cs�|}t|t�sJzt|���}Wn*tttfk
rHtd|���d�YnXz|j|}Wntk
rlYnX|��s�t	d|�d|����dS)NzInvalid file object: zFile descriptor z is used by transport )
r�intr?�AttributeErrorr�
ValueErrorr%r�
is_closingr8)r&rr?rfrrr�_ensure_fd_no_transport�s
�z-BaseSelectorEventLoop._ensure_fd_no_transportc		Gs�|��t�|||d�}z|j�|�}Wn*tk
rR|j�|tj|df�Yn>X|j|j	}\}}|j�
||tjB||f�|dk	r�|��dSr+)�
_check_closedr�Handler"rr�registerr�
EVENT_READrG�modify�cancel�	r&r�callback�argsZhandler�mask�reader�writerrrrrDs�
�z!BaseSelectorEventLoop._add_readercCs�|��rdSz|j�|�}Wntk
r2YdSX|j|j}\}}|tjM}|sd|j�|�n|j�	||d|f�|dk	r�|�
�dSdSdS�NFT)r9r"rrrrGrrt�
unregisterrurv�r&rrrzr{r|rrrr=sz$BaseSelectorEventLoop._remove_readerc		Gs�|��t�|||d�}z|j�|�}Wn*tk
rR|j�|tjd|f�Yn>X|j|j	}\}}|j�
||tjB||f�|dk	r�|��dSr+)rqrrrr"rrrsr�EVENT_WRITErGrurvrwrrr�_add_writer%s�
�z!BaseSelectorEventLoop._add_writercCs�|��rdSz|j�|�}Wntk
r2YdSX|j|j}\}}|tjM}|sd|j�|�n|j�	|||df�|dk	r�|�
�dSdSdS)�Remove a writer callback.FNT)r9r"rrrrGrr�r~rurvrrrr�_remove_writer4sz$BaseSelectorEventLoop._remove_writercGs|�|�|j||f|��S)zAdd a reader callback.)rprD�r&rrxryrrr�
add_readerKs
z BaseSelectorEventLoop.add_readercCs|�|�|�|�S)zRemove a reader callback.)rpr=�r&rrrr�
remove_readerPs
z#BaseSelectorEventLoop.remove_readercGs|�|�|j||f|��S)zAdd a writer callback..)rpr�r�rrr�
add_writerUs
z BaseSelectorEventLoop.add_writercCs|�|�|�|�S)r�)rpr�r�rrr�
remove_writerZs
z#BaseSelectorEventLoop.remove_writerc	�s�t|�|jr"|��dkr"td��z|�|�WSttfk
rFYnX|��}|��}|�	||j
|||�|�t�
|j|��|IdHS)z�Receive data from the socket.

        The return value is a bytes object representing the data received.
        The maximum amount of data to be received at once is specified by
        nbytes.
        r�the socket must be non-blockingN)rrQ�
gettimeoutrnrIrKrJrgr?r��
_sock_recv�add_done_callback�	functools�partial�_sock_read_done)r&r�n�futrrrr�	sock_recv_s�zBaseSelectorEventLoop.sock_recvcCs|�|�dSr+)r��r&rr�rrrr�tsz%BaseSelectorEventLoop._sock_read_donec
Cs�|��rdSz|�|�}Wn\ttfk
r4YdSttfk
rL�Yn6tk
rv}z|�|�W5d}~XYnX|�|�dSr+)	�donerIrKrJrirjrh�
set_exception�
set_result)r&r�rr�rGrerrrr�wsz BaseSelectorEventLoop._sock_recvc	�s�t|�|jr"|��dkr"td��z|�|�WSttfk
rFYnX|��}|��}|�	||j
|||�|�t�
|j|��|IdHS)z�Receive data from the socket.

        The received data is written into *buf* (a writable buffer).
        The return value is the number of bytes written.
        rr�N)rrQr�rn�	recv_intorKrJrgr?r��_sock_recv_intor�r�r�r�)r&r�bufr�rrrr�sock_recv_into�s�z$BaseSelectorEventLoop.sock_recv_intoc
Cs�|��rdSz|�|�}Wn\ttfk
r4YdSttfk
rL�Yn6tk
rv}z|�|�W5d}~XYnX|�|�dSr+)	r�r�rKrJrirjrhr�r�)r&r�rr��nbytesrerrrr��sz%BaseSelectorEventLoop._sock_recv_intoc	�s�t|�|jr"|��dkr"td��z|�|�}Wnttfk
rLd}YnX|t|�kr^dS|��}|�	�}|�
t�|j
|��|�||j||t|�|g�|IdHS)a�Send data to the socket.

        The socket must be connected to a remote socket. This method continues
        to send data from data until either all data has been sent or an
        error occurs. None is returned on success. On error, an exception is
        raised, and there is no way to determine how much data, if any, was
        successfully processed by the receiving end of the connection.
        rr�N)rrQr�rnrOrKrJ�lenrgr?r�r�r��_sock_write_doner��
_sock_sendall�
memoryview)r&rrGr�r�rrrr�sock_sendall�s&	
��z"BaseSelectorEventLoop.sock_sendallc
Cs�|��rdS|d}z|�||d��}Wnbttfk
rDYdSttfk
r\�Yn2tk
r�}z|�|�WY�dSd}~XYnX||7}|t|�kr�|�	d�n||d<dS)Nr)
r�rOrKrJrirjrhr�r�r�)r&r�rZview�pos�startr�rerrrr��s 
z#BaseSelectorEventLoop._sock_sendallc�s�t|�|jr"|��dkr"td��ttd�r8|jtjkrf|j||j|j	|d�IdH}|d\}}}}}|�
�}|�|||�|IdHS)zTConnect to a remote socket at address.

        This method is a coroutine.
        rr��AF_UNIX)�family�proto�loopN)rrQr�rn�hasattrrBr�r�Z_ensure_resolvedr�rg�
_sock_connect)r&rr6Zresolvedrbr�rrr�sock_connect�s�z"BaseSelectorEventLoop.sock_connectc
Cs�|��}z|�|�Wn�ttfk
rV|�t�|j|��|�||j	|||�YnNt
tfk
rn�Yn6tk
r�}z|�
|�W5d}~XYnX|�d�dSr+)r?ZconnectrKrJr�r�r�r�r��_sock_connect_cbrirjrhr�r�)r&r�rr6rrerrrr��s�z#BaseSelectorEventLoop._sock_connectcCs|�|�dSr+)r�r�rrrr�sz&BaseSelectorEventLoop._sock_write_donec
Cs�|��rdSz,|�tjtj�}|dkr6t|d|����WnZttfk
rPYnNtt	fk
rh�Yn6t
k
r�}z|�|�W5d}~XYnX|�d�dS)NrzConnect call failed )
r�Z
getsockoptrBZ
SOL_SOCKETZSO_ERRORrPrKrJrirjrhr�r�)r&r�rr6�errrerrrr�sz&BaseSelectorEventLoop._sock_connect_cbc�sBt|�|jr"|��dkr"td��|��}|�|d|�|IdHS)aWAccept a connection.

        The socket must be bound to an address and listening for connections.
        The return value is a pair (conn, address) where conn is a new socket
        object usable to send and receive data on the connection, and address
        is the address bound to the socket on the other end of the connection.
        rr�FN)rrQr�rnrg�_sock_accept)r&rr�rrr�sock_acceptsz!BaseSelectorEventLoop.sock_acceptc
Cs�|��}|r|�|�|��r"dSz|��\}}|�d�Wnnttfk
rh|�||j|d|�YnRt	t
fk
r��Yn:tk
r�}z|�|�W5d}~XYnX|�
||f�dSr})r?r�r�r\rCrKrJr�r�rirjrhr�r�)r&r�Z
registeredrrrcr6rerrrr�*s
z"BaseSelectorEventLoop._sock_acceptc	�sp|j|j=|��}|��|��IdHz |j|j|||dd�IdHW�S|��|r^|��||j|j<XdS)NF)Zfallback)	r%�_sock_fd�
is_reading�
pause_reading�_make_empty_waiter�_reset_empty_waiter�resume_readingZ
sock_sendfile�_sock)r&Ztransp�file�offset�countr�rrr�_sendfile_native<s
�z&BaseSelectorEventLoop._sendfile_nativecCs�|D]v\}}|j|j}\}}|tj@rL|dk	rL|jrB|�|�n
|�|�|tj@r|dk	r|jrp|�|�q|�|�qdSr+)	�fileobjrGrrtZ
_cancelledr=Z
_add_callbackr�r�)r&Z
event_listrrzr�r{r|rrr�_process_eventsJs
z%BaseSelectorEventLoop._process_eventscCs|�|���|��dSr+)r=r?r;)r&rrrr�
_stop_servingXsz#BaseSelectorEventLoop._stop_serving)N)N)N)NNN)-r!�
__module__�__qualname__�__doc__rr/rZSSL_HANDSHAKE_TIMEOUTr4r7r;r:r#rHrErRrWrTrarprDr=r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r��
__classcell__rrr'rr0s~
����
�
	�
.�
)rcs�eZdZdZeZdZd�fdd�	Zdd�Zdd�Z	d	d
�Z
dd�Zd
d�Zdd�Z
ejfdd�Zddd�Zdd�Zdd�Zdd�Zdd�Z�ZS) �_SelectorTransportiNcs�t��||�t�|�|jd<z|��|jd<Wntk
rNd|jd<YnXd|jkr�z|��|jd<Wn tj	k
r�d|jd<YnX||_
|��|_d|_
|�|�||_|��|_d|_d|_|jdk	r�|j��||j|j<dS)NrBZsocknamerZFr)rrrr`�_extraZgetsocknamerPZgetpeernamerB�errorr�r?r��_protocol_connected�set_protocol�_server�_buffer_factory�_buffer�
_conn_lost�_closingZ_attachr%)r&r�rr-r)r*r'rrris,





z_SelectorTransport.__init__cCs�|jjg}|jdkr |�d�n|jr0|�d�|�d|j���|jdk	r�|j��s�t|jj	|jt
j�}|rz|�d�n
|�d�t|jj	|jt
j�}|r�d}nd}|�
�}|�d|�d	|�d
��d�d�|��S)
N�closed�closingzfd=zread=pollingz	read=idle�pollingZidlezwrite=<z
, bufsize=�>z<{}>� )r r!r��appendr�r��_loopr9rr"rrtr��get_write_buffer_size�format�join)r&�infor��state�bufsizerrr�__repr__�s0


�
�z_SelectorTransport.__repr__cCs|�d�dSr+)�_force_closer<rrr�abort�sz_SelectorTransport.abortcCs||_d|_dS�NT)�	_protocolr��r&r-rrrr��sz_SelectorTransport.set_protocolcCs|jSr+)r�r<rrr�get_protocol�sz_SelectorTransport.get_protocolcCs|jSr+)r�r<rrrro�sz_SelectorTransport.is_closingcCsT|jr
dSd|_|j�|j�|jsP|jd7_|j�|j�|j�|jd�dS�NTr)	r�r�r=r�r�r�r��	call_soon�_call_connection_lostr<rrrr;�sz_SelectorTransport.closecCs,|jdk	r(|d|��t|d�|j��dS)Nzunclosed transport )�source)r��ResourceWarningr;)r&Z_warnrrr�__del__�s
z_SelectorTransport.__del__�Fatal error on transportcCsNt|t�r(|j��r@tjd||dd�n|j�||||jd��|�|�dS)Nz%r: %sTrM)rXrYrfr-)	rrPr��	get_debugrrr_r�r�)r&rerXrrr�_fatal_error�s

�z_SelectorTransport._fatal_errorcCsd|jr
dS|jr(|j��|j�|j�|jsBd|_|j�|j�|jd7_|j�|j	|�dSr�)
r�r��clearr�r�r�r�r=r�r��r&rerrrr��s
z_SelectorTransport._force_closecCsVz|jr|j�|�W5|j��d|_d|_d|_|j}|dk	rP|��d|_XdSr+)r�r;r�r�r�Z_detachr�Zconnection_lost)r&rer*rrrr��s
z(_SelectorTransport._call_connection_lostcCs
t|j�Sr+)r�r�r<rrrr��sz(_SelectorTransport.get_write_buffer_sizecGs"|jr
dS|jj||f|��dSr+)r�r�rDr�rrrrD�sz_SelectorTransport._add_reader)NN)r�)r!r�r��max_size�	bytearrayr�r�rr�r�r�r�ror;�warnings�warnr�r�r�r�r�rDr�rrr'rr�]s 

r�cs�eZdZdZejjZd#�fdd�	Z�fdd�Z	dd�Z
d	d
�Zdd�Zd
d�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Z�fdd�Zdd �Zd!d"�Z�ZS)$r,TNcs~d|_t��|||||�d|_d|_d|_t�|j�|j	�
|jj|�|j	�
|j
|j|j�|dk	rz|j	�
tj|d�dSr
)�_read_ready_cbrr�_eof�_paused�
_empty_waiterrZ_set_nodelayr�r�r�r��connection_maderDr��_read_readyr�_set_result_unless_cancelled)r&r�rr-r.r)r*r'rrr�s 
�
�z!_SelectorSocketTransport.__init__cs.t|tj�r|j|_n|j|_t��|�dSr+)rrZBufferedProtocol�_read_ready__get_bufferr��_read_ready__data_receivedrr�r�r'rrr�	s
z%_SelectorSocketTransport.set_protocolcCs|jo|jSr+)r�r�r<rrrr�sz#_SelectorSocketTransport.is_readingcCs>|js|jrdSd|_|j�|j�|j��r:t�d|�dS)NTz%r pauses reading)r�r�r�r=r�r�rrr<rrrr�s
z&_SelectorSocketTransport.pause_readingcCs@|js|jsdSd|_|�|j|j�|j��r<t�d|�dS)NFz%r resumes reading)	r�r�rDr�r�r�r�rrr<rrrr�s
z'_SelectorSocketTransport.resume_readingcCs|��dSr+)r�r<rrrr�$sz$_SelectorSocketTransport._read_readyc
Cs`|jr
dSz |j�d�}t|�s(td��WnLttfk
rD�Yn4tk
rv}z|�|d�WY�dSd}~XYnXz|j	�
|�}Wndttfk
r�YdSttfk
r��Yn4tk
r�}z|�|d�WY�dSd}~XYnX|�s|�
�dSz|j�|�WnJttfk
�r,�Yn0tk
�rZ}z|�|d�W5d}~XYnXdS)N���z%get_buffer() returned an empty bufferz/Fatal error: protocol.get_buffer() call failed.�$Fatal read error on socket transportz3Fatal error: protocol.buffer_updated() call failed.)r�r�Z
get_bufferr�r8rirjrhr�r�r�rKrJ�_read_ready__on_eofZbuffer_updated)r&r�rer�rrrr�'sF��z0_SelectorSocketTransport._read_ready__get_bufferc
Cs�|jr
dSz|j�|j�}Wndttfk
r6YdSttfk
rN�Yn4tk
r�}z|�	|d�WY�dSd}~XYnX|s�|�
�dSz|j�|�WnFttfk
r��Yn.tk
r�}z|�	|d�W5d}~XYnXdS)Nr�z2Fatal error: protocol.data_received() call failed.)
r�r�rIr�rKrJrirjrhr�r�r�Z
data_received)r&rGrerrrr�Ls.�z3_SelectorSocketTransport._read_ready__data_receivedc
Cs�|j��rt�d|�z|j��}WnLttfk
r>�Yn4tk
rp}z|�	|d�WY�dSd}~XYnX|r�|j�
|j�n|��dS)Nz%r received EOFz1Fatal error: protocol.eof_received() call failed.)
r�r�rrr�Zeof_receivedrirjrhr�r=r�r;)r&Z	keep_openrerrrr�es
�z,_SelectorSocketTransport._read_ready__on_eofc
Cs6t|tttf�s$tdt|�j����|jr2td��|j	dk	rDtd��|sLdS|j
rz|j
tjkrht
�d�|j
d7_
dS|j�sz|j�|�}Wnbttfk
r�Ynbttfk
r��YnJtk
r�}z|�|d�WY�dSd}~XYnX||d�}|�sdS|j�|j|j�|j�|�|��dS)N�/data argument must be a bytes-like object, not z%Cannot call write() after write_eof()z(unable to write; sendfile is in progress�socket.send() raised exception.r�%Fatal write error on socket transport)r�bytesr�r�r�typer!r�r8r�r�r�!LOG_THRESHOLD_FOR_CONNLOST_WRITESr�warningr�r�rOrKrJrirjrhr�r�r�r��_write_ready�extend�_maybe_pause_protocol)r&rGr�rerrr�writezs:

z_SelectorSocketTransport.writec
Cs(|jstd��|jrdSz|j�|j�}Wn�ttfk
rBYn�ttfk
rZ�Yn�t	k
r�}z>|j
�|j�|j�
�|�|d�|jdk	r�|j�|�W5d}~XYnpX|r�|jd|�=|��|j�s$|j
�|j�|jdk	r�|j�d�|j�r|�d�n|j�r$|j�tj�dS)NzData should not be emptyr�)r��AssertionErrorr�r�rOrKrJrirjrhr�r�r�r�r�r�r��_maybe_resume_protocolr�r�r�r��shutdownrB�SHUT_WR)r&r�rerrrr�s4


z%_SelectorSocketTransport._write_readycCs.|js|jrdSd|_|js*|j�tj�dSr�)r�r�r�r�rrBrr<rrr�	write_eof�s
z"_SelectorSocketTransport.write_eofcCsdSr�rr<rrr�
can_write_eof�sz&_SelectorSocketTransport.can_write_eofcs*t��|�|jdk	r&|j�td��dS)NzConnection is closed by peer)rr�r�r��ConnectionErrorr�r'rrr��s

�z._SelectorSocketTransport._call_connection_lostcCs6|jdk	rtd��|j��|_|js0|j�d�|jS)NzEmpty waiter is already set)r�r8r�rgr�r�r<rrrr��s
z+_SelectorSocketTransport._make_empty_waitercCs
d|_dSr+)r�r<rrrr��sz,_SelectorSocketTransport._reset_empty_waiter)NNN)r!r�r�Z_start_tls_compatiblerZ
_SendfileModeZ
TRY_NATIVEZ_sendfile_compatiblerr�r�r�r�r�r�r�r�rrr	r
r�r�r�r�rrr'rr,�s*�%'r,csFeZdZejZd�fdd�	Zdd�Zdd�Zd
dd	�Z	d
d�Z
�ZS)r5Ncs^t��||||�||_|j�|jj|�|j�|j|j|j	�|dk	rZ|j�t
j|d�dSr+)rr�_addressr�r�r�r�rDr�r�rr�)r&r�rr-r6r.r)r'rrr�s
�
�z#_SelectorDatagramTransport.__init__cCstdd�|jD��S)Ncss|]\}}t|�VqdSr+)r�)�.0rGrbrrr�	<genexpr>�szC_SelectorDatagramTransport.get_write_buffer_size.<locals>.<genexpr>)�sumr�r<rrrr��sz0_SelectorDatagramTransport.get_write_buffer_sizec
Cs�|jr
dSz|j�|j�\}}Wn�ttfk
r8Yn�tk
rd}z|j�|�W5d}~XYnTt	t
fk
r|�Yn<tk
r�}z|�|d�W5d}~XYnX|j�
||�dS)Nz&Fatal read error on datagram transport)r�r�Zrecvfromr�rKrJrPr��error_receivedrirjrhr�Zdatagram_received�r&rGrdrerrrr��sz&_SelectorDatagramTransport._read_readyc
Cs�t|tttf�s$tdt|�j����|s,dS|jrV|d|jfkrPtd|j����|j}|j	r�|jr�|j	t
jkrxt�
d�|j	d7_	dS|j�slz,|jdr�|j�|�n|j�||�WdSttfk
r�|j�|j|j�Yn�tk
�r}z|j�|�WY�dSd}~XYnPttfk
�r6�Yn6tk
�rj}z|�|d�WY�dSd}~XYnX|j� t|�|f�|�!�dS)Nr�z!Invalid address: must be None or r�rrZ�'Fatal write error on datagram transport)"rr�r�r�rr�r!rrnr�rr�rrr�r�r�rO�sendtorKrJr�r�r��
_sendto_readyrPr�rrirjrhr�r�rrrrrr�sH
�

�z!_SelectorDatagramTransport.sendtoc
Cs|jr�|j��\}}z*|jdr.|j�|�n|j�||�Wqttfk
rj|j�||f�Yq�Yqt	k
r�}z|j
�|�WY�dSd}~XYqtt
fk
r��Yqtk
r�}z|�|d�WY�dSd}~XYqXq|��|j�s|j�|j�|j�r|�d�dS)NrZr)r��popleftr�r�rOrrKrJ�
appendleftrPr�rrirjrhr�rr�r�r�r�r�rrrrr*s2
�z(_SelectorDatagramTransport._sendto_ready)NNN)N)r!r�r��collections�dequer�rr�r�rrr�rrr'rr5�s�

+r5)r��__all__rr^r�rrBr�r$r�ImportError�rrrrrr	r
r�logrrrZ
BaseEventLooprZ_FlowControlMixinZ	Transportr�r,r5rrrr�<module>sF
1�o

?>