+
    BiS-                     f    R t ^ RIHt ^ RIHt  ! R R]P
                  4      t ! R R4      tR tR# )	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.
)deque)asyncorec                      a  ] tR t^;t o RtRtRt^ tRtRR lt	R t
R tR tR	 tR
 tR tR tR tR tR tR tR tR tR tR tR tRtV tR# )
async_chatzThis is an abstract class.  You must derive from this class, and add
the two methods collect_incoming_data() and found_terminator()i   zlatin-1Nc                    R V n         . V n        \        4       V n        \        P
                  P                  WV4       R# )    N)ac_in_bufferincomingr   producer_fifor   
dispatcher__init__)selfsockmaps   &&&,/usr/lib/python3.14/test/support/asynchat.pyr   async_chat.__init__J   s5    
  #W$$T5r   c                    \        R 4      hzmust be implemented in subclassNotImplementedErrorr   datas   &&r   collect_incoming_data async_chat.collect_incoming_dataX       !"CDDr   c                <    V P                   P                  V4       R # N)r	   appendr   s   &&r   _collect_incoming_data!async_chat._collect_incoming_data[   s    T"r   c                V    R P                  V P                  4      pV P                  R V# )r   NNN)joinr	   )r   ds   & r   	_get_dataasync_chat._get_data^   s%    HHT]]#MM!r   c                    \        R 4      hr   r   r   s   &r   found_terminatorasync_chat.found_terminatorc   r   r   c                    \        V\        4      '       d)   V P                  '       d   \        WP                  4      pM(\        V\
        4      '       d   V^ 8  d   \        R4      hWn        R# )zTSet the input delimiter.

Can be a fixed string of any length, an integer, or None.
z-the number of received bytes must be positiveN)
isinstancestruse_encodingbytesencodingint
ValueError
terminator)r   terms   &&r   set_terminatorasync_chat.set_terminatorf   sN    
 dC  T%6%6%6}}-Dc""taxLMMr   c                    V P                   # r   )r2   r'   s   &r   get_terminatorasync_chat.get_terminatorq   s    r   c                `    V P                  V P                  4      p\        T\        4      '       d-   T P                  '       d   \        \        T P                  4      pT P                  T,           T n
        T P                  '       Ed   \        T P                  4      pT P                  4       pT'       g%   T P                  T P                  4       RT n
        Kd  \        T\        4      '       d   TpY$8  d=   T P                  T P                  4       RT n
        T P                  T,
          T n        K  T P                  T P                  R T 4       T P                  TR  T n
        ^ T n        T P!                  4        EK
  \        T4      pT P                  P#                  T4      pTR8w  dS   T^ 8  d   T P                  T P                  R T 4       T P                  Ye,           R  T n
        T P!                  4        EK  \%        T P                  T4      pT'       d=   Yb8w  d5   T P                  T P                  R T)  4       T P                  T) R  T n
        R # T P                  T P                  4       RT n
        EK  R #   \         d     R # \         d    T P	                  4         R # i ; i)Nr   )recvac_in_buffer_sizeBlockingIOErrorOSErrorhandle_errorr+   r,   r-   r.   r/   r   lenr7   r   r0   r2   r(   findfind_prefix_at_end)r   r   lbr2   nterminator_lenindexs   &      r   handle_readasync_chat.handle_ready   s>   	99T334D dC  T%6%6%6dmm,D --4 T&&'B,,.J**4+<+<=$'!J,,6..t/@/@A(+D%&*oo&:DO..t/@/@!/DE(,(9(9!"(=D%&'DO))+ "%Z))..z:B;qy 2243D3DVe3LM(,(9(9%:N:O(PD% ))+ /t/@/@*ME ; 66t7H7H5&7QR040A0A5&'0JD- 2243D3DE,/)g    	 		s   J J-J-J-,J-c                &    V P                  4        R # r   )initiate_sendr'   s   &r   handle_writeasync_chat.handle_write   s    r   c                &    V P                  4        R # r   )closer'   s   &r   handle_closeasync_chat.handle_close   s    

