AlkantarClanX12

Your IP : 3.144.115.125


Current Path : /proc/self/root/opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //proc/self/root/opt/alt/python35/lib64/python3.5/__pycache__/asyncore.cpython-35.pyc



��Yf�N�@s
dZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZeee
eeeeh�ZyeWnek
r�iZYnXdd�ZGdd�de�ZeeefZdd	�Zd
d�Z dd
�Z!dd�Z"dddd�Z#dddd�Z$e$Z%dddddd�Z&Gdd�d�Z'Gdd�de'�Z(dd�Z)dddd �Z*ej+d!kr	Gd"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
CsOytj|�SWn7tttfk
rJ|tkr>t|Sd|SYnXdS)NzUnknown error %s)�os�strerror�
ValueError�
OverflowError�	NameErrorr)�err�r�-/opt/alt/python35/lib64/python3.5/asyncore.py�	_strerrorDsrc@seZdZdS)�ExitNowN)�__name__�
__module__�__qualname__rrrrrLsrcCs;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�yn|tj@r|j�|tj@r1|j�|tj@rH|j�|tjtjBtj	B@rm|j
�Wnttk
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/gc	Cs�|dkrt}|r�g}g}g}x�t|j��D]m\}}|j�}|j�}|rt|j|�|r�|jr�|j|�|s�|r=|j|�q=Wg|ko�|ko�|knr�tj|�dSt	j	||||�\}}}x6|D].}|j
|�}|dkr2qt|�qWx6|D].}|j
|�}|dkrkqGt|�qGWx6|D].}|j
|�}|dkr�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|dkrt}|dk	r.t|d�}tj�}|rxt|j��D]k\}}d}|j�r�|tjtjBO}|j	�r�|j
r�|tjO}|rS|j||�qSW|j|�}x?|D]7\}}|j
|�}|dkrq�t||�q�WdS)Ni�r)r0�intr%r>r1r2r3r&r(r4r6r'�registerr8r/)r9r:Zpollsterr=rr-r;rrr�poll2�s(
rAg>@FcCs�|dkrt}|r0ttd�r0t}nt}|dkr_xJ|r[|||�qEWn0x-|r�|dkr�|||�|d}qbWdS)Nr>r�)r0�hasattrr%rAr>)r9Zuse_pollr:�countZpoll_funrrr�loop�s		
rEc@s�eZdZdZdZdZdZdZdZe	dh�Z
dddd�Zdd�ZeZ
ddd	�Zdd
d�Zejejdd
�Zddd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'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)A�
dispatcherFN�warningcCs�|dkrt|_n	||_d|_|r�|jd�|j||�d|_y|j�|_Wq�tk
r�}z:|j	dt
tfkr�d|_n|j|��WYdd}~Xq�Xn	d|_
dS)NrTF)r0�_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|jrU|jd�|jdk	r�y|jd|j�Wn(tk
r�|jt|j��YnXddj	|�t
|�fS)N�.Z	listeningrLz%s:%dz<%s at %#x>� )�	__class__rrr6rMr5rL�	TypeError�repr�join�id)rPZstatusrrr�__repr__�s	

zdispatcher.__repr__cCs&|dkr|j}|||j<dS)N)rHrI)rPr:rrr�add_channels	zdispatcher.add_channelcCs>|j}|dkr|j}||kr1||=d|_dS)N)rIrH)rPr:r=rrrrNs		zdispatcher.del_channelcCs?||f|_tj||�}|jd�|j|�dS)Nr)Zfamily_and_typerOrJrK)rPZfamily�typerQrrr�
create_sockets
zdispatcher.create_socketcCs)||_|j�|_|j|�dS)N)rO�filenorIr[)rPrQr:rrrrK s	zdispatcher.set_socketcCsRy9|jjtjtj|jjtjtj�dB�Wntk
rMYnXdS)NrB)rOZ
setsockopt�
SOL_SOCKETZSO_REUSEADDR�
getsockoptr*)rPrrr�set_reuse_addr&s	
zdispatcher.set_reuse_addrcCsdS)NTr)rPrrrr37szdispatcher.readablecCsdS)NTr)rPrrrr4:szdispatcher.writablecCs:d|_tjdkr*|dkr*d}|jj|�S)NT�nt�)r6r�namerO�listen)rPZnumrrrreAs	zdispatcher.listencCs||_|jj|�S)N)rMrO�bind)rPrMrrrrfGs	zdispatcher.bindcCs�d|_d|_|jj|�}|tttfksT|tkratj	dkra||_
dS|dtfkr�||_
|j�nt
|t|��dS)NFTrb�cer)rbrg)rL�
connectingrOZ
connect_exrrrrrrdrMr	�handle_connect_eventr*r)rPZaddressrrrr�connectKs				
zdispatcher.connectcCs�y|jj�\}}Wn]tk
r1dSYnRtk
rx}z(|jdtttfkrcdS�WYdd}~XnX||fSdS)Nr)rO�acceptrVr*r+rrr
)rPZconnrM�whyrrrrkYs
zdispatcher.acceptcCs�y|jj|�}|SWn`tk
r|}z@|jdtkrFdS|jdtkrg|j�dS�WYdd}~XnXdS)Nr)rO�sendr*r+rr,r))rP�data�resultrlrrrrmgs
zdispatcher.sendcCs~y.|jj|�}|s)|j�dS|SWnItk
ry}z)|jdtkrd|j�dS�WYdd}~XnXdS)N�r)rO�recvr)r*r+r,)rPZbuffer_sizernrlrrrrqts

zdispatcher.recvcCs�d|_d|_d|_|j�|jdk	r�y|jj�WnAtk
r�}z!|jdtt	fkrv�WYdd}~XnXdS)NFr)
rLr6rhrNrO�closer*r+rr
)rPrlrrrrr�s			
zdispatcher.closecCstjjdt|��dS)Nzlog: %s
)�sys�stderrr"�str)rP�messagerrr�log�szdispatcher.log�infocCs'||jkr#td||f�dS)Nz%s: %s)�ignore_log_types�print)rPrvr\rrr�log_info�szdispatcher.log_infocCsM|jr|j�n3|js?|jr2|j�|j�n
|j�dS)N)r6�
handle_acceptrLrhri�handle_read)rPrrrr�s	
		

zdispatcher.handle_read_eventcCs\|jjtjtj�}|dkr<t|t|���|j�d|_d|_dS)NrTF)	rOr`r_�SO_ERRORr*r�handle_connectrLrh)rPrrrrri�s
	zdispatcher.handle_connect_eventcCs7|jr
