AlkantarClanX12

Your IP : 3.133.119.247


Current Path : /opt/alt/python37/lib64/python3.7/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/__pycache__/asyncore.cpython-37.pyc

B

� f�N�@shdZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZeee
eeeeh�ZyeWnek
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
Cs>y
t�|�Stttfk
r8|tkr0t|Sd|SXdS)NzUnknown error %s)�os�strerror�
ValueError�
OverflowError�	NameErrorr)�err�r�-/opt/alt/python37/lib64/python3.7/asyncore.py�	_strerrorDs
rc@seZdZdS)�ExitNowN)�__name__�
__module__�__qualname__rrrrrLsrcCs:y|��Wn(tk
r"�Yn|��YnXdS)N)�handle_read_event�_reraised_exceptions�handle_error)�objrrr�readQsr cCs:y|��Wn(tk
r"�Yn|��YnXdS)N)�handle_write_eventrr)rrrr�writeYsr"cCs:y|��Wn(tk
r"�Yn|��YnXdS)N)�handle_expt_eventrr)rrrr�
_exceptionasr$c
Cs�yX|tj@r|��|tj@r&|��|tj@r8|��|tjtjBtj	B@rV|�
�Wnhtk
r�}z$|jdt
kr�|��n|�
�Wdd}~XYn(tk
r��Yn|��YnXdS)Nr)�select�POLLINr�POLLOUTr!�POLLPRIr#ZPOLLHUPZPOLLERRZPOLLNVAL�handle_close�OSError�args�
_DISCONNECTEDrr)r�flags�errr�	readwriteis"



r/�c	CsL|dkrt}|�rHg}g}g}x\t|���D]L\}}|��}|��}|rR|�|�|rf|jsf|�|�|sn|r,|�|�q,Wg|kr�|kr�|kr�nnt�|�dSt	�	||||�\}}}x(|D] }|�
|�}|dkr�q�t|�q�Wx*|D]"}|�
|�}|dk�rq�t|�q�Wx.|D]&}|�
|�}|dk�r:�qt
|��qWdS)N)�
socket_map�list�items�readable�writable�append�	accepting�timeZsleepr%�getr r"r$)	�timeout�map�r�wr.�fdrZis_rZis_wrrr�poll}sD


"








r?cCs�|dkrt}|dk	r t|d�}t��}|r�x\t|���D]L\}}d}|��r^|tjtjBO}|�	�rv|j
sv|tjO}|r:|�||�q:W|�|�}x.|D]&\}}|�
|�}|dkr�q�t||�q�WdS)Ni�r)r1�intr%r?r2r3r4r&r(r5r7r'�registerr9r/)r:r;Zpollsterr>rr-r<rrr�poll2�s(


rB�>@FcCsj|dkrt}|r ttd�r t}nt}|dkrBx8|r>|||�q.Wn$x"|rd|dkrd|||�|d}qDWdS)Nr?r�)r1�hasattrr%rBr?)r:Zuse_pollr;�countZpoll_funrrr�loop�s
rGc@s6eZdZdZdZdZdZdZdZe	dh�Z
dAdd�Zdd�ZeZ
dBdd	�ZdCd
d�Zejejfdd
�ZdDdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdEd'd(�Z d)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|_y|��|_Wq�tk
r�}z*|j	dt
tfkrvd|_n|�|��Wdd}~XYq�Xnd|_
dS)NrTF)r1�_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�y|�d|j�Wn$tk
r�|�t|j��YnXdd�	|�t
|�fS)N�.Z	listeningrNz%s:%dz<%s at %#x>� )�	__class__rrr7rOr6rN�	TypeError�repr�join�id)rRZstatusrrr�__repr__�s

zdispatcher.__repr__cCs|dkr|j}|||j<dS)N)rJrK)rRr;rrr�add_channelszdispatcher.add_channelcCs,|j}|dkr|j}||kr"||=d|_dS)N)rKrJ)rRr;r>rrrrPszdispatcher.del_channelcCs.||f|_t�||�}|�d�|�|�dS)Nr)Zfamily_and_typerQrLrM)rRZfamily�typerSrrr�
create_sockets

