\d2-dZddlZddlmZddlmZdZeeedGdd ejZ Gd d Z d Z dS) 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)deque) _deprecatedznThe {name} module is deprecated and will be removed in Python {remove}. The recommended replacement is asyncio) )removeceZdZdZdZdZdZdZddZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZdZdZdZdZdS) async_chatzThis is an abstract class. You must derive from this class, and add the two methods collect_incoming_data() and found_terminator()irzlatin-1Ncd|_g|_t|_tj|||dSN) ac_in_bufferincomingr producer_fifoasyncore dispatcher__init__)selfsockmaps ..\python\lib\asynchat.pyrzasync_chat.__init__JsB  #WW$$T455555r c tdNzmust be implemented in subclassNotImplementedErrorrdatas rcollect_incoming_dataz async_chat.collect_incoming_dataX!"CDDDr c:|j|dSN)rappendrs r_collect_incoming_dataz!async_chat._collect_incoming_data[s T"""""r cNd|j}|jdd=|Sr )joinr)rds r _get_datazasync_chat._get_data^s( HHT] # # M!!! r c tdrrrs rfound_terminatorzasync_chat.found_terminatorcrr ct|tr|jrt||j}n*t|t r|dkrt d||_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)rterms rset_terminatorzasync_chat.set_terminatorfsj dC  NT%6 Nt}--DD c " " NtaxxLMM Mr c|jSr )r2r(s rget_terminatorzasync_chat.get_terminatorqs r c  ||j}n1#t$rYdSt$r|YdSwxYwt |t r!|jrtt |j }|j |z|_ |j rt|j }| }|s#| |j d|_ nt |tr|}||kr2| |j d|_ |j|z |_nM| |j d||j |d|_ d|_|nt|}|j |}|dkrT|dkr"| |j d||j ||zd|_ |nxt%|j |}|r@||kr8| |j d| |j | d|_ dS| |j d|_ |j dSdS)Nr r)recvac_in_buffer_sizeBlockingIOErrorOSError handle_errorr+r,r-r.r/r lenr6rr0r2r)findfind_prefix_at_end)rrlbr2nterminator_lenindexs r handle_readzasync_chat.handle_readys 99T344DD    FF          FF  dC  -T%6 -dm,,D -43 0T&''B,,..J0 0**4+<===$'!!J,,, 066..t/@AAA(+D%&*o&:DOO..t/@!/DEEE(,(9!""(=D%&'DO))++++"%Z)..z::B;;qyy2243DVeV3LMMM(,(9%:N:O:O(PD%))++++/t/@*MME 0 B;; 66t7H5&7QRRR040A5&''0JD-2243DEEE,/)g3 03 03 03 03 0s A A  A c.|dSr ) initiate_sendr(s r handle_writezasync_chat.handle_writes r c.|dSr )closer(s r handle_closezasync_chat.handle_closes r ct|tttfst dt ||j}t||krGtdt||D]'}|j ||||z(n|j || dS)Nz#data argument must be byte-ish (%r)r) r+r. bytearray memoryview TypeErrortypeac_out_buffer_sizer>rangerr!rG)rrsabsis rpushzasync_chat.pushs$ : >?? (A JJ(( (& t99t  1c$ii.. : :"))$q4x.9999 :   % %d + + + r cb|j||dSr )rr!rG)rproducers rpush_with_producerzasync_chat.push_with_producers1 !!(+++ r cdS)z4predicate for inclusion in the readable for select()r(s rreadablezasync_chat.readables qr c |jp|j S)z4predicate for inclusion in the writable for select())r connectedr(s rwritablezasync_chat.writables!9$.&89r c:|jddS)zAautomatically close this channel once the outgoing queue is emptyN)rr!r(s rclose_when_donezasync_chat.close_when_dones !!$'''''r c|jrE|jr?|jd}|s |jd=||dS|j} |d|}nI#t$r<|}|r|j|n|jd=YwxYwt|tr|j rt||j } | |}n%#t$r|YdSwxYw|rA|t|ks|t|kr||d|jd<n|jd=dSdSdS)Nr)rr^rKrQrOmore appendleftr+r,r-r.r/sendr<r=r>)rfirstobsrnum_sents rrGzasync_chat.initiate_sends % T^% &q)E &q)=%%'''F)C TcT{   zz||.&11$7777*1-  $$$ 2): 2T4=11 99T??   !!###  .c$ii''3U+;+;,1()),rrt)rresults rrczsimple_producer.mores\ ty>>D, , ,Y0 001F $"2"3"34DIMYFDIMr N)rr)rlrmrnrrcr[r rrqrqs7''''r rqct|dz }|rA||d|s$|dz}|r||d|$|S)NrZ)r>endswith)haystackneedlels rr@r@6sk F aA H%%fRaRj11 Q H%%fRaRj11 Hr ) ror collectionsrwarningsr_DEPRECATION_MSGrlrr rqr@r[r rrs8( N H&w7777X#X#X#X#X#$X#X#X#v@     r