Sindbad~EG File Manager
�
(ΜgR-��d�dZddlmZddlmZGd�dej
�ZGd�d�Zd�Zy )
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��eZdZdZdZdZdZdZdd�Zd�Z d�Z
d �Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�
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-1Nc��d|_g|_t�|_tj
j
|||�y�N�)�ac_in_buffer�incomingr�
producer_fifor�
dispatcher�__init__)�self�sock�maps �2/usr/local/lib/python3.12/test/support/asynchat.pyrzasync_chat.__init__Js7�����
��
�#�W������$�$�T�4��5r c��td���Nzmust be implemented in subclass��NotImplementedError�r�datas r�collect_incoming_dataz async_chat.collect_incoming_dataX���!�"C�D�Dr c�:�|jj|�y�N)r�appendrs r�_collect_incoming_dataz!async_chat._collect_incoming_data[s���
�
���T�"r c�Z�dj|j�}|jdd�=|Sr)�joinr)r�ds r� _get_datazasync_chat._get_data^s%���H�H�T�]�]�#���M�M�!���r c��td��rr�rs r�found_terminatorzasync_chat.found_terminatorcrr c���t|t�r*|jrt||j�}||_yt|t
�r|dkrt
d��||_y)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)r�terms r�set_terminatorzasync_chat.set_terminatorfsT��
�d�C� �T�%6�%6���t�}�}�-�D������c�
"�t�a�x��L�M�M���r c��|jSr)r.r$s r�get_terminatorzasync_chat.get_terminatorqs�����r c�� |j|j�}t|t�r&|jrtt|j�}|j|z|_
|j�r�t|j�}|j�}|s$|j|j�d|_
�n�t|t�r�|}||kr8|j|j�d|_
|j|z
|_�n4|j|jd|�|j|d|_
d|_|j!�n�t|�}|jj#|�}|dk7rK|dkDr|j|jd|�|j||zd|_
|j!�ntt%|j|�}|r:||k7r4|j|jd|�|j|d|_
y|j|j�d|_
|jr���yy#t$rYyt$r|j �YywxYw)Nr r���)�recv�ac_in_buffer_size�BlockingIOError�OSError�handle_errorr'r(r)r*r+r
�lenr2rr,r.r%�find�find_prefix_at_end)rr�lbr.�n�terminator_len�indexs r�handle_readzasync_chat.handle_readys>�� ��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�7I8c�$�|j�yr)�
initiate_sendr$s r�handle_writezasync_chat.handle_write�s�����r c�$�|j�yr)�closer$s r�handle_closezasync_chat.handle_close�s���
�
�r c�h�t|tttf�st dt|���|j}t|�|kDr=tdt|�|�D]#}|jj||||z��%n|jj|�|j�y)Nz#data argument must be byte-ish (%r)r)r'r*� bytearray�
memoryview� TypeError�type�ac_out_buffer_sizer:�rangerrrC)rr�sabs�is r�pushzasync_chat.push�s����$�� �:� >�?��A� ��J�(�
(��&�&���t�9�t���1�c�$�i��.���"�"�)�)�$�q��4��.�9�/�
���%�%�d�+����r c�Z�|jj|�|j�yr)rrrC)r�producers r�push_with_producerzasync_chat.push_with_producer�s"�����!�!�(�+����r c��y)z4predicate for inclusion in the readable for select()��r$s r�readablezasync_chat.readable�s��r c�8�|jxs
|jS)z4predicate for inclusion in the writable for select())r� connectedr$s r�writablezasync_chat.writable�s���!�!�9�$�.�.�&8�9r c�:�|jjd�y)zAautomatically close this channel once the outgoing queue is emptyN)rrr$s r�close_when_donezasync_chat.close_when_done�s�����!�!�$�'r c��|jr�|jr�|jd}|s |jd=|�|j�y|j} |d|}t|t�r"|jrt||j�} |j|�}|r<|t|�ks|t|�kr||d|jd<y|jd=yyy#t$r?|j�}|r|jj
|�n
|jd=Y��'wxYw#t$r|j�YywxYw)Nr)rrZrGrMrK�more�
appendleftr'r(r)r*r+�sendr8r9r:)r�first�obsr�num_sents rrCzasync_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,�!AD)�(D)�,E�Ec�d�d|_|jdd�=|jj�yr)r
rr�clearr$s r�discard_bufferszasync_chat.discard_bufferss(������M�M�!����� � �"r )NN)�__name__�
__module__�__qualname__�__doc__r6rMr)r+rrrr"r%r0r2rArDrGrQrTrXr[r]rCrgrWr rrr;s|��F�
����
�L��H�6�E�#��
E� ��F0�P��
���:�(�&�P#r rc��eZdZdd�Zd�Zy)�simple_producerc� �||_||_yr)r�buffer_size)rrros rrzsimple_producer.__init__s���� �&��r c���t|j�|jkDr9|jd|j}|j|jd|_|S|j}d|_|Sr)r:rro)r�results rr_zsimple_producer.moresb���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)rhrirjrr_rWr rrmrms��'�r rmc��t|�dz
}|r0|j|d|�s|dz}|r|j|d|�s�|S)NrV)r:�endswith)�haystack�needle�ls rr<r<6sK���F��a��A�
�H�%�%�f�R�a�j�1� �Q����H�%�%�f�R�a�j�1��Hr N) rk�collectionsr�test.supportrr
rrmr<rWr r�<module>rys8��B�*�!�X#��$�$�X#�v��@
r
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists