AlkantarClanX12

Your IP : 18.221.68.196


Current Path : /opt/alt/python34/lib64/python3.4/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/__pycache__/asyncore.cpython-34.pyo

�
j fR�@sdZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZeee
eeeef�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!krddl,Z,Gd"d#�d#�Z-Gd$d%�d%e'�Z.ndS)&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/python34/lib64/python3.4/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�yz|tj@r|j�n|tj@r7|j�n|tj@rQ|j�n|tjtjBtj	B@ry|j
�nWnttk
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}n|r�g}g}g}x�t|j��D]v\}}|j�}|j�}|rz|j|�n|r�|jr�|j|�n|s�|r@|j|�q@q@Wg|ko�|ko�|knr�tj|�dSy%t	j	||||�\}}}Wnt
k
r/dSYnXx9|D]1}|j|�}|dkr^q7nt|�q7Wx9|D]1}|j|�}|dkr�qsnt
|�qsWx<|D]1}|j|�}|dkr�q�nt|�q�WndS)N)�
socket_map�list�items�readable�writable�append�	accepting�timeZsleepr%�InterruptedError�getr r"r$)	�timeout�map�r�wr.�fdrZis_rZis_wrrr�poll}sJ	'
%
	


r?cCsK|dkrt}n|dk	r4t|d�}ntj�}|rGx�t|j��D]t\}}d}|j�r�|tjtjBO}n|j	�r�|j
r�|tjO}n|rY|j||�qYqYWy|j|�}Wnt
k
r�g}YnXxE|D]:\}}|j|�}|dkr3qnt||�qWndS)Ni�r)r0�intr%r?r1r2r3r&r(r4r6r'�registerr8r9r/)r:r;Zpollsterr>rr-r<rrr�poll2�s.	
rBg>@FcCs�|dkrt}n|r3ttd�r3t}nt}|dkrbxJ|r^|||�qHWn0x-|r�|dkr�|||�|d}qeWdS)Nr?r�)r0�hasattrr%rBr?)r:Zuse_pollr;�countZpoll_funrrr�loop�s			
rFc@s�eZdZdZdZdZdZdZdZe	dg�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'�Z d(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,dAdB�Z-dS)C�
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|jrX|jd�n|jdk	r�y|jd|j�Wq�tk
r�|jt|j��Yq�Xnddj	|�t
|�fS)N�.Z	listeningrMz%s:%dz<%s at %#x>� )�	__class__rrr6rNr5rM�	TypeError�repr�join�id)rQZstatusrrr�__repr__s	
zdispatcher.__repr__cCs)|dkr|j}n|||j<dS)N)rIrJ)rQr;rrr�add_channelszdispatcher.add_channelcCsD|j}|dkr!|j}n||kr7||=nd|_dS)N)rJrI)rQr;r>rrrrOs	
zdispatcher.del_channelcCs?||f|_tj||�}|jd�|j|�dS)Nr)Zfamily_and_typerPrKrL)rQZfamily�typerRrrr�
create_sockets
zdispatcher.create_socketcCs)||_|j�|_|j|�dS)N)rP�filenorJr\)rQrRr;rrrrL%s	zdispatcher.set_socketcCsRy9|jjtjtj|jjtjtj�dB�Wntk
rMYnXdS)NrC)rPZ
setsockopt�
SOL_SOCKETZSO_REUSEADDR�
getsockoptr*)rQrrr�set_reuse_addr+s	
zdispatcher.set_reuse_addrcCsdS)NTr)rQrrrr3<szdispatcher.readablecCsdS)NTr)rQrrrr4?szdispatcher.writablecCs=d|_tjdkr-|dkr-d}n|jj|�S)NT�nt�)r6r�namerP�listen)rQZnumrrrrfFs		zdispatcher.listencCs||_|jj|�S)N)rNrP�bind)rQrNrrrrgLs	zdispatcher.bindcCs�d|_d|_|jj|�}|tttfksT|tkratj	dkra||_
dS|dtfkr�||_
|j�nt
|t|��dS)NFTrc�cer)zntrh)rM�
connectingrPZ
connect_exrrrrrrerNr	�handle_connect_eventr*r)rQZaddressrrrr�connectPs				
zdispatcher.connectcCs�y|jj�\}}Wn]tk
r1dSYnRtk
rx}z(|jdtttfkrcdS�WYdd}~XnX||fSdS)Nr)rP�acceptrWr*r+rrr
)rQZconnrN�whyrrrrl^s
zdispatcher.acceptcCs�y|jj|�}|SWn`tk
r|}z@|jdtkrFdS|jdtkrg|j�dS�WYdd}~XnXdS)Nr)rP�sendr*r+rr,r))rQ�data�resultrmrrrrnls
zdispatcher.sendcCs~y.|jj|�}|s)|j�dS|SWnItk
ry}z)|jdtkrd|j�dS�WYdd}~XnXdS)N�r)rP�recvr)r*r+r,)rQZbuffer_sizerormrrrrrys

zdispatcher.recvcCs�d|_d|_d|_|j�|jdk	r�y|jj�Wq�tk
r�}z$|jdtt	fkry�nWYdd}~Xq�XndS)NFr)
rMr6rirOrP�closer*r+rr
)rQrmrrrrs�s			
zdispatcher.closec
Cs�yt|j|�}Wn.tk
rFtd|jj|f��Yn9Xdi|jjd6|d6}tj|tdd�|SdS)Nz!%s instance has no attribute '%s'zA%(me)s.%(attr)s is deprecated; use %(me)s.socket.%(attr)s instead�me�attr�
stacklevel�)�getattrrP�AttributeErrorrVr�warnings�warn�DeprecationWarning)rQruZretattr�msgrrr�__getattr__�s
zdispatcher.__getattr__cCstjjdt|��dS)Nzlog: %s
)�sys�stderrr"�str)rQ�messagerrr�log�szdispatcher.log�infocCs*||jkr&td||f�ndS)Nz%s: %s)�ignore_log_types�print)rQr�r]rrr�log_info�szdispatcher.log_infocCsP|jr|j�n6|jsB|jr5|j�n|j�n
|j�dS)N)r6�
handle_acceptrMrirj�handle_read)rQrrrr�s	
		

zdispatcher.handle_read_eventcCs_|jjtjtj�}|dkr?t|t|���n|j�d|_d|_dS)NrTF)	rPrar`�SO_ERRORr*r�handle_connectrMri)rQrrrrrj�s
	zdispatcher.handle_connect_eventcCs=|jr
