Ë
    òT•jR-  ã                   ód   — d Z ddlmZ ddlmZ  G d„ dej
                  «      Z G d„ d«      Zd„ Zy	)
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                   óˆ   — e Zd ZdZdZdZdZdZdd„Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zy)Ú
async_chatz‡This is an abstract class.  You must derive from this class, and add
    the two methods collect_incoming_data() and found_terminator()i   r   zlatin-1Nc                 ó€   — d| _         g | _        t        «       | _        t        j
                  j                  | ||«       y ©Nó    )Úac_in_bufferÚincomingr   Úproducer_fifor   Ú
dispatcherÚ__init__)ÚselfÚsockÚmaps      ú,/usr/lib/python3.12/test/support/asynchat.pyr   zasync_chat.__init__J   s7   € àˆÔð
 ˆŒô #›WˆÔÜ×Ñ×$Ñ$ T¨4°Õ5r	   c                 ó   — t        d«      ‚©Nzmust be implemented in subclass©ÚNotImplementedError©r   Údatas     r   Úcollect_incoming_dataz async_chat.collect_incoming_dataX   ó   € Ü!Ð"CÓDÐDr	   c                 ó:   — | j                   j                  |«       y ©N)r   Úappendr   s     r   Ú_collect_incoming_dataz!async_chat._collect_incoming_data[   s   € Ø�‰×Ñ˜TÕ"r	   c                 óZ   — dj                  | j                  «      }| j                  d d …= |S r   )Újoinr   )r   Úds     r   Ú	_get_datazasync_chat._get_data^   s%   € Ø�H‰H�T—]‘]Ó#ˆØ�M‰Mš!ÐØˆr	   c                 ó   — t        d«      ‚r   r   ©r   s    r   Úfound_terminatorzasync_chat.found_terminatorc   r   r	   c                 óÆ   — t        |t        «      r*| j                  rt        || j                  «      }|| _        yt        |t
        «      r|dk  rt        d«      ‚|| _        y)zdSet the input delimiter.

        Can be a fixed string of any length, an integer, or None.
        r   z-the number of received bytes must be positiveN)Ú
