Hacked By AnonymousFox

Current Path : /usr/lib64/python3.6/__pycache__/
Upload File :
Current File : //usr/lib64/python3.6/__pycache__/asyncore.cpython-36.pyc

3


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



r/�c	CsN|dkrt}|�rJg}g}g}x^t|j��D]N\}}|j�}|j�}|rR|j|�|rh|jrh|j|�|sp|r,|j|�q,Wg|ko�|ko�|knr�tj|�dSt	j	||||�\}}}x(|D] }|j
|�}|dkr�q�t|�q�Wx*|D]"}|j
|�}|dk�rq�t|�q�Wx.|D]&}|j
|�}|dk�r<�q t
|��q WdS)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�}tj�}|r�x^t|j��D]N\}}d}|j�r^|tjtjBO}|j	�rx|j
rx|tjO}|r:|j||�q:W|j|�}x.|D]&\}}|j
|�}|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�warningcCs�|dkrt|_n||_d|_|r�|jd�|j||�d|_y|j�|_Wq�tk
r�}z,|j	dt
tfkrvd|_n|j|��WYdd}~Xq�Xnd|_
dS)NrTF)r1�_map�_fileno�setblocking�
set_socket�	connectedZgetpeername�addrr*r+rr�del_channel�socket)�self�sockr;rrrr�__init__�s 

zdispatcher.__init__cCs�|jjd|jjg}|jr.|jr.|jd�n|jr>|jd�|jdk	r�y|jd|j�Wn$tk
r�|jt|j��YnXddj	|�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|_tj||�}|jd�|j|�dS)Nr)Zfamily_and_typerQrLrM)rRZfamily�typerSrrr�
create_sockets

zdispatcher.create_socketcCs||_|j�|_|j|�dS)N)rQ�filenorKr])rRrSr;rrrrM s
zdispatcher.set_socketcCsDy*|jjtjtj|jjtjtj�dB�Wntk
r>YnXdS)NrD)rQZ
setsockopt�
SOL_SOCKETZSO_REUSEADDR�
getsockoptr*)rRrrr�set_reuse_addr&s
zdispatcher.set_reuse_addrcCsdS)NTr)rRrrrr47szdispatcher.readablecCsdS)NTr)rRrrrr5:szdispatcher.writablecCs(d|_tjdkr|dkrd}|jj|�S)NT�nt�)r7r�namerQ�listen)rRZnumrrrrgAszdispatcher.listencCs||_|jj|�S)N)rOrQ�bind)rRrOrrrrhGszdispatcher.bindcCspd|_d|_|jj|�}|tttfks8|tkrBtj	dkrB||_
dS|dtfkr^||_
|j�nt
|t|��dS)NFTrdr)rN�
connectingrQZ
connect_exrrrrrrfrOr	�handle_connect_eventr*r)rRZaddressrrrr�connectKs
zdispatcher.connectcCsny|jj�\}}WnNtk
r&dStk
r`}z |jdtttfkrNdS�WYdd}~Xn
X||fSdS)Nr)rQ�acceptrXr*r+rrr
)rRZconnrO�whyrrrrlYszdispatcher.acceptcCsfy|jj|�}|Stk
r`}z4|jdtkr4dS|jdtkrN|j�dS�WYdd}~XnXdS)Nr)rQ�sendr*r+rr,r))rR�data�resultrmrrrrngszdispatcher.sendcCshy$|jj|�}|s|j�dS|SWn>tk
rb}z"|jdtkrP|j�dS�WYdd}~XnXdS)N�r)rQ�recvr)r*r+r,)rR�buffer_sizerormrrrrrtszdispatcher.recvcCsnd|_d|_d|_|j�|jdk	rjy|jj�Wn6tk
rh}z|jdtt	fkrX�WYdd}~XnXdS)NFr)
rNr7rirPrQ�closer*r+rr
)rRrmrrrrt�s
zdispatcher.closecCstjjdt|��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|j�n&|js.|jr$|j�|j�n|j�dS)N)r7�
handle_acceptrNrirj�handle_read)rRrrrr�s

