Your IP : 18.117.104.132


Current Path : /opt/alt/python310/lib64/python3.10/__pycache__/
Upload File :
Current File : //opt/alt/python310/lib64/python3.10/__pycache__/asyncore.cpython-310.opt-1.pyc

o

6��f,O�@sxdZddlZddlZddlZddlZddlZddlZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZmZmZmZmZejdedd�eee
eeeeh�ZzeWneyYiZYnwdd�ZGd	d
�d
e�ZeeefZ dd�Z!d
d�Z"dd�Z#dd�Z$d)dd�Z%d)dd�Z&e&Z'd*dd�Z(Gdd�d�Z)Gdd�de)�Z*d d!�Z+d+d"d#�Z,ej-d$kr�Gd%d&�d&�Z.Gd'd(�d(e)�Z/dSdS),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�	errorcodezlThe asyncore module is deprecated and will be removed in Python 3.12. The recommended replacement is asyncio�)�
stacklevelc
CsBzt�|�WStttfy |tvrt|YSd|YSw)NzUnknown error %s)�os�strerror�
ValueError�
OverflowError�	NameErrorr)�err�r�//opt/alt/python310/lib64/python3.10/asyncore.py�	_strerrorKs�rc@seZdZdS)�ExitNowN)�__name__�
__module__�__qualname__rrrrrSsrcC�2z|��WdSty�|��YdS�N)�handle_read_event�_reraised_exceptions�handle_error��objrrr�readX�r%cCrr)�handle_write_eventr!r"r#rrr�write`r&r(cCrr)�handle_expt_eventr!r"r#rrr�
_exceptionhr&r*c
Cs�z0|tj@r
|��|tj@r|��|tj@r|��|tjtjBtj	B@r.|�
�WdSWdStyX}z|jt
vrB|��n|�
�WYd}~dSWYd}~dSd}~wty_�|��YdSr)�select�POLLINr �POLLOUTr'�POLLPRIr)ZPOLLHUPZPOLLERRZPOLLNVAL�handle_close�OSError�errno�
_DISCONNECTEDr"r!)r$�flags�errr�	readwriteps(


�

��r5�c	Cs6|durt}|r�g}g}g}t|���D]&\}}|��}|��}|r'|�|�|r1|js1|�|�|s5|r:|�|�qg|krJ|krJ|krSnnt�|�dSt	�	||||�\}}}|D]}|�
|�}|durlq`t|�q`|D]}|�
|�}|durqst|�qs|D]}|�
|�}|dur�q�t
|�q�dSdSr)�
socket_map�list�items�readable�writable�append�	accepting�time�sleepr+�getr%r(r*)	�timeout�map�r�wr4�fdr$Zis_rZis_wrrr�poll�sF



�"






�rFcCs�|durt}|durt|d�}t��}|r^t|���D]&\}}d}|��r.|tjtjBO}|�	�r:|j
s:|tjO}|rB|�||�q|�|�}|D]\}}|�
|�}|durXqJt||�qJdSdS)Ni�r)r7�intr+rFr8r9r:r,r.r;r=r-�registerr@r5)rArBZpollsterrEr$r3rCrrr�poll2�s.
�

�rI�>@FcCs�|durt}|rttd�rt}nt}|dur#|r!|||�|sdSdS|r:|dkr>|||�|d}|r<|dks)dSdSdSdS)NrFr�)r7�hasattrr+rIrF)rAZuse_pollrB�countZpoll_funrrr�loop�s
�
�rNc@s2eZdZdZdZdZdZdZdZe	dh�Z
dAdd�Zdd�ZdBdd	�Z
dBd
d�Zejejfdd
�ZdBdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�ZdCd'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)D�
dispatcherFN�warningc
Cs�|durt|_n||_d|_|rK|�d�|�||�d|_z|��|_WdStyJ}z|j	t
tfvr9d|_n|�|��WYd}~dSd}~wwd|_
dS)NFT)r7�_map�_fileno�setblocking�
set_socket�	connectedZgetpeername�addrr0r1rr�del_channel�socket)�self�sockrBrrrr�__init__�s&

���
zdispatcher.__init__cCs�|jjd|jjg}|jr|jr|�d�n|jr|�d�|jdur@z
|�d|j�Wnty?|�t|j��Ynwdd�	|�t
|�fS)N�.Z	listeningrUz%s:%dz<%s at %#x>� )�	__class__rrr=rVr<rU�	TypeError�repr�join�id)rYZstatusrrr�__repr__s