dS|js/|jr/|j�q/n|j�dS)N)r6rMrirj�handle_write)rQrrrr!�s			zdispatcher.handle_write_eventcCsB|jjtjtj�}|dkr4|j�n
|j�dS)Nr)rPrar`r�r)�handle_expt)rQrrrrr#�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_tracebackrXrZr�r))rQZnil�t�v�tbinfoZ	self_reprrrrr�szdispatcher.handle_errorcCs|jdd�dS)Nz!unhandled incoming priority eventrH)r�)rQrrrr��szdispatcher.handle_exptcCs|jdd�dS)Nzunhandled read eventrH)r�)rQrrrr��szdispatcher.handle_readcCs|jdd�dS)Nzunhandled write eventrH)r�)rQrrrr��szdispatcher.handle_writecCs|jdd�dS)Nzunhandled connect eventrH)r�)rQrrrr��szdispatcher.handle_connectcCs,|j�}|dk	r(|j|�ndS)N)rl�handle_accepted)rQZpairrrrr��szdispatcher.handle_acceptcCs|j�|jdd�dS)Nzunhandled accepted eventrH)rsr�)rQrRrNrrrr�s
zdispatcher.handle_acceptedcCs|jdd�|j�dS)Nzunhandled close eventrH)r�rs)rQrrrr)szdispatcher.handle_close).rrr�debugrMr6ri�closingrN�	frozensetr�rSr[�__str__r\rOrPZAF_INETZSOCK_STREAMr^rLrbr3r4rfrgrkrlrnrrrsr~r�r�rrjr!r#rr�r�r�r�r�r�r)rrrrrG�sN 
	
rGc@sReZdZdddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)�dispatcher_with_sendNcCs tj|||�d|_dS)Nrq)rGrS�
out_buffer)rQrRr;rrrrSszdispatcher_with_send.__init__cCs?d}tj||jdd��}|j|d�|_dS)Nri)rGrnr�)rQZnum_sentrrr�
initiate_sendsz"dispatcher_with_send.initiate_sendcCs|j�dS)N)r�)rQrrrr�sz!dispatcher_with_send.handle_writecCs|jpt|j�S)N)rM�lenr�)rQrrrr4szdispatcher_with_send.writablecCsA|jr#|jdt|��n|j||_|j�dS)Nz
sending %s)r�r�rXr�r�)rQrorrrrn!s	zdispatcher_with_send.send)rrrrSr�r�r4rnrrrrr�s
r�cCs�tj�\}}}g}|s0td��nxD|rv|j|jjj|jjjt|j	�f�|j
}q3W~|d\}}}djdd�|D��}|||f|||fS)Nztraceback does not existrCrUcSsg|]}d|�qS)z
[%s|%s|%s]r)�.0�xrrr�
<listcomp><s	z%compact_traceback.<locals>.<listcomp>���)r�exc_info�AssertionErrorr5�tb_frame�f_code�co_filename�co_namer��	tb_lineno�tb_nextrY)r�r��tbr��fileZfunction�liner�rrrr�+s	
r�cCs�|dkrt}nx�t|j��D]�}y|j�Wq(tk
r�}z'|jdtkrgn|ss�nWYdd}~Xq(tk
r��Yq(|s��nYq(Xq(W|j�dS)Nr)	r0r1�valuesrsr*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>)rQr>rrrrSfszfile_wrapper.__init__cCs4|jdkr&tjd|t�n|j�dS)Nrzunclosed file %r)r>rzr{�ResourceWarningrs)rQrrr�__del__iszfile_wrapper.__del__cGstj|j|�S)N)rr r>)rQr+rrrrrnszfile_wrapper.recvcGstj|j|�S)N)rr"r>)rQr+rrrrnqszfile_wrapper.sendNcCs9|tjkr)|tjkr)|r)dStd��dS)Nrz-Only asyncore specific behaviour implemented.)rPr`r��NotImplementedError)rQ�levelZoptnameZbuflenrrrrats
zfile_wrapper.getsockoptcCs0|jdkrdStj|j�d|_dS)NrrCr�)r>rrs)rQrrrrsszfile_wrapper.closecCs|jS)N)r>)rQrrrr_�szfile_wrapper.fileno)rrrrSr�rrrnrar r"rsr_rrrrr�asr�c@s+eZdZddd�Zdd�ZdS)�file_dispatcherNcCs�tj|d|�d|_y|j�}Wntk
r@YnX|j|�tj|tjd�}|tj	B}tj|tj
|�dS)NTr)rGrSrMr_ry�set_file�fcntlZF_GETFLr�
O_NONBLOCKZF_SETFL)rQr>r;r-rrrrS�s	


zfile_dispatcher.__init__cCs/t|�|_|jj�|_|j�dS)N)r�rPr_rJr\)rQr>rrrr��szfile_dispatcher.set_file)rrrrSr�rrrrr��s
r�)/�__doc__r%rPrr7rzr�errnorrrrrrrr	r
rrr
rr�r,r0rr�	Exceptionr�KeyboardInterrupt�
SystemExitrr r"r$r/r?rBZpoll3rFrGr�r�r�rer�r�r�rrrr�<module>/sBX
*�:'