HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: //lib/python3.6/site-packages/supervisor/medusa/__pycache__/asynchat_25.cpython-36.opt-1.pyc
3

�k�`L*�@sjdZddlZddlmZddlmZddlmZGdd�dej�Z	Gdd	�d	�Z
Gd
d�d�Zdd
�ZdS)a�A class supporting chat-style (command/response) protocols.

This class adds support for 'chat' style protocols - where one side
sends a 'command', and the other sends a response (examples would be
the common internet protocols - smtp, nntp, ftp, etc..).

The handle_read() method looks at the input stream for the current
'terminator' (usually '\r\n' for single-line responses, '\r\n.\r\n'
for multi-line output), calling self.found_terminator() on its
receipt.

for example:
Say you build an async nntp client using this class.  At the start
of the connection, you'll have self.terminator set to '\r\n', in
order to process the single-line greeting.  Just before issuing a
'LIST' command you'll set it to '\r\n.\r\n'.  The output of the LIST
command will be accumulated (using your own 'collect_incoming_data'
method) up to the terminator, and then control will be returned to
you - by calling your self.found_terminator() method.
�N)�asyncore_25)�long)�as_bytesc@s�eZdZdZdZdZd$dd�Zdd�Zdd	�Zd
d�Z	dd
�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�ZdS)%�
async_chatz�This is an abstract class.  You must derive from this class, and add
    the two methods collect_incoming_data() and found_terminator()iNcCs(d|_d|_t�|_tjj|||�dS)N�)�ac_in_buffer�
ac_out_buffer�fifo�
producer_fifo�asyncore�
dispatcher�__init__)�selfZconn�map�r�!/usr/lib/python3.6/asynchat_25.pyr
?szasync_chat.__init__cCstd��dS)Nzmust be implemented in subclass)�NotImplementedError)r�datarrr�collect_incoming_dataEsz async_chat.collect_incoming_datacCstd��dS)Nzmust be implemented in subclass)r)rrrr�found_terminatorHszasync_chat.found_terminatorcCs
||_dS)zRSet the input delimiter.  Can be a fixed string of any length, an integer, or NoneN)�
terminator)rZtermrrr�set_terminatorKszasync_chat.set_terminatorcCs|jS)N)r)rrrr�get_terminatorOszasync_chat.get_terminatorcCs�y|j|j�}Wntjk
r.|j�dSX|j|7_�x`|j�r�t|j�}|j�}|st|j|j�d|_qBt	|t
�s�t	|t�r�|}||kr�|j|j�d|_|j|8_n2|j|jd|��|j|d�|_d|_|j
�qBt|�}|jj|�}|dk�rD|dk�r&|j|jd|��|j||d�|_|j
�qBt|j|�}|�r�||k�r�|j|jd|��|j|d�|_PqB|j|j�d|_qBWdS)Nrr����)Zrecv�ac_in_buffer_size�socket�error�handle_errorr�lenrr�
isinstance�intrrr�find�find_prefix_at_end)rrZlbr�nZterminator_len�indexrrr�handle_readWsJ

	



zasync_chat.handle_readcCs|j�dS)N)�
initiate_send)rrrr�handle_write�szasync_chat.handle_writecCs|j�dS)N)�close)rrrr�handle_close�szasync_chat.handle_closecCs$t|�}|jjt|��|j�dS)N)rr
�push�simple_producerr')rrrrrr+�szasync_chat.pushcCs|jj|�|j�dS)N)r
r+r')rZproducerrrr�push_with_producer�szasync_chat.push_with_producercCst|j�|jkS)z4predicate for inclusion in the readable for select())rrr)rrrr�readable�szasync_chat.readablecCs|jdko|jj�o|jS)z4predicate for inclusion in the writable for select()r)rr
�is_empty�	connected)rrrr�writable�s

zasync_chat.writablecCs|jjd�dS)zAautomatically close this channel once the outgoing queue is emptyN)r
r+)rrrr�close_when_done�szasync_chat.close_when_donecCs�x�t|j�r�|jj�}|dkr:|js6|jj�|j�dSt|t�r`|jj�|j|7_dS|j�}|r||j||_dS|jj�qdSqWdS)N)	rr
�firstr�popr)r �bytes�more)r�prrrr�
refill_buffer�s$




zasync_chat.refill_buffercCsx|j}t|j�|kr|j�|jrt|jrty,|j|jd|��}|rR|j|d�|_Wntjk
rr|j�dSXdS)N)	�ac_out_buffer_sizerrr8r0�sendrrr)rZobsZnum_sentrrrr'�szasync_chat.initiate_sendcCs&d|_d|_x|jr |jj�qWdS)Nr)rrr
r4)rrrr�discard_buffers�szasync_chat.discard_buffers)NN)�__name__�
__module__�__qualname__�__doc__rr9r
rrrrr&r(r*r+r-r.r1r2r8r'r;rrrrr6s&
A
rc@seZdZddd�Zdd�ZdS)r,�cCs||_||_dS)N)r�buffer_size)rrrArrrr
�szsimple_producer.__init__cCsJt|j�|jkr6|jd|j�}|j|jd�|_|S|j}d|_|SdS)Nr)rrrA)r�resultrrrr6�szsimple_producer.moreN)r@)r<r=r>r
r6rrrrr,�s
r,c@s>eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)r	NcCs|sg|_n||_dS)N)�list)rrCrrrr
�sz
fifo.__init__cCs
t|j�S)N)rrC)rrrr�__len__szfifo.__len__cCs
|jgkS)N)rC)rrrrr/sz
fifo.is_emptycCs
|jdS)Nr)rC)rrrrr3	sz
fifo.firstcCs|jj|�dS)N)rC�append)rrrrrr+sz	fifo.pushcCs|jrd|jjd�fSdSdS)Nrr)rN)rCr4)rrrrr4szfifo.pop)N)	r<r=r>r
rDr/r3r+r4rrrrr	�s
r	cCs6t|�d}x$|r0|j|d|��r0|d8}qW|S)Nr)r�endswith)ZhaystackZneedle�lrrrr#$sr#)
r?rZsupervisor.medusarrZsupervisor.compatrrrrr,r	r#rrrr�<module>/s7(