AlkantarClanX12

Your IP : 3.141.29.90


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/asynchat.cpython-35.opt-1.pyc



��Yf�.�@sqdZddlZddlmZGdd�dej�ZGdd�d�ZGdd	�d	�Zd
d�ZdS)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)�dequec@seZdZdZdZdZdZdZdddd�Zdd	�Z	d
d�Z
dd
�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�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()irzlatin-1NcCs8d|_g|_t�|_tjj|||�dS)N�)�ac_in_buffer�incomingr�
producer_fifo�asyncore�
dispatcher�__init__)�selfZsock�map�r
�-/opt/alt/python35/lib64/python3.5/asynchat.pyr
Cs		zasync_chat.__init__cCstd��dS)Nzmust be implemented in subclass)�NotImplementedError)r�datar
r
r�collect_incoming_dataQsz async_chat.collect_incoming_datacCs|jj|�dS)N)r�append)rrr
r
r�_collect_incoming_dataTsz!async_chat._collect_incoming_datacCs&dj|j�}|jdd�=|S)Nr)�joinr)r�dr
r
r�	_get_dataWszasync_chat._get_datacCstd��dS)Nzmust be implemented in subclass)r)rr
r
r�found_terminator\szasync_chat.found_terminatorcCsat|t�r-|jr-t||j�}n't|t�rT|dkrTtd��||_dS)zdSet the input delimiter.

        Can be a fixed string of any length, an integer, or None.
        rz-the number of received bytes must be positiveN)�
isinstance�str�use_encoding�bytes�encoding�int�
ValueError�
terminator)rZtermr
r
r�set_terminator_s
zasync_chat.set_terminatorcCs|jS)N)r)rr
r
r�get_terminatorjszasync_chat.get_terminatorcCsiy|j|j�}WnHtk
r.dSYn3tk
r`}z|j�dSWYdd}~XnXt|t�r�|jr�tt|j	�}|j
||_
x�|j
rdt|j
�}|j�}|s�|j
|j
�d|_
q�t|t�rw|}||kr1|j
|j
�d|_
|j||_qa|j
|j
d|��|j
|d�|_
d|_|j�q�t|�}|j
j|�}|dkr�|dkr�|j
|j
d|��|j
||d�|_
|j�q�t|j
|�}|rH||krD|j
|j
d|��|j
|d�|_
Pq�|j
|j
�d|_
q�WdS)Nrr����)Zrecv�ac_in_buffer_size�BlockingIOError�OSError�handle_errorrrrrrr�lenr!rrrr�find�find_prefix_at_end)rrZwhyZlbr�nZterminator_len�indexr
r
r�handle_readrsR

		
	
zasync_chat.handle_readcCs|j�dS)N)�
initiate_send)rr
r
r�handle_write�szasync_chat.handle_writecCs|j�dS)N)�close)rr
r
r�handle_close�szasync_chat.handle_closecCs�t|tttf�s-tdt|���|j}t|�|kr�xQtdt|�|�D]$}|j	j
||||��qaWn|j	j
|�|j�dS)Nz#data argument must be byte-ish (%r)r)rr�	bytearray�
memoryview�	TypeError�type�ac_out_buffer_sizer(�rangerrr.)rrZsabs�ir
r
r�push�s	%zasync_chat.pushcCs|jj|�|j�dS)N)rrr.)rZproducerr
r
r�push_with_producer�szasync_chat.push_with_producercCsdS)z4predicate for inclusion in the readable for select()r"r
)rr
r
r�readable�szasync_chat.readablecCs|jp|jS)z4predicate for inclusion in the writable for select())r�	connected)rr
r
r�writable�szasync_chat.writablecCs|jjd�dS)zAautomatically close this channel once the outgoing queue is emptyN)rr)rr
r
r�close_when_done�szasync_chat.close_when_donecCsgx`|jrb|jrb|jd}|sL|jd=|dkrL|j�dS|j}y|d|�}WnDtk
r�|j�}|r�|jj|�n
|jd=wYnXt|t�r�|j	r�t
||j�}y|j|�}Wn t
k
r|j�dSYnX|r^|t|�ks:|t|�krT||d�|jd<n
|jd=dSWdS)Nr)rr<r1r6r4�more�
appendleftrrrrr�sendr&r'r()r�firstZobsrZnum_sentr
r
rr.�s8


	



	$
zasync_chat.initiate_sendcCs*d|_|jdd�=|jj�dS)Nr)rrr�clear)rr
r
r�discard_bufferss	zasync_chat.discard_buffers)�__name__�
__module__�__qualname__�__doc__r$r6rrr
rrrrr r!r-r/r1r9r:r;r=r>r.rDr
r
r
rr4s,H(rc@s+eZdZddd�Zdd�ZdS)�simple_producericCs||_||_dS)N)r�buffer_size)rrrJr
r
rr
s	zsimple_producer.__init__cCset|j�|jkrK|jd|j�}|j|jd�|_|S|j}d|_|SdS)Nr)r(rrJ)r�resultr
r
rr?s		zsimple_producer.moreN)rErFrGr
r?r
r
r
rrIsrIc@s[eZdZddd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�ZdS)�fifoNcCsJddl}|jdtdd�|s7t�|_nt|�|_dS)Nrz(fifo class will be removed in Python 3.6�
stacklevel�)�warnings�warn�DeprecationWarningr�list)rrRrOr
r
rr
!s	
z
fifo.__init__cCs
t|j�S)N)r(rR)rr
r
r�__len__*szfifo.__len__cCs|jS)N)rR)rr
r
r�is_empty-sz
fifo.is_emptycCs|jdS)Nr)rR)rr
r
rrB0sz
fifo.firstcCs|jj|�dS)N)rRr)rrr
r
rr93sz	fifo.pushcCs$|jrd|jj�fSdSdS)Nr"r)rN)rR�popleft)rr
r
r�pop6s	zfifo.pop)	rErFrGr
rSrTrBr9rVr
r
r
rrL s	rLcCsEt|�d}x.|r@|j|d|��r@|d8}qW|S)Nr")r(�endswith)ZhaystackZneedle�lr
r
rr*Ls#r*)	rHr�collectionsrr	rrIrLr*r
r
r
r�<module>/s�,