grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026o ®û|j-ã@s^dZddlZddlmZddlmZededd�Gdd „d ejƒZGd d „d ƒZ d 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)Údeque)ÚwarnzlThe asynchat module is deprecated and will be removed in Python 3.12. The recommended replacement is asyncioé)Ú stacklevelc@sªeZdZdZdZdZdZdZd(dd„Zdd „Z d d „Z d d „Z dd„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-1NcCs(d|_g|_tƒ|_tj |||¡dS©Nó)Ú ac_in_bufferÚincomingrÚ producer_fifoÚasyncoreÚ dispatcherÚ__init__)ÚselfZsockÚmap©rú//opt/alt/python310/lib64/python3.10/asynchat.pyrKszasync_chat.__init__cCótdƒ‚©Nzmust be implemented in subclass©ÚNotImplementedError©rÚdatarrrÚcollect_incoming_dataYóz async_chat.collect_incoming_datacCs|j |¡dS©N)r ÚappendrrrrÚ_collect_incoming_data\sz!async_chat._collect_incoming_datacCsd |j¡}|jdd…=|Sr)Újoinr )rÚdrrrÚ _get_data_s  zasync_chat._get_datacCrrr©rrrrÚfound_terminatordrzasync_chat.found_terminatorcCsBt|tƒr|jrt||jƒ}n t|tƒr|dkrtdƒ‚||_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)rZtermrrrÚset_terminatorgs  zasync_chat.set_terminatorcCs|jSr)r*r!rrrÚget_terminatorrszasync_chat.get_terminatorcCs¼z| |j¡}WntyYdSty| ¡YdSwt|tƒr.|jr.tt|j ƒ}|j ||_ |j rÜt |j ƒ}|  ¡}|sL|  |j ¡d|_ n‹t|tƒr�|}||krg|  |j ¡d|_ |j||_np|  |j d|…¡|j |d…|_ d|_| ¡nVt |ƒ}|j  |¡}|dkr¬|dkr�|  |j d|…¡|j ||d…|_ | ¡n+t|j |ƒ}|rÎ||krÌ|  |j d| …¡|j | d…|_ dS|  |j ¡d|_ |j s7dSdS)Nrréÿÿÿÿ)ZrecvÚac_in_buffer_sizeÚBlockingIOErrorÚOSErrorÚ handle_errorr#r$r%r&r'r Úlenr,rr(r*r"ÚfindÚfind_prefix_at_end)rrZlbr*ÚnZterminator_lenÚindexrrrÚ handle_readzsV  þ           Ízasync_chat.handle_readcCó | ¡dSr)Ú initiate_sendr!rrrÚ handle_writeÂó zasync_chat.handle_writecCr8r)Úcloser!rrrÚ handle_closeÅr;zasync_chat.handle_closecCsxt|tttfƒstdt|ƒƒ‚|j}t|ƒ|kr0tdt|ƒ|ƒD]}|j   ||||…¡q n|j   |¡|  ¡dS)Nz#data argument must be byte-ish (%r)r) r#r&Ú bytearrayÚ memoryviewÚ TypeErrorÚtypeÚac_out_buffer_sizer2Úranger rr9)rrZsabsÚirrrÚpushÈsÿ ÿ  zasync_chat.pushcCs|j |¡| ¡dSr)r rr9)rZproducerrrrÚpush_with_producerÔs  zasync_chat.push_with_producercCsdS)z4predicate for inclusion in the readable for select()érr!rrrÚreadableØszasync_chat.readablecCs|jp|j S)z4predicate for inclusion in the writable for select())r Ú connectedr!rrrÚwritableàszasync_chat.writablecCs|j d¡dS)zAautomatically close this channel once the outgoing queue is emptyN)r rr!rrrÚclose_when_doneäszasync_chat.close_when_donecCs|jr„|jr†|jd}|s|jd=|dur| ¡dS|j}z|d|…}Wnty@| ¡}|r:|j |¡n|jd=Yqwt|tƒrO|j rOt ||j ƒ}z|  |¡}Wnt yd| ¡YdSw|r‚|t|ƒkss|t|ƒkr~||d…|jd<dS|jd=dSdSdS)Nr)r rIr=rBr@ÚmoreÚ appendleftr#r$r%r&r'Úsendr0r1r2)rÚfirstZobsrZnum_sentrrrr9ès@   ú  þþÛzasync_chat.initiate_sendcCs d|_|jdd…=|j ¡dSr)r r r Úclearr!rrrÚdiscard_bufferss zasync_chat.discard_buffers)NN)Ú__name__Ú __module__Ú __qualname__Ú__doc__r.rBr%r'rrrr r"r+r,r7r:r=rErFrHrJrKr9rQrrrrr<s.  H  (rc@seZdZddd„Zdd„ZdS)Úsimple_producerécCs||_||_dSr)rÚ buffer_size)rrrXrrrrs zsimple_producer.__init__cCsFt|jƒ|jkr|jd|j…}|j|jd…|_|S|j}d|_|Sr)r2rrX)rÚresultrrrrLszsimple_producer.moreN)rW)rRrSrTrrLrrrrrVs  rVcCsDt|ƒd}|r | |d|…¡s |d8}|r | |d|…¡r|S)NrG)r2Úendswith)ZhaystackZneedleÚlrrrr47s ÿr4) rUr Ú collectionsrÚwarningsrÚDeprecationWarningr rrVr4rrrrÚs  ü\