%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/internet/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/internet/__pycache__/asyncioreactor.cpython-312.pyc

�

Ϫ�fy+���dZddlZddlZddlmZmZddlmZmZm	Z	ddl
mZddlm
Z
ddlmZddlmZmZmZdd	lmZdd
lmZee�Gd�de��Zdd
�Zy)z'
asyncio-based reactor implementation.
�N)�AbstractEventLoop�get_event_loop)�Dict�Optional�Type)�implementer)�FileDescriptor)�
IReactorFDSet)�_NO_FILEDESC�PosixReactorBase�_ContinuousPolling)�Logger)�callWithLoggerc���eZdZdZdZe�Zddeef�fd�
Z	d�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zdd�Z�fd�Z�fd�Zd�Zd�Zd�Zd�Zd�Z�xZS)�AsyncioSelectorReactora�
    Reactor running on top of L{asyncio.SelectorEventLoop}.

    On POSIX platforms, the default event loop is
    L{asyncio.SelectorEventLoop}.
    On Windows, the default event loop on Python 3.7 and older
    is C{asyncio.WindowsSelectorEventLoop}, but on Python 3.8 and newer
    the default event loop is C{asyncio.WindowsProactorEventLoop} which
    is incompatible with L{AsyncioSelectorReactor}.
    Applications that use L{AsyncioSelectorReactor} on Windows
    with Python 3.8+ must call
    C{asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())}
    before instantiating and running L{AsyncioSelectorReactor}.
    F�	eventloopc���|�t�}n|}tjdk(r ddlm}t||�rt
d|����||_i|_i|_	t|�|_d|_d|_
t�|�=�y)N�win32r)�ProactorEventLoopz)ProactorEventLoop is not supported, got: )r�sys�platform�asyncior�
isinstance�	TypeError�_asyncioEventloop�_writers�_readersr
�_continuousPolling�_scheduledAt�_timerHandle�super�__init__)�selfr�
_eventloopr�	__class__s    ��A/usr/lib/python3/dist-packages/twisted/internet/asyncioreactor.pyr"zAsyncioSelectorReactor.__init__0s������,:�,<�J�"�J�
�<�<�7�"�1��*�&7�8��?�
�|�L���5?���9;��
�9;��
�"4�T�":��� ��� ���
����c�n�	|jjj|�y#t$rYywxYw)am	
        Compensate for a bug in asyncio where it will not unregister a FD that
        it cannot handle in the epoll loop. It touches internal asyncio code.

        A description of the bug by markrwilliams:

        The C{add_writer} method of asyncio event loops isn't atomic because
        all the Selector classes in the selector module internally record a
        file object before passing it to the platform's selector
        implementation. If the platform's selector decides the file object
        isn't acceptable, the resulting exception doesn't cause the Selector to
        un-track the file object.

        The failing/hanging stdio test goes through the following sequence of
        events (roughly):

        * The first C{connection.write(intToByte(value))} call hits the asyncio
        reactor's C{addWriter} method.

        * C{addWriter} calls the asyncio loop's C{add_writer} method, which
        happens to live on C{_BaseSelectorEventLoop}.

        * The asyncio loop's C{add_writer} method checks if the file object has
        been registered before via the selector's C{get_key} method.

        * It hasn't, so the KeyError block runs and calls the selector's
        register method

        * Code examples that follow use EpollSelector, but the code flow holds
        true for any other selector implementation. The selector's register
        method first calls through to the next register method in the MRO

        * That next method is always C{_BaseSelectorImpl.register} which
        creates a C{SelectorKey} instance for the file object, stores it under
        the file object's file descriptor, and then returns it.

        * Control returns to the concrete selector implementation, which asks
        the operating system to track the file descriptor using the right API.

        * The operating system refuses! An exception is raised that, in this
        case, the asyncio reactor handles by creating a C{_ContinuousPolling}
        object to watch the file descriptor.

        * The second C{connection.write(intToByte(value))} call hits the
        asyncio reactor's C{addWriter} method, which hits the C{add_writer}
        method. But the loop's selector's get_key method now returns a
        C{SelectorKey}! Now the asyncio reactor's C{addWriter} method thinks
        the asyncio loop will watch the file descriptor, even though it won't.
        N)r�	_selector�
unregister�
BaseException)r#�fds  r&�_unregisterFDInAsyncioz-AsyncioSelectorReactor._unregisterFDInAsyncioKs4��d	��"�"�,�,�7�7��;���	��	�s�%(�	4�4c�0�|r|jn|j}|j�dk(r|j|t|�y	|�}|r|j|||�yy#t
$r'}|}|jjd�Yd}~�Bd}~wwxYw�N���)�doRead�doWrite�fileno�_disconnectSelectabler�	Exception�_log�failure)r#�
selectable�read�method�why�es      r&�_readOrWritez#AsyncioSelectorReactor._readOrWrite�s���&*��"�"�
�0B�0B������"�$��&�&�z�<��F��	$��(�C���&�&�z�3��=����	$��C��I�I���d�#�#��	$�s�A%�%	B�.B�Bc���||jj�vs||jjvry|j�}	|jj|t||j|d�||j|<y#t$rU}|j|�|jtjk(r|jj|�n�Yd}~yd}~wwxYw)NT)
r�keysrr3r�
add_readerrr=�OSErrorr-�errno�EPERM�	addReader)r#�readerr,r<s    r&rDz AsyncioSelectorReactor.addReader�s����T�]�]�'�'�)�)�V�t�7N�7N�7W�7W�-W��
�]�]�_��
	��"�"�-�-��N�F�D�,=�,=�v�t�
�%'�D�M�M�&�!���	��'�'��+��w�w�%�+�+�%��'�'�1�1�&�9��:��
	�s�=B�	C#�AC�C#c���||jj�vs||jjvry|j�}	|jj|t||j|d�||j|<y#t$r/|j|�|jj|�Yyt$r|j|�Yyt$r|j|��wxYw)NF)
