AlkantarClanX12

Your IP : 3.21.247.78


Current Path : /usr/lib64/python3.8/__pycache__/
Upload File :
Current File : //usr/lib64/python3.8/__pycache__/asyncore.cpython-38.pyc

U

e5d~N�@shdZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZeee
eeeeh�ZzeWnek
r�iZYnXdd�ZGdd�de�ZeeefZdd	�Zd
d�Z dd
�Z!dd�Z"d&dd�Z#d'dd�Z$e$Z%d(dd�Z&Gdd�d�Z'Gdd�de'�Z(dd�Z)d)dd �Z*ej+d!k�rdGd"d#�d#�Z,Gd$d%�d%e'�Z-dS)*a�Basic infrastructure for asynchronous socket service clients and servers.

There are only two ways to have a program on a single processor do "more
than one thing at a time".  Multi-threaded programming is the simplest and
most popular way to do it, but there is another very different technique,
that lets you have nearly all the advantages of multi-threading, without
actually using multiple threads. it's really only practical if your program
is largely I/O bound. If your program is CPU bound, then pre-emptive
scheduled threads are probably what you really need. Network servers are
rarely CPU-bound, however.

If your operating system supports the select() system call in its I/O
library (and nearly all do), then you can use it to juggle multiple
communication channels at once; doing other work while your I/O is taking
place in the "background."  Although this strategy can seem strange and
complex, especially at first, it is in many ways easier to understand and
control than multi-threaded programming. The module documented here solves
many of the difficult problems for you, making the task of building
sophisticated high-performance network servers and clients a snap.
�N)
�EALREADY�EINPROGRESS�EWOULDBLOCK�
ECONNRESET�EINVAL�ENOTCONN�	ESHUTDOWN�EISCONN�EBADF�ECONNABORTED�EPIPE�EAGAIN�	errorcodec
CsHzt�|�WStttfk
rB|tkr6t|YSd|YSXdS)NzUnknown error %s)�os�strerror�
ValueError�
OverflowError�	NameErrorr)�err�r� /usr/lib64/python3.8/asyncore.py�	_strerrorDsrc@seZdZdS)�ExitNowN)�__name__�
__module__�__qualname__rrrrrLsrcCs:z|��Wn(tk
r"�Yn|��YnXdS�N)�handle_read_event�_reraised_exceptions�handle_error��objrrr�readQsr"cCs:z|��Wn(tk
r"�Yn|��YnXdSr)�handle_write_eventrrr rrr�writeYsr$cCs:z|��Wn(tk
r"�Yn|��YnXdSr)�handle_expt_eventrrr rrr�
_exceptionasr&c
Cs�zX|tj@r|��|tj@r&|��|tj@r8|��|tjtjBtj	B@rV|�
�Wnhtk
r�}z$|jdt
kr�|��n|�
�W5d}~XYn(tk
r��Yn|��YnXdS�Nr)�select�POLLINr�POLLOUTr#�POLLPRIr%ZPOLLHUPZPOLLERRZPOLLNVAL�handle_close�OSError�args�
_DISCONNECTEDrr)r!�flags�errr�	readwriteis"



r2�c	Cs<|dkrt}|�r8g}g}g}t|���D]L\}}|��}|��}|rP|�|�|rd|jsd|�|�|sl|r*|�|�q*g|kr�|kr�|kr�nnt�|�dSt	�	||||�\}}}|D] }|�
|�}|dkr�q�t|�q�|D]"}|�
|�}|dk�rq�t|�q�|D]&}|�
|�}|dk�r,�qt
|��qdSr)�
socket_map�list�items�readable�writable�append�	accepting�time�sleepr(�getr"r$r&)	�timeout�map�r�wr1�fdr!Zis_rZis_wrrr�poll}sD


"







rCcCs�|dkrt}|dk	r t|d�}t��}|r�t|���D]L\}}d}|��r\|tjtjBO}|�	�rt|j
st|tjO}|r8|�||�q8|�|�}|D]&\}}|�
|�}|dkr�q�t||�q�dS)Ni�r)r4�intr(rCr5r6r7r)r+r8r:r*�registerr=r2)r>r?ZpollsterrBr!r0r@rrr�poll2�s(


rF�>@FcCsb|dkrt}|r ttd�r t}nt}|dkr>|r^|||�q,n |r^|dkr^|||�|d}q>dS)NrCr�)r4�hasattrr(rFrC)r>Zuse_pollr?�countZpoll_funrrr�loop�s
rKc@s2eZdZdZdZdZdZdZdZe	dh�Z
dAdd�Zdd�ZdBdd	�Z
dCd
d�Zejejfdd
�ZdDdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdEd'd(�Zd)d*�Z d+d,�Z!d-d.�Z"d/d0�Z#d1d2�Z$d3d4�Z%d5d6�Z&d7d8�Z'd9d:�Z(d;d<�Z)d=d>�Z*d?d@�Z+dS)F�
dispatcherFN�warningc
Cs�|dkrt|_n||_d|_|r�|�d�|�||�d|_z|��|_Wq�tk
r�}z*|j	dt
tfkrvd|_n|�|��W5d}~XYq�Xnd|_
dS�NrTF)r4�_map�_fileno�setblocking�
set_socket�	connectedZgetpeername�addrr-r.rr�del_channel�socket)�self�sockr?rrrr�__init__�s 