�zdispatcher.__repr__cCs|dur|j}|||j<dSr)rQrR)rYrBrrr�add_channelszdispatcher.add_channelcCs,|j}|dur
|j}||vr||=d|_dSr)rRrQ)rYrBrErrrrWs
zdispatcher.del_channelcCs.||f|_t�||�}|�d�|�|�dS�NF)Zfamily_and_typerXrSrT)rYZfamily�typerZrrr�
create_sockets

zdispatcher.create_socketcCs||_|��|_|�|�dSr)rX�filenorRrd�rYrZrBrrrrT%s
zdispatcher.set_socketcCsBz|j�tjtj|j�tjtj�dB�WdSty YdSw)NrK)rXZ
setsockopt�
SOL_SOCKETZSO_REUSEADDR�
getsockoptr0�rYrrr�set_reuse_addr*s
��
��zdispatcher.set_reuse_addrcC�dS�NTrrlrrrr:;�zdispatcher.readablecCrnrorrlrrrr;>rpzdispatcher.writablecCs(d|_tjdkr|dkrd}|j�|�S)NT�nt�)r=r�namerX�listen)rYZnumrrrrtEszdispatcher.listencCs||_|j�|�Sr)rVrX�bind)rYrVrrrruKszdispatcher.bindcCsnd|_d|_|j�|�}|tttfvs|tkr!tj	dkr!||_
dS|dtfvr0||_
|��dSt
|t|��)NFTrqr)rU�
connectingrXZ
connect_exrrrrrrsrVr	�handle_connect_eventr0r)rYZaddressrrrr�connectOszdispatcher.connectc
Csdz|j��\}}W||fStyYdSty1}z|jtttfvr,WYd}~dS�d}~wwr)rX�acceptr_r0r1rrr
)rYZconnrV�whyrrrry]s	���zdispatcher.acceptc
Csfz	|j�|�}|WSty2}z|jtkrWYd}~dS|jtvr-|��WYd}~dS�d}~ww�Nr)rX�sendr0r1rr2r/)rY�data�resultrzrrrr|ks