zdispatcher.handle_read_eventcCs@|jjtjtj�}|dkr(t|t|���|j�d|_d|_dS)NrTF)	rQrbra�SO_ERRORr*r�handle_connectrNri)rRrrrrrj�szdispatcher.handle_connect_eventcCs*|jr
dS|js|jr|j�|j�dS)N)r7rNrirj�handle_write)rRrrrr!�szdispatcher.handle_write_eventcCs0|jjtjtj�}|dkr$|j�n|j�dS)Nr)rQrbrar�r)�handle_expt)rRrrrrr#�s
zdispatcher.handle_expt_eventcCsXt�\}}}}yt|�}Wndt|�}YnX|jd||||fd�|j�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|jdd�dS)Nz!unhandled incoming priority eventrI)r})rRrrrr��szdispatcher.handle_exptcCs|jdd�dS)Nzunhandled read eventrI)r})rRrrrr�szdispatcher.handle_readcCs|jdd�dS)Nzunhandled write eventrI)r})rRrrrr��szdispatcher.handle_writecCs|jdd�dS)Nzunhandled connect eventrI)r})rRrrrr��szdispatcher.handle_connectcCs|j�}|dk	r|j|�dS)N)rl�handle_accepted)rRZpairrrrr~�szdispatcher.handle_acceptcCs|j�|jdd�dS)Nzunhandled accepted eventrI)rtr})rRrSrOrrrr��szdispatcher.handle_acceptedcCs|jdd�|j�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_sendNcCstj|||�d|_dS)Nrq)rHrT�
out_buffer)rRrSr;rrrrT�szdispatcher_with_send.__init__cCs.d}tj||jdd��}|j|d�|_dS)Nri)rHrnr�)rRZnum_sentrrr�
initiate_sendsz"dispatcher_with_send.initiate_sendcCs|j�dS)N)r�)rRrrrr�sz!dispatcher_with_send.handle_writecCs|jpt|j�S)N)rN�lenr�)rRrrrr5szdispatcher_with_send.writablecCs0|jr|jdt|��|j||_|j�dS)Nz
sending %s)r�r}rYr�r�)rRrorrrrnszdispatcher_with_send.send)NN)rrrrTr�r�r5rnrrrrr��s

r�cCs�tj�\}}}g}|std��x0|rN|j|jjj|jjjt|j	�f�|j
}q W~|d\}}}djdd�|D��}|||f|||fS)Nztraceback does not existrDrVcSsg|]}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|j��D]n}y|j�Wqtk
rb}z|jdtkrLn|sR�WYdd}~Xqtk
rv�Yq|s��YqXqW|j�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_wrappercCstj|�|_dS)N)r�dupr>)rRr>rrrrTQszfile_wrapper.__init__cCs*|jdkrtjd|t|d�|j�dS)Nrzunclosed file %r)�source)r>�warnings�warn�ResourceWarningrt)rRrrr�__del__Ts
zfile_wrapper.__del__cGstj|jf|��S)N)rr r>)rRr+rrrrrZszfile_wrapper.recvcGstj|jf|��S)N)rr"r>)rRr+rrrrn]szfile_wrapper.sendNcCs*|tjkr|tjkr|rdStd��dS)Nrz-Only asyncore specific behaviour implemented.)rQrar��NotImplementedError)rR�levelZoptnameZbuflenrrrrb`s


zfile_wrapper.getsockoptcCs(|jdkrdS|j}d|_tj|�dS)NrrDr�)r>rrt)rRr>rrrrtks

zfile_wrapper.closecCs|jS)N)r>)rRrrrr`rszfile_wrapper.fileno)N)rrrrTr�rrrnrbr r"rtr`rrrrr�Ls
r�c@seZdZddd�Zdd�ZdS)�file_dispatcherNcCsPtj|d|�d|_y|j�}Wntk
r4YnX|j|�tj|d�dS)NTF)rHrTrNr`�AttributeError�set_filer�set_blocking)rRr>r;rrrrTws
zfile_dispatcher.__init__cCs"t|�|_|jj�|_|j�dS)N)r�rQr`rKr])rRr>rrrr��s
zfile_dispatcher.set_file)N)rrrrTr�rrrrr�us
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<


'

-
)

Hacked By AnonymousFox1.0, Coded By AnonymousFox