zdispatcher.create_socketcCs||_|��|_|�|�dS)N)rQ�filenorKr])rRrSr;rrrrM s
zdispatcher.set_socketcCsDy*|j�tjtj|j�tjtj�dB�Wntk
r>YnXdS)NrD)rQZ
setsockopt�
SOL_SOCKETZSO_REUSEADDR�
getsockoptr*)rRrrr�set_reuse_addr%s
zdispatcher.set_reuse_addrcCsdS)NTr)rRrrrr46szdispatcher.readablecCsdS)NTr)rRrrrr59szdispatcher.writablecCs(d|_tjdkr|dkrd}|j�|�S)NT�nt�)r7r�namerQ�listen)rRZnumrrrrg@szdispatcher.listencCs||_|j�|�S)N)rOrQ�bind)rRrOrrrrhFszdispatcher.bindcCspd|_d|_|j�|�}|tttfks8|tkrBtj	dkrB||_
dS|dtfkr^||_
|��nt
|t|��dS)NFTrdr)rN�
connectingrQZ
connect_exrrrrrrfrOr	�handle_connect_eventr*r)rRZaddressrrrr�connectJs
zdispatcher.connectc
Csny|j��\}}WnNtk
r&dStk
r`}z|jdtttfkrNdS�Wdd}~XYn
X||fSdS)Nr)rQ�acceptrXr*r+rrr
)rRZconnrO�whyrrrrlXszdispatcher.acceptc
Csfy|j�|�}|Stk
r`}z2|jdtkr4dS|jdtkrN|��dS�Wdd}~XYnXdS)Nr)rQ�sendr*r+rr,r))rR�data�resultrmrrrrnfszdispatcher.sendc
Cshy$|j�|�}|s|��dS|SWn>tk
rb}z |jdtkrP|��dS�Wdd}~XYnXdS)N�r)rQ�recvr)r*r+r,)rR�buffer_sizerormrrrrrsszdispatcher.recvc
Csnd|_d|_d|_|��|jdk	rjy|j��Wn6tk
rh}z|jdtt	fkrX�Wdd}~XYnXdS)NFr)
rNr7rirPrQ�closer*r+rr
)rRrmrrrrt�s
zdispatcher.closecCstj�dt|��dS)Nzlog: %s
)�sys�stderrr"�str)rR�messagerrr�log�szdispatcher.log�infocCs||jkrtd||f�dS)Nz%s: %s)�ignore_log_types�print)rRrxr^rrr�log_info�s
zdispatcher.log_infocCs:|jr|��n&|js.|jr$|��|��n|��dS)N)r7�
handle_acceptrNrirj�handle_read)rRrrrr�s

zdispatcher.handle_read_eventcCs@|j�tjtj�}|dkr(t|t|���|��d|_d|_dS)NrTF)	rQrbra�SO_ERRORr*r�handle_connectrNri)rRrrrrrj�szdispatcher.handle_connect_eventcCs*|jr
dS|js|jr|��|��dS)N)r7rNrirj�handle_write)rRrrrr!�szdispatcher.handle_write_eventcCs0|j�tjtj�}|dkr$|��n|��dS)Nr)rQrbrar�r)�handle_expt)rRrrrrr#�s
zdispatcher.handle_expt_eventcCsXt�\}}}}y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_tracebackrYr[r}r))rRZnil�t�v�tbinfoZ	self_reprrrrr�szdispatcher.handle_errorcCs|�dd�dS)Nz!unhandled incoming priority eventrI)r})rRrrrr��szdispatcher.handle_exptcCs|�dd�dS)Nzunhandled read eventrI)r})rRrrrr�szdispatcher.handle_readcCs|�dd�dS)Nzunhandled write eventrI)r})rRrrrr��szdispatcher.handle_writecCs|�dd�dS)Nzunhandled connect eventrI)r})rRrrrr��szdispatcher.handle_connectcCs|��}|dk	r|j|�dS)N)rl�handle_accepted)rRZpairrrrr~�szdispatcher.handle_acceptcCs|��|�dd�dS)Nzunhandled accepted eventrI)rtr})rRrSrOrrrr��szdispatcher.handle_acceptedcCs|�dd�|��dS)Nzunhandled close eventrI)r}rt)rRrrrr)�szdispatcher.handle_close)NN)N)N)N)rz)-rrr�debugrNr7ri�closingrO�	frozensetr{rTr\�__str__r]rPrQZAF_INETZSOCK_STREAMr_rMrcr4r5rgrhrkrlrnrrrtryr}rrjr!r#rr�rr�r�r~r�r)rrrrrH�sL

 


	