��zdispatcher.sendc
Cs`z|j�|�}|s|��WdS|WSty/}z|jtvr*|��WYd}~dS�d}~ww�N�)rX�recvr/r0r1r2)rYZbuffer_sizer}rzrrrr�xs
��zdispatcher.recvc
Cspd|_d|_d|_|��|jdur6z|j��WdSty5}z|jtt	fvr*�WYd}~dSd}~wwdSre)
rUr=rvrWrX�closer0r1rr
)rYrzrrrr��s
����zdispatcher.closecCstj�dt|��dS)Nzlog: %s
)�sys�stderrr(�str)rY�messagerrr�log�szdispatcher.log�infocCs"||jvrtd||f�dSdS)Nz%s: %s)�ignore_log_types�print)rYr�rfrrr�log_info�s
�zdispatcher.log_infocCs>|jr	|��dS|js|jr|��|��dS|��dSr)r=�
handle_acceptrUrvrw�handle_readrlrrrr �szdispatcher.handle_read_eventcCs@|j�tjtj�}|dkrt|t|���|��d|_d|_dS)NrTF)	rXrkrj�SO_ERRORr0r�handle_connectrUrv�rYrrrrrw�s
zdispatcher.handle_connect_eventcCs*|jrdS|js|jr|��|��dSr)r=rUrvrw�handle_writerlrrrr'�szdispatcher.handle_write_eventcCs2|j�tjtj�}|dkr|��dS|��dSr{)rXrkrjr�r/�handle_exptr�rrrr)�szdispatcher.handle_expt_eventcCsTt�\}}}}zt|�}Wn
dt|�}Y|�d||||fd�|��dS)Nz)<__repr__(self) failed for object at %0x>z:uncaptured python exception, closing channel %s (%s:%s %s)�error)�compact_tracebackr`rbr�r/)rYZnil�t�v�tbinfoZ	self_reprrrrr"�s��	zdispatcher.handle_errorcC�|�dd�dS)Nz!unhandled incoming priority eventrP�r�rlrrrr���zdispatcher.handle_exptcCr�)Nzunhandled read eventrPr�rlrrrr��r�zdispatcher.handle_readcCr�)Nzunhandled write eventrPr�rlrrrr��r�zdispatcher.handle_writecCr�)Nzunhandled connect eventrPr�rlrrrr��r�zdispatcher.handle_connectcCs"|��}|dur|j|�dSdSr)ry�handle_accepted)rYZpairrrrr��s�zdispatcher.handle_acceptcCs|��|�dd�dS)Nzunhandled accepted eventrP)r�r�)rYrZrVrrrr��szdispatcher.handle_acceptedcCs|�dd�|��dS)Nzunhandled close eventrP)r�r�rlrrrr/�szdispatcher.handle_close�NNr)r�),rrr�debugrUr=rv�closingrV�	frozensetr�r[rcrdrWrXZAF_INETZSOCK_STREAMrgrTrmr:r;rtrurxryr|r�r�r�r�r rwr'r)r"r�r�r�r�r�r�r/rrrrrO�sL

 

	


rOc@s6eZdZddd�Zdd�Zdd�Zdd	�Zd
d�ZdS)
�dispatcher_with_sendNcCst�|||�d|_dSr)rOr[�
out_bufferrirrrr[s
zdispatcher_with_send.__init__cCs.d}t�||jdd��}|j|d�|_dS)Nri)rOr|r�)rYZnum_sentrrr�
initiate_sendsz"dispatcher_with_send.initiate_sendcCs|��dSr)r�rlrrrr�sz!dispatcher_with_send.handle_writecCs|jpt|j�Sr)rU�lenr�rlrrrr;szdispatcher_with_send.writablecCs0|jr|�dt|��|j||_|��dS)Nz
sending %s)r�r�r`r�r�)rYr}rrrr|szdispatcher_with_send.sendr�)rrrr[r�r�r;r|rrrrr�s
r�cCs�t��\}}}g}|std��|r'|�|jjj|jjjt|j	�f�|j
}|s~|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�AssertionErrorr<�tb_frame�f_code�co_filename�co_namer��	tb_lineno�tb_nextra)r�r��tbr��fileZfunction�liner�rrrr�s ��	r�cCs�|durt}t|���D]1}z|��Wqty/}z|jtkr"n|s%�WYd}~qd}~wty6�|s<�Yq|��dSr)	r7r8�valuesr�r0r1r
r!�clear)rBZ
ignore_allr�rrr�	close_all0s$
��r��posixc@sNeZdZdd�Zdd�Zdd�Zdd�Zdd
d�ZeZeZ	dd
�Z
dd�Zd	S)�file_wrappercCst�|�|_dSr)r�duprE�rYrErrrr[Ur�zfile_wrapper.__init__cCs*|jdkrtjd|t|d�|��dS)Nrzunclosed file %r)�source)rE�warnings�warn�ResourceWarningr�rlrrr�__del__Xs

�zfile_wrapper.__del__cG�tj|jg|�R�Sr)rr%rE�rY�argsrrrr�^�zfile_wrapper.recvcGr�r)rr(rEr�rrrr|ar�zfile_wrapper.sendNcCs$|tjkr|tjkr|sdStd��)Nrz-Only asyncore specific behaviour implemented.)rXrjr��NotImplementedError)rY�levelZoptnameZbuflenrrrrkds

�zfile_wrapper.getsockoptcCs(|jdkrdS|j}d|_t�|�dS)Nrr�)rErr�r�rrrr�os

zfile_wrapper.closecCs|jSr)rErlrrrrhvszfile_wrapper.filenor)rrrr[r�r�r|rkr%r(r�rhrrrrr�Ps
r�c@seZdZddd�Zdd�ZdS)�file_dispatcherNcCsNt�|d|�d|_z|��}Wn	tyYnw|�|�t�|d�dS)NTF)rOr[rUrh�AttributeError�set_filer�set_blocking)rYrErBrrrr[{s�
zfile_dispatcher.__init__cCs"t|�|_|j��|_|��dSr)r�rXrhrRrdr�rrrr��s
zfile_dispatcher.set_filer)rrrr[r�rrrrr�ys
r�)r6N)rJFNNre)0�__doc__r+rXr�r>r�rr1rrrrrrrr	r
rrr
rr��DeprecationWarningr�r2r7rr�	Exceptionr�KeyboardInterrupt�
SystemExitr!r%r(r*r5rFrIZpoll3rNrOr�r�r�rsr�r�rrrr�<module>sT<���


'
*

)�

?>