dS|js)|jr)|j�|j�dS)N)r6rLrhri�handle_write)rPrrrr!�s			
zdispatcher.handle_write_eventcCsB|jjtjtj�}|dkr4|j�n
|j�dS)Nr)rOr`r_r~r)�handle_expt)rPrrrrr#�s
zdispatcher.handle_expt_eventcCsnt�\}}}}yt|�}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_tracebackrWrYr{r))rPZnil�t�v�tbinfoZ	self_reprrrrr�szdispatcher.handle_errorcCs|jdd�dS)Nz!unhandled incoming priority eventrG)r{)rPrrrr��szdispatcher.handle_exptcCs|jdd�dS)Nzunhandled read eventrG)r{)rPrrrr}�szdispatcher.handle_readcCs|jdd�dS)Nzunhandled write eventrG)r{)rPrrrr��szdispatcher.handle_writecCs|jdd�dS)Nzunhandled connect eventrG)r{)rPrrrr�szdispatcher.handle_connectcCs)|j�}|dk	r%|j|�dS)N)rk�handle_accepted)rPZpairrrrr|�szdispatcher.handle_acceptcCs|j�|jdd�dS)Nzunhandled accepted eventrG)rrr{)rPrQrMrrrr��s
zdispatcher.handle_acceptedcCs|jdd�|j�dS)Nzunhandled close eventrG)r{rr)rPrrrr)�szdispatcher.handle_close)-rrr�debugrLr6rh�closingrM�	frozensetryrRrZ�__str__r[rNrOZAF_INETZSOCK_STREAMr]rKrar3r4rerfrjrkrmrqrrrwr{rrir!r#rr�r}r�rr|r�r)rrrrrF�sL 
	
rFc@sReZdZdddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)�dispatcher_with_sendNcCs tj|||�d|_dS)Nrp)rFrR�
out_buffer)rPrQr:rrrrR�szdispatcher_with_send.__init__cCs?d}tj||jdd��}|j|d�|_dS)Nri)rFrmr�)rPZnum_sentrrr�
initiate_sendsz"dispatcher_with_send.initiate_sendcCs|j�dS)N)r�)rPrrrr�sz!dispatcher_with_send.handle_writecCs|jpt|j�S)N)rL�lenr�)rPrrrr4szdispatcher_with_send.writablecCs>|jr |jdt|��|j||_|j�dS)Nz
sending %s)r�r{rWr�r�)rPrnrrrrms	zdispatcher_with_send.send)rrrrRr�r�r4rmrrrrr��s
r�cCs�tj�\}}}g}|s-td��xD|rs|j|jjj|jjjt|j	�f�|j
}q0W~|d\}}}djdd�|D��}|||f|||fS)Nztraceback does not existrBrTcSsg|]}d|�qS)z
[%s|%s|%s]r)�.0�xrrr�
<listcomp>)s	z%compact_traceback.<locals>.<listcomp>���)rs�exc_info�AssertionErrorr5�tb_frame�f_code�co_filename�co_nameru�	tb_lineno�tb_nextrX)r�r��tbr��fileZfunction�linerxrrrr�s	
r�cCs�|dkrt}x�t|j��D]}y|j�Wq%tk
r}z$|jdtkrdn	|sm�WYdd}~Xq%tk
r��Yq%|s��Yq%Xq%W|j�dS)Nr)	r0r1�valuesrrr*r+r
r�clear)r:Z
ignore_allr�rrr�	close_all,s 
r��posixc@sseZdZdd�Zdd�Zdd�Zdd�Zd	d
d�ZeZeZ	dd
�Z
dd�Zd	S)�file_wrappercCstj|�|_dS)N)r�dupr=)rPr=rrrrRQszfile_wrapper.__init__cCs1|jdkr#tjd|t�|j�dS)Nrzunclosed file %r)r=�warnings�warn�ResourceWarningrr)rPrrr�__del__Tszfile_wrapper.__del__cGstj|j|�S)N)rr r=)rPr+rrrrqYszfile_wrapper.recvcGstj|j|�S)N)rr"r=)rPr+rrrrm\szfile_wrapper.sendNcCs9|tjkr)|tjkr)|r)dStd��dS)Nrz-Only asyncore specific behaviour implemented.)rOr_r~�NotImplementedError)rP�levelZoptnameZbuflenrrrr`_s
zfile_wrapper.getsockoptcCs0|jdkrdStj|j�d|_dS)NrrBr�)r=rrr)rPrrrrrjszfile_wrapper.closecCs|jS)N)r=)rPrrrr^pszfile_wrapper.fileno)rrrrRr�rqrmr`r r"rrr^rrrrr�Lsr�c@s+eZdZddd�Zdd�ZdS)�file_dispatcherNcCsbtj|d|�d|_y|j�}Wntk
r@YnX|j|�tj|d�dS)NTF)rFrRrLr^�AttributeError�set_filer�set_blocking)rPr=r:rrrrRus	

zfile_dispatcher.__init__cCs/t|�|_|jj�|_|j�dS)N)r�rOr^rIr[)rPr=rrrr��szfile_dispatcher.set_file)rrrrRr�rrrrr�ssr�).�__doc__r%rOrsr7r�r�errnorrrrrrrr	r
rrr
rr�r,r0rr�	Exceptionr�KeyboardInterrupt�
SystemExitrr r"r$r/r>rAZpoll3rErFr�r�r�rdr�r�rrrr�<module>/s@X
'�,'