zdispatcher.__init__cCs�|jjd|jjg}|jr.|jr.|�d�n|jr>|�d�|jdk	r�z|�d|j�Wn$tk
r�|�t|j��YnXdd�	|�t
|�fS)N�.Z	listeningrSz%s:%dz<%s at %#x>� )�	__class__rrr:rTr9rS�	TypeError�repr�join�id)rWZstatusrrr�__repr__�s

zdispatcher.__repr__cCs|dkr|j}|||j<dSr)rOrP)rWr?rrr�add_channel	szdispatcher.add_channelcCs,|j}|dkr|j}||kr"||=d|_dSr)rPrO)rWr?rBrrrrUszdispatcher.del_channelcCs.||f|_t�||�}|�d�|�|�dSr')Zfamily_and_typerVrQrR)rWZfamily�typerXrrr�
create_sockets

zdispatcher.create_socketcCs||_|��|_|�|�dSr)rV�filenorPrb�rWrXr?rrrrRs
zdispatcher.set_socketcCsDz*|j�tjtj|j�tjtj�dB�Wntk
r>YnXdS)NrH)rVZ
setsockopt�
SOL_SOCKETZSO_REUSEADDR�
getsockoptr-�rWrrr�set_reuse_addr#s
���zdispatcher.set_reuse_addrcCsdS�NTrrirrrr74szdispatcher.readablecCsdSrkrrirrrr87szdispatcher.writablecCs(d|_tjdkr|dkrd}|j�|�S)NT�nt�)r:r�namerV�listen)rWZnumrrrro>szdispatcher.listencCs||_|j�|�Sr)rTrV�bind)rWrTrrrrpDszdispatcher.bindcCspd|_d|_|j�|�}|tttfks8|tkrBtj	dkrB||_
dS|dtfkr^||_
|��nt
|t|��dS)NFTrlr)rS�
connectingrVZ
connect_exrrrrrrnrTr	�handle_connect_eventr-r)rWZaddressrrrr�connectHs��
zdispatcher.connectc
Csvz|j��\}}WnVtk
r(YdStk
rh}z$|jdtttfkrVWY�
dS�W5d}~XYn
X||fSdSr')rV�acceptr]r-r.rrr
)rWZconnrT�whyrrrrtVs
zdispatcher.acceptc
Cstz|j�|�}|WStk
rn}z>|jdtkr<WY�*dS|jdtkr\|��WY�
dS�W5d}~XYnXdSr')rV�sendr-r.rr/r,)rW�data�resultrurrrrvds

zdispatcher.sendc
Csrz(|j�|�}|s |��WdS|WSWnDtk
rl}z&|jdtkrZ|��WY�
dS�W5d}~XYnXdS)N�r)rV�recvr,r-r.r/)rWZbuffer_sizerwrurrrrzqs

zdispatcher.recvc
Csnd|_d|_d|_|��|jdk	rjz|j��Wn6tk
rh}z|jdtt	fkrX�W5d}~XYnXdS)NFr)
rSr:rqrUrV�closer-r.rr
)rWrurrrr{�s
zdispatcher.closecCstj�dt|��dS)Nzlog: %s
)�sys�stderrr$�str)rW�messagerrr�log�szdispatcher.log�infocCs||jkrtd||f�dS)Nz%s: %s)�ignore_log_types�print)rWrrcrrr�log_info�s
zdispatcher.log_infocCs:|jr|��n&|js.|jr$|��|��n|��dSr)r:�
handle_acceptrSrqrr�handle_readrirrrr�s