r   c                   \        V\        \        \        34      '       g   \	        R \        V4      4      hV P                  p\        V4      V8  dB   \        ^ \        V4      V4       F&  pV P                  P                  WW2,            4       K(  	  MV P                  P                  V4       V P                  4        R# )z#data argument must be byte-ish (%r)N)r+   r.   	bytearray
memoryview	TypeErrortypeac_out_buffer_sizer@   ranger
   r   rJ   )r   r   sabsis   &&  r   pushasync_chat.push   s    $	: >??A J( (&&t9t1c$i.""))$.9 / %%d+r   c                \    V P                   P                  V4       V P                  4        R # r   )r
   r   rJ   )r   producers   &&r   push_with_producerasync_chat.push_with_producer   s"    !!(+r   c                    ^# )z4predicate for inclusion in the readable for select() r'   s   &r   readableasync_chat.readable   s     r   c                L    V P                   ;'       g    V P                  '       * # )z4predicate for inclusion in the writable for select())r
   	connectedr'   s   &r   writableasync_chat.writable   s    !!99$..&89r   c                <    V P                   P                  R4       R# )zAautomatically close this channel once the outgoing queue is emptyN)r
   r   r'   s   &r   close_when_doneasync_chat.close_when_done   s    !!$'r   c                   V P                   '       d   V P                  '       d   V P                   ^ ,          pV'       g$   V P                   ^  Vf   V P                  4        R# V P                  p VRV p\        T\        4      '       d(   T P                  '       d   \        Y0P                  4      p T P                  T4      pT'       dA   T\        T4      8  g   T\        T4      8  d   YR T P                   ^ &   R# T P                   ^  R# R# R#   \         dG    TP                  4       pT'       d   T P                   P                  T4       MT P                   ^   EKa  i ; i  \         d    T P                  4         R# i ; i)    N)r
   re   rO   rV   rT   more
appendleftr+   r,   r-   r.   r/   sendr>   r?   r@   )r   firstobsr   num_sents   &    r   rJ   async_chat.initiate_send   sW      T^^^&&q)E&&q)=%%' ))CTc{ $$$):):):T==199T?
 c$i'3U+;,1),<D&&q)  **1-K &4   zz|&&11$7**1-  !!#s*   0D 3E& "E#5)E#"E#&FFc                b    R V n         V P                  R V P                  P                  4        R# )r   r!   N)r   r	   r
   clearr'   s   &r   discard_buffersasync_chat.discard_buffers  s(    MM!  "r   )r   r	   r
   r2   )NN)__name__
__module____qualname____firstlineno____doc__r<   rV   r-   r/   r   r   r   r$   r(   r4   r7   rG   rK   rO   rZ   r^   rb   rf   ri   rJ   rv   __static_attributes____classdictcell____classdict__s   @r   r   r   ;   s     F
 
 LH6E#
E	F0P
:(&P# #r   r   c                   0   a  ] tR tRt o RR ltR tRtV tR# )simple_produceri  c                    Wn         W n        R # r   )r   buffer_size)r   r   r   s   &&&r   r   simple_producer.__init__  s    	&r   c                    \        V P                  4      V P                  8  d:   V P                  R V P                   pV P                  V P                  R  V n        V# V P                  pRV n        V# )Nr   )r@   r   r   )r   results   & r   rm   simple_producer.more  sb    tyy>D,,,YY0 0 01F		$"2"2"34DIMYYFDIMr   )r   r   N)i   )rx   ry   rz   r{   r   rm   r}   r~   r   s   @r   r   r     s     ' r   r   c                     \        V4      ^,
          pV'       d&   V P                  VRV 4      '       g   V^,          pK-  V# )   N)r@   endswith)haystackneedlels   && r   rB   rB   6  s6    FaA
H%%fRaj11	QHr   N)	r|   collectionsr   test.supportr   r   r   r   rB   ra   r   r   <module>r      s8   B*  !X#$$ X#v @r   