rHc@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�dispatcher_with_sendNcCst�|||�d|_dS)Nrq)rHrT�
out_buffer)rRrSr;rrrrT�szdispatcher_with_send.__init__cCs.d}t�||jdd��}|j|d�|_dS)Nri)rHrnr�)rRZnum_sentrrr�
initiate_sendsz"dispatcher_with_send.initiate_sendcCs|��dS)N)r�)rRrrrr�sz!dispatcher_with_send.handle_writecCs|jpt|j�S)N)rN�lenr�)rRrrrr5
szdispatcher_with_send.writablecCs0|jr|�dt|��|j||_|��dS)Nz
sending %s)r�r}rYr�r�)rRrorrrrn
szdispatcher_with_send.send)NN)rrrrTr�r�r5rnrrrrr��s

r�cCs�t��\}}}g}|std��x0|rN|�|jjj|jjjt|j	�f�|j
}q W~|d\}}}d�dd�|D��}|||f|||fS)Nztraceback does not exist���rVcSsg|]}d|�qS)z
[%s|%s|%s]r)�.0�xrrr�
<listcomp>(sz%compact_traceback.<locals>.<listcomp>)ru�exc_info�AssertionErrorr6�tb_frame�f_code�co_filename�co_namerw�	tb_lineno�tb_nextrZ)r�r��tbr��fileZfunction�linerzrrrr�s
r�cCs�|dkrt}x~t|���D]n}y|��Wqtk
rb}z|jdtkrLn|sR�Wdd}~XYqtk
rv�Yq|s��YqXqW|��dS)Nr)	r1r2�valuesrtr*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�|�|_dS)N)r�dupr>)rRr>rrrrTPszfile_wrapper.__init__cCs*|jdkrtjd|t|d�|��dS)Nrzunclosed file %r)�source)r>�warnings�warn�ResourceWarningrt)rRrrr�__del__Ss
zfile_wrapper.__del__cGstj|jf|��S)N)rr r>)rRr+rrrrrYszfile_wrapper.recvcGstj|jf|��S)N)rr"r>)rRr+rrrrn\szfile_wrapper.sendNcCs(|tjkr|tjkr|sdStd��dS)Nrz-Only asyncore specific behaviour implemented.)rQrar��NotImplementedError)rR�levelZoptnameZbuflenrrrrb_s


zfile_wrapper.getsockoptcCs(|jdkrdS|j}d|_t�|�dS)Nrr�)r>rrt)rRr>rrrrtjs

zfile_wrapper.closecCs|jS)N)r>)rRrrrr`qszfile_wrapper.fileno)N)rrrrTr�rrrnrbr r"rtr`rrrrr�Ks
r�c@seZdZddd�Zdd�ZdS)�file_dispatcherNcCsPt�|d|�d|_y|��}Wntk
r4YnX|�|�t�|d�dS)NTF)rHrTrNr`�AttributeError�set_filer�set_blocking)rRr>r;rrrrTvs
zfile_dispatcher.__init__cCs"t|�|_|j��|_|��dS)N)r�rQr`rKr])rRr>rrrr��s
zfile_dispatcher.set_file)N)rrrrTr�rrrrr�ts
r�)r0N)r0N)rCFNN)NF).�__doc__r%rQrur8r�r�errnorrrrrrrr	r
rrr
rr�r,r1rr�	Exceptionr�KeyboardInterrupt�
SystemExitrr r"r$r/r?rBZpoll3rGrHr�r�r�rfr�r�rrrr�<module>/sB<


'

,
)