zdispatcher.handle_read_eventcCs@|j�tjtj�}|dkr(t|t|���|��d|_d|_dSrN)	rVrhrg�SO_ERRORr-r�handle_connectrSrq�rWrrrrrr�szdispatcher.handle_connect_eventcCs*|jr
dS|js|jr|��|��dSr)r:rSrqrr�handle_writerirrrr#�szdispatcher.handle_write_eventcCs0|j�tjtj�}|dkr$|��n|��dSr')rVrhrgr�r,�handle_exptr�rrrr%�s
zdispatcher.handle_expt_eventcCsXt�\}}}}zt|�}Wndt|�}YnX|�d||||fd�|��dS)Nz)<__repr__(self) failed for object at %0x>z:uncaptured python exception, closing channel %s (%s:%s %s)�error)�compact_tracebackr^r`r�r,)rWZnil�t�v�tbinfoZ	self_reprrrrr�s��	zdispatcher.handle_errorcCs|�dd�dS)Nz!unhandled incoming priority eventrM�r�rirrrr��szdispatcher.handle_exptcCs|�dd�dS)Nzunhandled read eventrMr�rirrrr��szdispatcher.handle_readcCs|�dd�dS)Nzunhandled write eventrMr�rirrrr��szdispatcher.handle_writecCs|�dd�dS)Nzunhandled connect eventrMr�rirrrr��szdispatcher.handle_connectcCs|��}|dk	r|j|�dSr)rt�handle_accepted)rWZpairrrrr��szdispatcher.handle_acceptcCs|��|�dd�dS)Nzunhandled accepted eventrM)r{r�)rWrXrTrrrr��szdispatcher.handle_acceptedcCs|�dd�|��dS)Nzunhandled close eventrM)r�r{rirrrr,�szdispatcher.handle_close)NN)N)N)N)r�),rrr�debugrSr:rq�closingrT�	frozensetr�rYrarbrUrVZAF_INETZSOCK_STREAMrdrRrjr7r8rorprsrtrvrzr{r�r�rrrr#r%rr�r�r�r�r�r�r,rrrrrL�sJ

 

	


rLc@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�dispatcher_with_sendNcCst�|||�d|_dS)Nry)rLrY�
out_bufferrfrrrrY�szdispatcher_with_send.__init__cCs.d}t�||jdd��}|j|d�|_dS)Nri)rLrvr�)rWZnum_sentrrr�
initiate_sendsz"dispatcher_with_send.initiate_sendcCs|��dSr)r�rirrrr�sz!dispatcher_with_send.handle_writecCs|jpt|j�Sr)rS�lenr�rirrrr8szdispatcher_with_send.writablecCs0|jr|�dt|��|j||_|��dS)Nz
sending %s)r�r�r^r�r�)rWrwrrrrvszdispatcher_with_send.send)NN)rrrrYr�r�r8rvrrrrr��s

r�cCs�t��\}}}g}|std��|rL|�|jjj|jjjt|j	�f�|j
}q~|d\}}}d�dd�|D��}|||f|||fS)Nztraceback does not exist���r[cSsg|]}d|�qS)z
[%s|%s|%s]r)�.0�xrrr�
<listcomp>&sz%compact_traceback.<locals>.<listcomp>)r|�exc_info�AssertionErrorr9�tb_frame�f_code�co_filename�co_namer~�	tb_lineno�tb_nextr_)r�r��tbr��fileZfunction�liner�rrrr�s�r�cCs�|dkrt}t|���D]n}z|��Wqtk
r`}z|jdtkrJn|sP�W5d}~XYqtk
rt�Yq|s��YqXq|��dSr')	r4r5�valuesr{r-r.r
r�clear)r?Z
ignore_allr�rrr�	close_all)s 
r��posixc@sNeZdZdd�Zdd�Zdd�Zdd�Zdd
d�ZeZeZ	dd
�Z
dd�Zd	S)�file_wrappercCst�|�|_dSr)r�duprB�rWrBrrrrYNszfile_wrapper.__init__cCs*|jdkrtjd|t|d�|��dS)Nrzunclosed file %r)�source)rB�warnings�warn�ResourceWarningr{rirrr�__del__Qs

�zfile_wrapper.__del__cGstj|jf|��Sr)rr"rB�rWr.rrrrzWszfile_wrapper.recvcGstj|jf|��Sr)rr$rBr�rrrrvZszfile_wrapper.sendNcCs(|tjkr|tjkr|sdStd��dS)Nrz-Only asyncore specific behaviour implemented.)rVrgr��NotImplementedError)rW�levelZoptnameZbuflenrrrrh]s
��zfile_wrapper.getsockoptcCs(|jdkrdS|j}d|_t�|�dS)Nrr�)rBrr{r�rrrr{hs

zfile_wrapper.closecCs|jSr)rBrirrrreoszfile_wrapper.fileno)N)rrrrYr�rzrvrhr"r$r{rerrrrr�Is
r�c@seZdZddd�Zdd�ZdS)�file_dispatcherNcCsPt�|d|�d|_z|��}Wntk
r4YnX|�|�t�|d�dS)NTF)rLrYrSre�AttributeError�set_filer�set_blocking)rWrBr?rrrrYts
zfile_dispatcher.__init__cCs"t|�|_|j��|_|��dSr)r�rVrerPrbr�rrrr�s
zfile_dispatcher.set_file)N)rrrrYr�rrrrr�rs
r�)r3N)r3N)rGFNN)NF).�__doc__r(rVr|r;r�r�errnorrrrrrrr	r
rrr
rr�r/r4rr�	Exceptionr�KeyboardInterrupt�
SystemExitrr"r$r&r2rCrFZpoll3rKrLr�r�r�rnr�r�rrrr�<module>sD<�


'

*
)