Sindbad~EG File Manager
�
(Μg�O���dZddlZddlZddlZddlZddlZddlZddlmZm Z m
Z
mZmZm
Z
mZmZmZmZmZmZmZeee
eeeeh�Z ed�ZGd�de�ZeeefZd�Zd�Z d �Z!d
�Z"dd�Z#dd�Z$e$Z%dd
�Z&Gd�d�Z'Gd�de'�Z(d�Z)dd�Z*ejVdk(rGd�d�Z,Gd�de'�Z-yy#e$riZY�xwxYw)a�Basic infrastructure for asynchronous socket service clients and servers.
There are only two ways to have a program on a single processor do "more
than one thing at a time". Multi-threaded programming is the simplest and
most popular way to do it, but there is another very different technique,
that lets you have nearly all the advantages of multi-threading, without
actually using multiple threads. it's really only practical if your program
is largely I/O bound. If your program is CPU bound, then pre-emptive
scheduled threads are probably what you really need. Network servers are
rarely CPU-bound, however.
If your operating system supports the select() system call in its I/O
library (and nearly all do), then you can use it to juggle multiple
communication channels at once; doing other work while your I/O is taking
place in the "background." Although this strategy can seem strange and
complex, especially at first, it is in many ways easier to understand and
control than multi-threaded programming. The module documented here solves
many of the difficult problems for you, making the task of building
sophisticated high-performance network servers and clients a snap.
�N)
�EALREADY�EINPROGRESS�EWOULDBLOCK�
ECONNRESET�EINVAL�ENOTCONN� ESHUTDOWN�EISCONN�EBADF�ECONNABORTED�EPIPE�EAGAIN� errorcodec�� tj|�S#tttf$r|t
vrt
|cYSd|zcYSwxYw)NzUnknown error %s)�os�strerror�
ValueError�
OverflowError� NameErrorr)�errs �2/usr/local/lib/python3.12/test/support/asyncore.py� _strerrorrJsI��'��{�{�3�����
�y�1�'��)���S�>�!�!�3�&�&�'�s��%A�A�Ac��eZdZy)�ExitNowN)�__name__�
__module__�__qualname__��rrrRs��rrc�f� |j�y#t$r�|j�YyxYw�N)�handle_read_event�_reraised_exceptions�handle_error��objs r�readr'W�1����������
���������0c�f� |j�y#t$r�|j�YyxYwr!)�handle_write_eventr#r$r%s r�writer,_s1������ ����
������r)c�f� |j�y#t$r�|j�YyxYwr!)�handle_expt_eventr#r$r%s r�
_exceptionr/gr(r)c�6� |tjzr|j�|tjzr|j �|tj
zr|j
�|tjtjztjzzr|j�yy#t$rB}|jtvr|j�n|j�Yd}~yYd}~yd}~wt$r�|j�YyxYwr!)�select�POLLINr"�POLLOUTr+�POLLPRIr.�POLLHUP�POLLERR�POLLNVAL�handle_close�OSError�errno�
_DISCONNECTEDr$r#)r&�flags�es r� readwriter>os�����6�=�=� ��!�!�#��6�>�>�!��"�"�$��6�>�>�!��!�!�#��F�N�N�V�^�^�3�f�o�o�E�F�����G�����7�7�-�'����������
�� ��
������s�B.B2�2 D�;3C8�8Dc��|�t}|�rHg}g}g}t|j��D]m\}}|j�}|j �}|r|j|�|r|js|j|�|s|s�]|j|��og|cxk(r|cxk(r|k(rnntj|�ytj||||�\}}}|D]!}|j|�}|��t|��#|D]!}|j|�}|��t|��#|D]!}|j|�}|��t|��#yyr!)�
socket_map�list�items�readable�writable�append� accepting�time�sleepr1�getr'r,r/) �timeout�map�r�wr=�fdr&�is_r�is_ws r�pollrQ�s5��
�{���
���B��B���C�I�I�K�(�G�B���<�<�>�D��<�<�>�D��������C�M�M�������t������)����a��1���J�J�w����-�-��1�a��1���1�a��B��'�'�"�+�C��{����I� ��B��'�'�"�+�C��{���#�J� ��B��'�'�"�+�C��{���s�O� �=rc��|�t}|�t|dz�}tj�}|r�t |j��D]\}}d}|j
�r$|tjtjzz}|j�r|js|tjz}|s�n|j||���|j|�}|D]%\}}|j|�}|��t||��'yy)Ni�r)r@�intr1rQrArBrCr2r4rDrFr3�registerrIr>)rJrK�pollsterrNr&r<rLs r�poll2rV�s���
�{������g�d�l�#���{�{�}�H�
��C�I�I�K�(�G�B���E��|�|�~��������7�7���|�|�~�c�m�m�����'����!�!�"�e�,�)�
�M�M�'�"���I�B���'�'�"�+�C��{���c�5�!� �rc��|�t}|rttd�rt}nt}|�|r
|||�|r�yy|r|dkDr|||�|dz
}|r|dkDr�yyyy)NrQr�)r@�hasattrr1rVrQ)rJ�use_pollrK�count�poll_funs r�loopr]�sh��
�{����G�F�F�+������}���W�c�"���e�a�i��W�c�"��A�I�E��e�a�i�c�i�crc�"�eZdZdZdZdZdZdZdZe dh�Z
d"d�Zd�Zd#d�Z
d#d�Zej ej"fd�Zd#d �Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd$d�Zd�Z d�Z!d�Z"d�Z#d�Z$d�Z%d�Z&d�Z'd�Z(d�Z)d �Z*d!�Z+y)%�
dispatcherFN�warningc�`�|�t|_n||_d|_|rA|jd�|j ||�d|_ |j
�|_yd|_
y#t$r<}|jttfvrd|_n|j|��Yd}~yd}~wwxYw)NFT)r@�_map�_fileno�setblocking�
set_socket� connected�getpeername�addrr9r:rr�del_channel�socket)�self�sockrKrs r�__init__zdispatcher.__init__�s����;�"�D�I��D�I�����
���U�#��O�O�D�#�&�!�D�N�
� �,�,�.�� ��D�K���
��9�9��6� 2�2�&+�D�N�
�$�$�S�)��
#��
�s�
A(�( B-�12B(�(B-c���|jjdz|jjzg}|jr|jr|jd�n|jr|jd�|j� |jd|jz�ddj|�t|�fzS#t$r'|jt|j��Y�NwxYw)N�.� listeningrfz%s:%dz<%s at %#x>� )� __class__rrrFrhrErf� TypeError�repr�join�id)rk�statuss r�__repr__zdispatcher.__repr__s����.�.�+�+�C�/����0K�0K�K�L���>�>�d�i�i��M�M�+�&�
�^�^��M�M�+�&��9�9� �
/��
�
�g�� � �1�2������ 0�"�T�(�;�;�;���
/��
�
�d�4�9�9�o�.�
/�s�C�-C3�2C3c�>�|�|j}|||j<yr!)rbrc)rkrKs r�add_channelzdispatcher.add_channels���;��)�)�C� ��D�L�L�rc�T�|j}|�|j}||vr||=d|_yr!)rcrb)rkrKrNs rrizdispatcher.del_channels.��
�\�\���;��)�)�C�
��9��B����rc��||f|_tj||�}|jd�|j|�y�NF)�family_and_typerjrdre)rk�family�typerls r�
create_socketzdispatcher.create_sockets8��%�t�|����}�}�V�T�*�����������rc�^�||_|j�|_|j|�yr!)rj�filenorcrz�rkrlrKs rrezdispatcher.set_socket$s$������{�{�}�������rc�� |jjtjtj|jj tjtj�dz�y#t
$rYywxYw)NrX)rj�
setsockopt�
SOL_SOCKET�SO_REUSEADDR�
getsockoptr9�rks r�set_reuse_addrzdispatcher.set_reuse_addr)sj�� ��K�K�"�"��!�!�6�#6�#6����&�&�v�'8�'8�'-�':�':�<�>?�@�
��
� �� �s�A2A5�5 B�Bc��y�NTrr�s rrCzdispatcher.readable:���rc��yr�rr�s rrDzdispatcher.writable=r�rc�z�d|_tjdk(r|dkDrd}|jj |�S)NT�nt�)rFr�namerj�listen)rk�nums rr�zdispatcher.listenDs4�����
�7�7�d�?�s�Q�w��C��{�{�!�!�#�&�&rc�F�||_|jj|�Sr!)rhrj�bind)rkrhs rr�zdispatcher.bindJs���� ��{�{����%�%rc�,�d|_d|_|jj|�}|tt
tfvs|tk(rtjdk(r||_
y|dtfvr||_
|j�yt|t|��)NFTr�r)rf�
connectingrj�
connect_exrrrrrr�rhr
�handle_connect_eventr9r)rk�addressrs r�connectzdispatcher.connectNs~���������k�k�$�$�W�-���;��+�6�6��&�=�R�W�W��_��D�I���1�g�,���D�I��%�%�'��#�y��~�.�.rc��� |jj�\}}||fS#t$rYyt$r(}|jt
ttfvrYd}~y�d}~wwxYwr!)rj�acceptrsr9r:rrr)rk�connrh�whys rr�zdispatcher.accept\s_��
����+�+�-�J�D�$���:���� ��� ��y�y�[�,��?�?���� �s�#� A�A�A�A�Ac��� |jj|�}|S#t$rE}|jtk(rYd}~y|jt
vr|j
�Yd}~y�d}~wwxYw�Nr)rj�sendr9r:rr;r8)rk�data�resultr�s rr�zdispatcher.sendjs]��
��[�[�%�%�d�+�F��M��� ��y�y�K�'�����m�+��!�!�#���� �s �� A-�A(�"A(�'A(�(A-c��� |jj|�}|s|j�y|S#t$r-}|jt
vr|j�Yd}~y�d}~wwxYw�Nr)rj�recvr8r9r:r;)rk�buffer_sizer�r�s rr�zdispatcher.recvwsb�� ��;�;�#�#�K�0�D���!�!�#������ ��y�y�M�)��!�!�#����
�s�-2�2� A(�"A#�"A#�#A(c��d|_d|_d|_|j�|j� |jj�yy#t$r#}|jttfvr�Yd}~yd}~wwxYwr})
rfrFr�rirj�closer9r:rr)rkr�s rr�zdispatcher.close�sr����������������;�;�"�
����!�!�#�#���
��9�9�X�u�$5�5��6��
�s�A� A;�A6�6A;c�Z�tjjdt|�z�y)Nzlog: %s
)�sys�stderrr,�str)rk�messages r�logzdispatcher.log�s���
�
����s�7�|�3�4rc�B�||jvrt|�d|���yy)Nz: )�ignore_log_types�print)rkr�r�s r�log_infozdispatcher.log_info�s"���t�,�,�,��d�G�,�-�-rc���|jr|j�y|js-|jr|j �|j�y|j�yr!)rF�
handle_acceptrfr�r��handle_readr�s rr"zdispatcher.handle_read_event�sI���>�>�
��� ��������)�)�+��������rc���|jjtjtj�}|dk7rt |t|���|j
�d|_d|_y)NrTF) rjr�r��SO_ERRORr9r�handle_connectrfr��rkrs rr�zdispatcher.handle_connect_event�sT���k�k�$�$�V�%6�%6����H���!�8��#�y��~�.�.����������rc��|jry|js|jr|j�|j �yr!)rFrfr�r��handle_writer�s rr+zdispatcher.handle_write_event�s4���>�>�
��~�~�����)�)�+����rc��|jjtjtj�}|dk7r|j �y|j�yr�)rjr�r�r�r8�handle_exptr�s rr.zdispatcher.handle_expt_event�sE���k�k�$�$�V�%6�%6����H���!�8�
�������rc���t�\}}}} t|�}|jd|�d|�d|�d|�d� d�|j �y#dt|�z}Y�BxYw)Nz)<__repr__(self) failed for object at %0x>z-uncaptured python exception, closing channel z (�:rq�)�error)�compact_tracebackrtrvr�r8)rk�nil�t�v�tbinfo� self_reprs rr$zdispatcher.handle_error�sj��-�/���Q��6� O��T�
�I�
�
�
�����
�
� �
����� O�C�b��h�N�I�s�A�Ac�(�|jdd�y)Nz!unhandled incoming priority eventr`�r�r�s rr�zdispatcher.handle_expt�s���
�
�9�9�Erc�(�|jdd�y)Nzunhandled read eventr`r�r�s rr�zdispatcher.handle_read�s���
�
�,�i�8rc�(�|jdd�y)Nzunhandled write eventr`r�r�s rr�zdispatcher.handle_write�s���
�
�-�y�9rc�(�|jdd�y)Nzunhandled connect eventr`r�r�s rr�zdispatcher.handle_connect�s���
�
�/��;rc�H�|j�}|�|j|�yyr!)r��handle_accepted)rk�pairs rr�zdispatcher.handle_accept�s(���{�{�}���� �D� � �$�'�rc�H�|j�|jdd�y)Nzunhandled accepted eventr`)r�r�)rkrlrhs rr�zdispatcher.handle_accepted�s���
�
���
�
�0�)�<rc�H�|jdd�|j�y)Nzunhandled close eventr`)r�r�r�s rr8zdispatcher.handle_close�s���
�
�-�y�9��
�
�r�NNr!)�info),rrr�debugrfrFr��closingrh� frozensetr�rmrxrzrirj�AF_INET�SOCK_STREAMr�rer�rCrDr�r�r�r�r�r�r�r�r�r"r�r+r.r$r�r�r�r�r�r�r8rrrr_r_�s����E��I��I��J��G��D� �)��-���@<�!��$*�>�>��8J�8J���
�"��'�&�/����$
� 5�.�
� � �
��(F�9�:�<�(�
=�rr_c�,�eZdZdd�Zd�Zd�Zd�Zd�Zy)�dispatcher_with_sendNc�@�tj|||�d|_yr�)r_rm�
out_bufferr�s rrmzdispatcher_with_send.__init__s�����D�$��,���rc�v�d}tj||jdd�}|j|d|_y)Nri)r_r�r�)rk�num_sents r�
initiate_sendz"dispatcher_with_send.initiate_sends4�����?�?�4�����%�)@�A���/�/�(�)�4��rc�$�|j�yr!)r�r�s rr�z!dispatcher_with_send.handle_writes�����rc�J�|jxst|j�Sr!)rf�lenr�r�s rrDzdispatcher_with_send.writables���N�N�"�;�s�4�?�?�';�;rc��|jr|jdt|�z�|j|z|_|j �y)Nz
sending %s)r�r�rtr�r�)rkr�s rr�zdispatcher_with_send.sends:���:�:��M�M�,��d��3�4��/�/�D�0������rr�)rrrrmr�r�rDr�rrrr�r�s���5�
�<�rr�c���tj�}|j}|std��g}|rr|j |j
jj|j
jjt|j�f�|j}|r�r~|d\}}}dj|D�cgc]}d|z�� c}�}|||ft|�||fScc}w)Nztraceback does not exist���rqz
[%s|%s|%s])r�� exception�
__traceback__�AssertionErrorrE�tb_frame�f_code�co_filename�co_namer�� tb_lineno�tb_nextrur�)�exc�tbr��file�function�line�xr�s rr�r�s���
�-�-�/�C� � � �B�
��7�8�8�
�F�
��
�
��K�K���*�*��K�K���&�&������� �
�Z�Z��
� �!�"�:��D�(�D��8�8�v�6�v�!�\�A�%�v�6�7�D��(�D�!�4��9�c�4�7�7��7s�=C"c��|�t}t|j��D]} |j��|j�y#t$r!}|j
tk(rn|s�Yd}~�Ld}~wt$r�|s�Y�_xYwr!) r@rA�valuesr�r9r:rr#�clear)rK�
ignore_allr�s r� close_allr�0sx��
�{���
�#�*�*�,�
�� �
�G�G�I� ��I�I�K��� ��w�w�%�������#� �� ����s�A � B�A.�.B�posixc�@�eZdZd�Zd�Zd�Zd�Zd d�ZeZeZ d�Z
d�Zy)
�file_wrapperc�8�tj|�|_yr!)r�duprN�rkrNs rrmzfile_wrapper.__init__Us���f�f�R�j�D�Grc��|jdk\rtjd|zt|��|j �y)Nrzunclosed file %r)�source)rN�warnings�warn�ResourceWarningr�r�s r�__del__zfile_wrapper.__del__Xs/���w�w�!�|��
�
�0�4�7��%)�+��J�J�Lrc�B�tj|jg|���Sr!)rr'rN�rk�argss rr�zfile_wrapper.recv^s���7�7�4�7�7�*�T�*�*rc�B�tj|jg|���Sr!)rr,rNrs rr�zfile_wrapper.sendas���8�8�D�G�G�+�d�+�+rNc�j�|tjk(r|tjk(r|sytd��)Nrz-Only asyncore specific behaviour implemented.)rjr�r��NotImplementedError)rk�level�optname�buflens rr�zfile_wrapper.getsockoptds4����*�*�*��6�?�?�*���%�'5�6�
6rc�t�|jdkry|j}d|_tj|�y)Nrr�)rNrr�rs rr�zfile_wrapper.closeos+���w�w��{�����B��D�G��H�H�R�Lrc��|jSr!)rNr�s rr�zfile_wrapper.filenovs���7�7�Nrr!)rrrrmr r�r�r�r'r,r�r�rrrrrPs1��
!� � +� ,� 6����� � rrc��eZdZdd�Zd�Zy)�file_dispatcherNc���tj|d|�d|_ |j�}|j|�t
j|d�y#t$rY�3wxYw)NTF)r_rmrfr��AttributeError�set_filer�set_blocking)rkrNrKs rrmzfile_dispatcher.__init__{s[������d�C�0�!�D�N�
��Y�Y�[��
�M�M�"���O�O�B��&�� "�
��
�s�A� A$�#A$c��t|�|_|jj�|_|j �yr!)rrjr�rcrzrs rrzfile_dispatcher.set_file�s.��&�r�*�D�K��;�;�-�-�/�D�L����rr!)rrrrmrrrrrrys�� '� rr)gN)g>@FNNr}).�__doc__r1rjr�rGrrr:rrrrrrr r
rrr
rrr�r;r@rr� Exceptionr�KeyboardInterrupt�
SystemExitr#r'r,r/r>rQrV�poll3r]r_r�r�r�r�rrrrr�<module>r!s
��B�*�
�
��� �����
�:�x��L�%� �"�#�
���'� �i� � �!2�J�?������(%�N"�4 ���$a�a�P �:��68�*�>�7�7�g��'�'�R�*��U��Q���J��s�B9�9C�C
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists