a
�RLgN��@s,dZdZddlZddlZddlZddlZddlZddlZddlZzddl Z Wne
ybdZ Yn0ddlmZddlm
Z
ddlmZddlmZdd lmZdd
lmZddlmZddlmZdd
lmZdd�Zdd�ZGdd�dej�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)�loggercCs6z|�|�}Wnty"YdS0t|j|@�SdS�NF)�get_key�KeyError�boolr)�selector�fdZevent�key�r�-/usr/lib/python3.9/asyncio/selector_events.py�_test_selector_event s
rcCs tdurt|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�ZdVdd
�Z �fdd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdddejfdd�Zdddejfdd�Zddejfdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�ZdWd5d6�Zd7d8�Zd9d:�Zd;d<�Z d=d>�Z!d?d@�Z"dAdB�Z#dCdD�Z$dXdEdF�Z%dGdH�Z&dIdJ�Z'dKdL�Z(dMdN�Z)dOdP�Z*dQdR�Z+�Z,S)YrzJSelector event loop.
See events.EventLoop for API specification.
NcsFt���|durt��}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*r2Zssl_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���|jdurH|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_datacCsTz"|j�d�}|sWqP|�|�Wqty8YqYqtyLYqPYq0qdS)Ni)r>�recvrH�InterruptedError�BlockingIOErrorrFrrrrEusz%BaseSelectorEventLoop._read_from_selfcCsL|j}|durdSz|�d�Wn&tyF|jrBtjddd�Yn0dS)N�z3Fail to write a null byte into the self-pipe socketT��exc_info)r@�send�OSError�_debugrr)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�tttfyXYdSt y�}
zl|
j
t
jt
jt
j
t
jfvr�|�d|
t�|�d��|�|���|�tj|j||||||�n�WYd}
~
qd}
~
00d| i}|�||||||�}|�|�qdS)Nz#%r got a new connection from %r: %rFz&socket.accept() out of system resource)�message� exceptionrB�peername)�range�acceptrQrrrCrKrJ�ConnectionAbortedErrorrP�errnoZEMFILEZENFILEZENOBUFSZENOMEM�call_exception_handlerr�TransportSocketr=r?Z
call_laterrZACCEPT_RETRY_DELAYrW�_accept_connection2Zcreate_task)
r&rUrr3r*rVr2�_�conn�addr�excr)r\rrrrT�s@����
�z(BaseSelectorEventLoop._accept_connectionc
�s�d}d}zr|�}|��} |r8|j|||| d|||d�}n|j||| ||d�}z| IdHWntyv|���Yn0Wntttfy��Yn^ty�}
zF|jr�d|
d�}|dur�||d<|dur�||d<|�|�WYd}
~
n
d}
~
00dS)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�s@���z)BaseSelectorEventLoop._accept_connection2c
Cs�|}t|t�sHzt|���}Wn(tttfyFtd|���d�Yn0z|j|}WntyhYn0|��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(tyP|j�|tj|df�Yn>0|j|j }\}}|j�
||tjB||f�|dur�|��|Sr+)�
_check_closedr�Handler"rr�registerr�
EVENT_READrG�modify�cancel� r&r�callback�args�handler�mask�reader�writerrrrrDs�
�z!BaseSelectorEventLoop._add_readercCs�|��rdSz|j�|�}Wnty0YdS0|j|j}\}}|tjM}|sb|j�|�n|j� ||d|f�|dur�|�
�dSdSdS)NFT)r9r"rrrrGrrt�
unregisterrurv�r&rrr{r|r}rrrr=sz$BaseSelectorEventLoop._remove_readerc Gs�|��t�|||d�}z|j�|�}Wn(tyP|j�|tjd|f�Yn>0|j|j }\}}|j�
||tjB||f�|dur�|��|Sr+)rqrrrr"rrrsr�EVENT_WRITErGrurvrwrrr�_add_writer&s�
�z!BaseSelectorEventLoop._add_writercCs�|��rdSz|j�|�}Wnty0YdS0|j|j}\}}|tjM}|sb|j�|�n|j� |||df�|dur�|�
�dSdSdS)�Remove a writer callback.FNT)r9r"rrrrGrr�r~rurvrrrr�_remove_writer6sz$BaseSelectorEventLoop._remove_writercGs"|�|�|j||g|�R�dS)zAdd a reader callback.N)rprD�r&rrxryrrr�
add_readerMs
z BaseSelectorEventLoop.add_readercCs|�|�|�|�S)zRemove a reader callback.)rpr=�r&rrrr�
remove_readerRs
z#BaseSelectorEventLoop.remove_readercGs"|�|�|j||g|�R�dS)zAdd a writer callback..N)rpr�r�rrr�
add_writerWs
z BaseSelectorEventLoop.add_writercCs|�|�|�|�S)r�)rpr�r�rrr�
remove_writer\s
z#BaseSelectorEventLoop.remove_writerc �s�t|�|jr"|��dkr"td��z|�|�WSttfyDYn0|��}|��}|� |�|�
||j|||�}|�t
j|j||d��|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-blocking�rzN)rrQ�
gettimeoutrnrIrKrJrgr?rprD�
_sock_recv�add_done_callback� functools�partial�_sock_read_done)r&r�n�futrrzrrr� sock_recvas
�zBaseSelectorEventLoop.sock_recvcCs|dus|��s|�|�dSr+)� cancelledr��r&rr�rzrrrr�wsz%BaseSelectorEventLoop._sock_read_donec
Cs�|��rdSz|�|�}WnZttfy2YdSttfyH�Yn8tyt}z|�|�WYd}~nd}~00|�|�dSr+) �donerIrKrJrirjrh�
set_exception�
set_result)r&r�rr�rGrerrrr�{s z BaseSelectorEventLoop._sock_recvc �s�t|�|jr"|��dkr"td��z|�|�WSttfyDYn0|��}|��}|� |�|�
||j|||�}|�t
j|j||d��|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�r�N)rrQr�rn� recv_intorKrJrgr?rprD�_sock_recv_intor�r�r�r�)r&r�bufr�rrzrrr�sock_recv_into�s
�z$BaseSelectorEventLoop.sock_recv_intoc
Cs�|��rdSz|�|�}WnZttfy2YdSttfyH�Yn8tyt}z|�|�WYd}~nd}~00|�|�dSr+) r�r�rKrJrirjrhr�r�)r&r�rr��nbytesrerrrr��s z%BaseSelectorEventLoop._sock_recv_intoc �s�t|�|jr"|��dkr"td��z|�|�}WnttfyJd}Yn0|t|�kr\dS|��}|� �}|�
|�|�||j||t
|�|g�}|�tj|j||d��|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�Nr�)rrQr�rnrOrKrJ�lenrgr?rpr��
_sock_sendall�
memoryviewr�r�r��_sock_write_done)r&rrGr�r�rrzrrr�sock_sendall�s&
��z"BaseSelectorEventLoop.sock_sendallc
Cs�|��rdS|d}z|�||d��}Wn\ttfyBYdSttfyX�Yn0ty�}z|�|�WYd}~dSd}~00||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�ttfyb|�|�|�||j|||�}|�tj |j
||d��YnNttfyx�Yn8t
y�}z|�|�WYd}~nd}~00|�d�dS)Nr�)r?ZconnectrKrJrpr��_sock_connect_cbr�r�r�r�rirjrhr�r�)r&r�rr6rrzrerrrr��s
�� z#BaseSelectorEventLoop._sock_connectcCs|dus|��s|�|�dSr+)r�r�r�rrrr�
sz&BaseSelectorEventLoop._sock_write_donec
Cs�|��rdSz,|�tjtj�}|dkr6t|d|����WnXttfyNYnNtt fyd�Yn8t
y�}z|�|�WYd}~nd}~00|�d�dS)NrzConnect call failed )
r�Z
getsockoptrBZ
SOL_SOCKETZSO_ERRORrPrKrJrirjrhr�r�)r&r�rr6�errrerrrr�s z&BaseSelectorEventLoop._sock_connect_cbc�s@t|�|jr"|��dkr"td��|��}|�||�|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�N)rrQr�rnrg�_sock_accept)r&rr�rrr�sock_accept$sz!BaseSelectorEventLoop.sock_acceptc
Cs�|��}z|��\}}|�d�Wn�ttfyl|�|�|�||j||�}|�t j
|j||d��YnRtt
fy��Yn<ty�}z|�|�WYd}~nd}~00|�||f�dS)NFr�)r?r\rCrKrJrprDr�r�r�r�r�rirjrhr�r�)r&r�rrrcr6rzrerrrr�3s
� z"BaseSelectorEventLoop._sock_acceptc �s�|j|j=|��}|��|��IdHzL|j|j|||dd�IdHW|��|rZ|��||j|j<S||j|j<n"|��|r�|��||j|j<0dS)NF)Zfallback) r%�_sock_fd�
is_reading�
pause_reading�_make_empty_waiterZ
sock_sendfile�_sock�_reset_empty_waiter�resume_reading)r&Ztransp�file�offset�countr�rrr�_sendfile_nativeDs*
���z&BaseSelectorEventLoop._sendfile_nativecCs�|D]v\}}|j|j}\}}|tj@rL|durL|jrB|�|�n
|�|�|tj@r|dur|jrp|�|�q|�|�qdSr+) �fileobjrGrrtZ
_cancelledr=Z
_add_callbackr�r�)r&Z
event_listrr{r�r|r}rrr�_process_eventsRs
z%BaseSelectorEventLoop._process_eventscCs|�|���|��dSr+)r=r?r;)r&rrrr�
_stop_serving`sz#BaseSelectorEventLoop._stop_serving)N)N)N)NNN)N)N)-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'rr0sj
����
�
�
.�
)
rcs�eZdZdZeZdZd�fdd� Zdd�Zdd�Z d d
�Z
dd�Zd
d�Zdd�Z
ejfdd�Zddd�Zdd�Zdd�Zdd�Zdd�Z�ZS) �_SelectorTransportiNcs�t��||�t�|�|jd<z|��|jd<WntyLd|jd<Yn0d|jvr�z|��|jd<Wntj y�d|jd<Yn0||_
|��|_d|_
|�|�||_|��|_d|_d|_|jdur�|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'rrrqs,
z_SelectorTransport.__init__cCs�|jjg}|jdur |�d�n|jr0|�d�|�d|j���|jdur�|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=zread=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__�s.
�
�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,|jdur(|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_debugrrr_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_closecCs�zN|jr|j�|�W|j��d|_d|_d|_|j}|dur�|��d|_n:|j��d|_d|_d|_|j}|dur�|��d|_0dSr+)r�r�Zconnection_lostr�r;r�r�Z_detach)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||g|�R�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�es
r�cs�eZdZdZejjZd#�fdd� Z�fdd�Z dd�Z
d d
�Zdd�Zd
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�|durz|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|jo|jSr+)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�rrr<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�rrr<rrrr�$s
z'_SelectorSocketTransport.resume_readingcCs|��dSr+)r�r<rrrr�,sz$_SelectorSocketTransport._read_readyc
CsV|jr
dSz |j�d�}t|�s(td��WnHttfyB�Yn2tyr}z|�|d�WYd}~dSd}~00z|j �
|�}Wn^ttfy�YdSttfy��Yn2ty�}z|�|d�WYd}~dSd}~00|�s�|�
�dSz|j�|�WnJttf�y �Yn2t�yP}z|�|d�WYd}~n
d}~00dS)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�/sB��z0_SelectorSocketTransport._read_ready__get_bufferc
Cs�|jr
dSz|j�|j�}Wn^ttfy4YdSttfyJ�Yn2tyz}z|� |d�WYd}~dSd}~00|s�|�
�dSz|j�|�WnFttfy��Yn0ty�}z|� |d�WYd}~n
d}~00dS)Nr�z2Fatal error: protocol.data_received() call failed.)
r�r�rIr�rKrJrirjrhr�r�r�Z
data_received)r&rGrerrrr�Ts,�z3_SelectorSocketTransport._read_ready__data_receivedc
Cs�|j��rt�d|�z|j��}WnHttfy<�Yn2tyl}z|� |d�WYd}~dSd}~00|r�|j�
|j�n|��dS)Nz%r received EOFz1Fatal error: protocol.eof_received() call failed.)
r�r�rrr�Zeof_receivedrirjrhr�r=r�r;)r&Z keep_openrerrrr�ms
�z,_SelectorSocketTransport._read_ready__on_eofc
Cs0t|tttf�s$tdt|�j����|jr2td��|j durDtd��|sLdS|j
rz|j
tjkrht
�d�|j
d7_
dS|j�sz|j�|�}Wn\ttfy�Yn^ttfy��YnHty�}z|�|d�WYd}~dSd}~00||d�}|�sdS|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�write�s>�
z_SelectorSocketTransport.writec
Cs&|jsJd��|jrdSz|j�|j�}Wn�ttfy@Yn�ttfyV�Yn�ty�}zF|j �
|j�|j��|�
|d�|jdur�|j�|�WYd}~nxd}~00|r�|jd|�=|��|j�s"|j �
|j�|jdur�|j�d�|j�r|�d�n|j�r"|j�tj�dS)NzData should not be emptyr�)r�r�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�rrBr r<rrr� write_eof�s
z"_SelectorSocketTransport.write_eofcCsdSr�rr<rrr�
can_write_eof�sz&_SelectorSocketTransport.can_write_eofcs*t��|�|jdur&|j�td��dS)NzConnection is closed by peer)rr�r�r��ConnectionErrorr�r'rrr��s
�z._SelectorSocketTransport._call_connection_lostcCs6|jdurtd��|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
rr�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 �|durZ|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>��zC_SelectorDatagramTransport.get_write_buffer_size.<locals>.<genexpr>)�sumr�r<rrrr��sz0_SelectorDatagramTransport.get_write_buffer_sizec
Cs�|jr
dSz|j�|j�\}}Wn�ttfy6Yn�tyd}z|j�|�WYd}~n\d}~0t t
fyz�Yn>ty�}z|�|d�WYd}~nd}~00|j�
||�dS)Nz&Fatal read error on datagram transport)r�r�Zrecvfromr�rKrJrPr��error_receivedrirjrhr�Zdatagram_received�r&rGrdrerrrr��s "z&_SelectorDatagramTransport._read_readyc
Cs�t|tttf�s$tdt|�j����|s,dS|jrV|d|jfvrPtd|j����|j}|j r�|jr�|j t
jkrxt�
d�|j d7_ dS|j�sdz,|jdr�|j�|�n|j�||�WdSttfy�|j�|j|j�Yn~t�y}z|j�|�WYd}~dSd}~0ttf�y0�Yn4t�yb}z|�|d�WYd}~dSd}~00|j� t|�|f�|�!�dS)Nr�z!Invalid address: must be None or r�rrZ�'Fatal write error on datagram transport)"rr�r�r�rrr!r
rnr�rrrrr�r�r�rO�sendtorKrJr�r�r��
_sendto_readyrPr�rrirjrhr�r�rrrrrrsJ�
�
�z!_SelectorDatagramTransport.sendtoc
Cs|jr�|j��\}}z*|jdr.|j�|�n|j�||�Wqttfyh|j�||f�Yq�Yqt y�}z|j
�|�WYd}~dSd}~0tt
fy��Yqty�}z|�|d�WYd}~dSd}~00q|��|j�s|j�|j�|j�r|�d�dS)NrZr)r��popleftr�r�rOrrKrJ�
appendleftrPr�rrirjrhr�rr�r�r�r�r�rrrrr2s0
�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�logrrrZ
BaseEventLooprZ_FlowControlMixinZ Transportr�r,r5rrrr�<module>sF
9�o |