rr?rr3r�
add_writerrr=�PermissionErrorr-�	addWriter�BrokenPipeErrorr+�r#�writerr,s   r&rIz AsyncioSelectorReactor.addWriter�s����T�]�]�'�'�)�)�V�t�7N�7N�7W�7W�-W��
�]�]�_��	��"�"�-�-��N�F�D�,=�,=�v�u�
�%'�D�M�M�&�!���	6��'�'��+�
�#�#�-�-�f�5��	,��'�'��+��	��'�'��+��	�s�=B�5C2�<C2�C2c��||jj�vs|jj|�sy|jj|�r|jj	|�y|j�}|dk(r|jj
|�}n|jj
|�|jj|�yr/)	rr?r�	isReading�removeReaderr3�popr�
remove_reader)r#rEr,s   r&rOz#AsyncioSelectorReactor.removeReader�s���
�d�m�m�(�(�*�*�d�.E�.E�.O�.O�PV�.W�
��"�"�,�,�V�4��#�#�0�0��8��
�]�]�_��
��8����"�"�6�*�B��M�M���f�%����,�,�R�0r'c��||jj�vs|jj|�sy|jj|�r|jj	|�y|j�}|dk(r|jj
|�}n|jj
|�|jj|�yr/)	rr?r�	isWriting�removeWriterr3rPr�
remove_writerrKs   r&rTz#AsyncioSelectorReactor.removeWriter�s���
�d�m�m�(�(�*�*�d�.E�.E�.O�.O�PV�.W�
��"�"�,�,�V�4��#�#�0�0��8��
�]�]�_��
��8����"�"�6�*�B��M�M���f�%����,�,�R�0r'c��|j|jj�|jj��|jj�zS�N)�
_removeAllrr?rr�	removeAll�r#s r&rYz AsyncioSelectorReactor.removeAll�sF���O�O�D�M�M�.�.�0�$�-�-�2D�2D�2F�G��%�%�/�/�1�
2�	
r'c�~�t|jj��|jj	�zSrW)�listrr?r�
getReadersrZs r&r]z!AsyncioSelectorReactor.getReaders��.���D�M�M�&�&�(�)�D�,C�,C�,N�,N�,P�P�Pr'c�~�t|jj��|jj	�zSrW)r\rr?r�
getWritersrZs r&r`z!AsyncioSelectorReactor.getWriters�r^r'c��|jj|dz|jj�|jj�y)Ng{�G�z�?)r�
call_later�stop�run_forever)r#�timeouts  r&�iteratezAsyncioSelectorReactor.iterate�s:�����)�)�'�D�.�$�:P�:P�:U�:U�V����*�*�,r'c��|j|��|jj�|jrd|_yy)N)�installSignalHandlersF)�startRunningrrd�_justStopped)r#rhs  r&�runzAsyncioSelectorReactor.run�s<�����0E��F����*�*�,���� %�D��r'c�H��t�|��|jdd��y)Nrc��yrW�rnr'r&�<lambda>z-AsyncioSelectorReactor.stop.<locals>.<lambda>s�r')r!rc�	callLater�r#r%s �r&rczAsyncioSelectorReactor.stops���
����	
���q�,�'r'c�V��t�|��|jj�yrW)r!�crashrrcrqs �r&rszAsyncioSelectorReactor.crashs���
��
�����#�#�%r'c�R�d|_|j�|j�yrW)r�runUntilCurrent�_reschedulerZs r&�_onTimerzAsyncioSelectorReactor._onTimers"�� ����������r'c��|j�}|�v|jj�|z}||_|j�|jj�|jj
||j�|_yyrW)rer�timerr �cancel�call_atrw)r#re�abs_times   r&rvz"AsyncioSelectorReactor._reschedulesv���,�,�.�����-�-�2�2�4�w�>�H� (�D��� � �,��!�!�(�(�*� $� 6� 6� >� >�x���� W�D��r'c�P�tj||�|j�yrW)r�_moveCallLaterSoonerrv)r#�tples  r&r~z+AsyncioSelectorReactor._moveCallLaterSooners���-�-�d�D�9����r'c���tj|||g|��i|��}|jj�|j	�z}|j
�||j
kr|j
�|SrW)rrprryrerrv)r#�seconds�f�args�kwargs�dcr|s       r&rpz AsyncioSelectorReactor.callLatersi��
�
'�
'��g�q�
J�4�
J�6�
J���)�)�.�.�0�4�<�<�>�A�����$��4�3D�3D�(D������	r'c�R���������fd�}�jj|�y)Nc�2���jd�g���i���S)Nr)rp)r�r�r�r#s����r&roz7AsyncioSelectorReactor.callFromThread.<locals>.<lambda>%s���N�D�N�N�1�a�9�$�9�&�9�r')r�call_soon_threadsafe)r#r�r�r��gs```` r&�callFromThreadz%AsyncioSelectorReactor.callFromThread$s���9�����3�3�A�6r'rW)T)�__name__�
__module__�__qualname__�__doc__�_asyncClosedrr6rrr"r-r=rDrIrOrTrYr]r`rfrkrcrsrwrvr~rpr��
__classcell__)r%s@r&rrs����
��L��8�D��(�+<�"=��65�n
>��(�.1�.1�0
�Q�Q�-�&�(�&��
X���7r'rc�6�t|�}ddlm}||�y)z�
    Install an asyncio-based reactor.

    @param eventloop: The asyncio eventloop to wrap. If default, the global one
        is selected.
    r)�installReactorN)r�twisted.internet.mainr�)r�reactorr�s   r&�installr�)s��%�Y�/�G�4��7�r'rW)r�rBrrrr�typingrrr�zope.interfacer�twisted.internet.abstractr	�twisted.internet.interfacesr
�twisted.internet.posixbaserrr
�twisted.loggerr�twisted.python.logrrr�rnr'r&�<module>r�s`��
�

�
�5�'�'�&�4�5���
"�-�
�]��I7�-�I7��I7�X
r'

Zerion Mini Shell 1.0