isinstanceÚstrÚuse_encodingÚbytesÚencodingÚintÚ
ValueErrorÚ
terminator)r   Úterms     r   Úset_terminatorzasync_chat.set_terminatorf   sT   € ô
 �dœCÔ  T×%6Ò%6Ü˜˜tŸ}™}Ó-ˆDð ˆ�ô ˜œcÔ" t¨a¢xÜÐLÓMÐMØˆ�r	   c                 ó   — | j                   S r   )r.   r$   s    r   Úget_terminatorzasync_chat.get_terminatorq   s   € Ø�‰Ðr	   c                 óö  — 	 | j                  | j                  «      }t        |t        «      r&| j                  rt        t        | j                  «      }| j                  |z   | _
        | j                  �rÝt        | j                  «      }| j                  «       }|s$| j                  | j                  «       d| _
        �nƒt        |t        «      r‰|}||k  r8| j                  | j                  «       d| _
        | j                  |z
  | _        �n4| j                  | j                  d | «       | j                  |d  | _
        d| _        | j!                  «        nêt        |«      }| j                  j#                  |«      }|dk7  rK|dkD  r| j                  | j                  d | «       | j                  ||z   d  | _
        | j!                  «        ntt%        | j                  |«      }|r:||k7  r4| j                  | j                  d |  «       | j                  | d  | _
        y | j                  | j                  «       d| _
        | j                  r�ŒÜy y # t        $ r Y y t        $ r | j	                  «        Y y w xY w)Nr	   r   éÿÿÿÿ)ÚrecvÚac_in_buffer_sizeÚBlockingIOErrorÚOSErrorÚhandle_errorr'   r(   r)   r*   r+   r
   Úlenr2   r   r,   r.   r%   ÚfindÚfind_prefix_at_end)r   r   Úlbr.   ÚnÚterminator_lenÚindexs          r   Úhandle_readzasync_chat.handle_ready   s>  € ð	Ø—9‘9˜T×3Ñ3Ó4ˆDô �dœCÔ  T×%6Ò%6Üœ˜dŸm™mÓ,ˆDØ ×-Ñ-°Ñ4ˆÔð ×ÓÜ�T×&Ñ&Ó'ˆBØ×,Ñ,Ó.ˆJÙà×*Ñ*¨4×+<Ñ+<Ô=Ø$'�Ö!Ü˜J¬Ô,à�Ø˜’6Ø×.Ñ.¨t×/@Ñ/@ÔAØ(+�DÔ%Ø&*§o¡o¸Ñ&:�D–Oà×.Ñ.¨t×/@Ñ/@ÀÀ!Ð/DÔEØ(,×(9Ñ(9¸!¸"Ð(=�DÔ%Ø&'�D”OØ×)Ñ)Õ+ô "% Z£�Ø×)Ñ)×.Ñ.¨zÓ:�Ø˜B’;à˜q’yð ×2Ñ2°4×3DÑ3DÀVÀeÐ3LÔMØ(,×(9Ñ(9¸%ÀÑ:NÐ:OÐ(P�DÔ%ð ×)Ñ)Õ+ô /¨t×/@Ñ/@À*ÓM�EÙØ  Bš;à ×6Ñ6°t×7HÑ7HÈÈ5È&Ð7QÔRØ04×0AÑ0AÀ5À&À'Ð0J˜DÔ-Øð ×2Ñ2°4×3DÑ3DÔEØ,/˜Ô)ðg ×Öøô ò 	ÙÜò 	Ø×ÑÔÙð	ús   ‚I É	I8ÉI8É7I8c                 ó$   — | j                  «        y r   )Úinitiate_sendr$   s    r   Úhandle_writezasync_chat.handle_writeÁ   s   € Ø×ÑÕr	   c                 ó$   — | j                  «        y r   )Úcloser$   s    r   Úhandle_closezasync_chat.handle_closeÄ   s   € Ø�
‰
�r	   c                 óh  — t        |t        t        t        f«      st	        dt        |«      «      ‚| j                  }t        |«      |kD  r=t        dt        |«      |«      D ]#  }| j                  j                  ||||z    «       Œ% n| j                  j                  |«       | j                  «        y )Nz#data argument must be byte-ish (%r)r   )r'   r*   Ú	bytearrayÚ
memoryviewÚ	TypeErrorÚtypeÚac_out_buffer_sizer:   Úranger   r   rC   )r   r   ÚsabsÚis       r   Úpushzasync_chat.pushÇ   s�   € Ü˜$¤¬	´:Ð >Ô?ÜÐAÜ  ›Jó(ð (à×&Ñ&ˆÜˆt‹9�tÒÜ˜1œc $›i¨Ó.ò :�Ø×"Ñ"×)Ñ)¨$¨q°°4±¨.Õ9ñ:ð ×Ñ×%Ñ% dÔ+Ø×ÑÕr	   c                 óZ   — | j                   j                  |«       | j                  «        y r   )r   r   rC   )r   Úproducers     r   Úpush_with_producerzasync_chat.push_with_producerÓ   s"   € Ø×Ñ×!Ñ! (Ô+Ø×ÑÕr	   c                  ó   — y)z4predicate for inclusion in the readable for select()é   © r$   s    r   Úreadablezasync_chat.readable×   s   € ð r	   c                 ó8   — | j                   xs | j                   S )z4predicate for inclusion in the writable for select())r   Ú	connectedr$   s    r   Úwritablezasync_chat.writableß   s   € à×!Ñ!Ò9¨$¯.©.Ð&8Ð9r	   c                 ó:   — | j                   j                  d«       y)zAautomatically close this channel once the outgoing queue is emptyN)r   r   r$   s    r   Úclose_when_donezasync_chat.close_when_doneã   s   € à×Ñ×!Ñ! $Õ'r	   c                 ó–  — | j                   rÓ| j                  rÆ| j                   d   }|s | j                   d= |€| j                  «        y | j                  }	 |d | }t        |t        «      r"| j                  rt        || j                  «      }	 | j                  |«      }|r<|t        |«      k  s|t        |«      k  r||d  | j                   d<   y | j                   d= y y y # t        $ r? |j                  «       }|r| j                   j                  |«       n| j                   d= Y �Œ'w xY w# t        $ r | j                  «        Y y w xY w)Nr   )r   rZ   rG   rM   rK   ÚmoreÚ
appendleftr'   r(   r)   r*   r+   Úsendr8   r9   r:   )r   ÚfirstÚobsr   Únum_sents        r   rC   zasync_chat.initiate_sendç   sP  € Ø× Ò  T§^¢^Ø×&Ñ& qÑ)ˆEáØ×&Ñ& qÐ)Ø�=Ø×%Ñ%Ô'Øð ×)Ñ)ˆCðØ˜T˜c�{�ô ˜$¤Ô$¨×):Ò):Ü˜T 4§=¡=Ó1�ðØŸ9™9 T›?�ñ
 Øœc $›iÒ'¨3´°U³Ò+;Ø,1°(°)Ð,<�D×&Ñ& qÑ)ð ð ×*Ñ*¨1Ð-àðK &4Ð øô ò Ø—z‘z“|�ÙØ×&Ñ&×1Ñ1°$Õ7à×*Ñ*¨1Ð-Úðûô ò Ø×!Ñ!Ô#Ùðús%   ÁC! ÂD, Ã!AD)Ä(D)Ä,EÅEc                 ód   — d| _         | j                  d d …= | j                  j                  «        y r   )r
   r   r   Úclearr$   s    r   Údiscard_bufferszasync_chat.discard_buffers  s(   € àˆÔØ�M‰Mš!ÐØ×Ñ× Ñ Õ"r	   )NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r6   rM   r)   r+   r   r   r   r"   r%   r0   r2   rA   rD   rG   rQ   rT   rX   r[   r]   rC   rg   rW   r	   r   r   r   ;   s|   „ ñFð
 ÐØÐð
 €LØ€Hó6òEò#òò
Eò	òòF0òPòò
òòò:ò(ò&óP#r	   r   c                   ó   — e Zd Zdd„Zd„ Zy)Úsimple_producerc                 ó    — || _         || _        y r   )r   Úbuffer_size)r   r   ro   s      r   r   zsimple_producer.__init__  s   € ØˆŒ	Ø&ˆÕr	   c                 óâ   — t        | j                  «      | j                  kD  r9| j                  d | j                   }| j                  | j                  d  | _        |S | j                  }d| _        |S r   )r:   r   ro   )r   Úresults     r   r_   zsimple_producer.more  sb   € Üˆt�y‰y‹>˜D×,Ñ,Ò,Ø—Y‘YÐ0 × 0Ñ 0Ð1ˆFØŸ	™	 $×"2Ñ"2Ð"3Ð4ˆDŒIØˆMà—Y‘YˆFØˆDŒIØˆMr	   N)i   )rh   ri   rj   r   r_   rW   r	   r   rm   rm     s   „ ó'ór	   rm   c                 ó†   — t        |«      dz
  }|r0| j                  |d | «      s|dz  }|r| j                  |d | «      sŒ|S )NrV   )r:   Úendswith)ÚhaystackÚneedleÚls      r   r<   r<   6  sK   € ÜˆF‹�a‰€AÙ
�H×%Ñ% f¨R¨a jÔ1Ø	ˆQ‰ˆñ �H×%Ñ% f¨R¨a jÕ1à€Hr	   N)	rk   Úcollectionsr   Útest.supportr   r   r   rm   r<   rW   r	   r   ú<module>ry      s8   ðñBõ* å !ôX#�×$Ñ$ô X#÷vñ ó@r	   