ronnie
2022-10-14 1504bb53e29d3d46222c0b3ea994fc494b48e153
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
K\¬Qc@s dZddlZddlZddlmZddlmZddlmZm    Z    dej
fd„ƒYZ dd d    „ƒYZ d
dd „ƒYZ d „ZdS(s¥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.
iÿÿÿÿN(tdeque(t py3kwarning(tfilterwarningstcatch_warningst
async_chatcBs¹eZdZdZdZddd„Zd„Zd„Zd„Z    d„Z
d„Z d„Z d    „Z d
„Zd „Zd „Zd „Zd„Zd„Zd„Zd„Zd„ZRS(s‡This is an abstract class.  You must derive from this class, and add
    the two methods collect_incoming_data() and found_terminator()icCs8d|_g|_tƒ|_tjj|||ƒdS(Nt(t ac_in_buffertincomingRt producer_fifotasyncoret
dispatchert__init__(tselftsocktmap((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyR @s         cCstdƒ‚dS(Nsmust be implemented in subclass(tNotImplementedError(R tdata((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytcollect_incoming_dataQscCs|jj|ƒdS(N(Rtappend(R R((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyt_collect_incoming_dataTscCsdj|jƒ}|j2|S(NR(tjoinR(R td((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyt    _get_dataWscCstdƒ‚dS(Nsmust be implemented in subclass(R(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytfound_terminator\scCs ||_dS(sRSet the input delimiter.  Can be a fixed string of any length, an integer, or NoneN(t
terminator(R tterm((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytset_terminator_scCs|jS(N(R(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytget_terminatorcscCs    y|j|jƒ}Wn!tjk
r9}|jƒdSX|j||_x¸|jrt|jƒ}|jƒ}|s“|j|jƒd|_qMt    |t
ƒs±t    |t ƒr)|}||krï|j|jƒd|_|j ||_ q|j|j| ƒ|j||_d|_ |j ƒqMt|ƒ}|jj|ƒ}|dkr—|dkrv|j|j| ƒn|j|||_|j ƒqMt|j|ƒ}|rè||krä|j|j|  ƒ|j| |_nPqM|j|jƒd|_qMWdS(NRiiÿÿÿÿ(trecvtac_in_buffer_sizetsocketterrort handle_errorRtlenRRt
isinstancetinttlongRRtfindtfind_prefix_at_end(R RtwhytlbRtntterminator_lentindex((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyt handle_readksJ
                     cCs|jƒdS(N(t initiate_send(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyt handle_write­scCs|jƒdS(N(tclose(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyt handle_close°scCsz|j}t|ƒ|kr\xNtdt|ƒ|ƒD]!}|jj||||!ƒq4Wn|jj|ƒ|jƒdS(Ni(tac_out_buffer_sizeR!txrangeRRR-(R Rtsabsti((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytpush³s     "cCs|jj|ƒ|jƒdS(N(RRR-(R tproducer((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytpush_with_producer¼scCsdS(s4predicate for inclusion in the readable for select()i((R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytreadableÀscCs|jp|j S(s4predicate for inclusion in the writable for select()(Rt    connected(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytwritableÈscCs|jjdƒdS(sAautomatically close this channel once the outgoing queue is emptyN(RRtNone(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytclose_when_doneÌsc    Csfx_|jra|jra|jd}|sO|jd=|dkrO|jƒdSn|j}y?tƒ0tr~tddtƒnt    |d|ƒ}WdQXWnCt
k
rÜ|j ƒ}|rÌ|jj |ƒq|jd=qnXy|j |ƒ}Wntjk
r|jƒdSX|r]|t|ƒks<|t|ƒkrP|||jd<q]|jd=ndSWdS(Nitignores.*buffer(RR9R;R0R1RRRtDeprecationWarningtbuffert    TypeErrortmoret
appendlefttsendRRR R!(R tfirsttobsRtnum_sent((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyR-Ðs: 
 
    
 
 
$ cCs!d|_|j2|jjƒdS(NR(RRRtclear(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytdiscard_buffersøs    N(t__name__t
__module__t__doc__RR1R;R RRRRRRR,R.R0R5R7R8R:R<R-RH(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyR7s(                            B                                    (tsimple_producercBseZdd„Zd„ZRS(icCs||_||_dS(N(Rt buffer_size(R RRM((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyR s    cCsYt|jƒ|jkr?|j|j }|j|j|_|S|j}d|_|SdS(NR(R!RRM(R tresult((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyRAs        (RIRJR RA(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyRLþs tfifocBsAeZdd„Zd„Zd„Zd„Zd„Zd„ZRS(cCs(|stƒ|_nt|ƒ|_dS(N(Rtlist(R RP((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyR scCs t|jƒS(N(R!RP(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyt__len__scCs|j S(N(RP(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytis_emptyscCs |jdS(Ni(RP(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyRDscCs|jj|ƒdS(N(RPR(R R((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyR5scCs$|jrd|jjƒfSdSdS(Nii(iN(RPtpopleftR;(R ((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pytpop!s    N(    RIRJR;R RQRRRDR5RT(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyROs                  cCs?t|ƒd}x(|r:|j|| ƒ r:|d8}qW|S(Ni(R!tendswith(thaystacktneedletl((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyR&6s(((RKRR    t collectionsRtsysRtwarningsRRR
RRLROR&(((sP/tmp/ndk-User/buildhost/install/prebuilt/darwin-x86_64/lib/python2.7/asynchat.pyt<module>/s  Ç(