%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__/base.cpython-312.pyc

�

Ϫ�fD��
��UdZddlZddlZddlZddlmZmZddlmZm	Z	m
Z
ddlmZddl
mZddlmZmZmZmZmZmZmZmZmZmZmZmZddlmZmZdd	lm Z m!Z!m"Z"m#Z#m$Z$m%Z%dd
l&m'Z(m)Z*m+Z,ddl-m.Z.m/Z/ddl0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?dd
l@mAZAddlBmCZCmDZDddlEmFZFddlGmHZHmIZJddlKmLZLmMZMmNZNerddlOmPZPddlBmQZQeHj��rddlSmTZTndZTee3�Gd�d��ZUee=�Gd�d��ZVee=�Gd�d��ZWedefZXeeXeeYdfeeZeYffZ[edeeZeXeeYdfeeZeYff�Z\Gd�d�Z]ee8e9�Gd �d!��Z^ed"eeZe\f�Z_eedefeeYdfeeZeYffZ`ee6e;e?�Gd#�d$e^��ZaeHj��r	eeae:�ee2�Gd%�d&e��ZbGd'�d(e j��ZdgZeeeZefd)<y)*z8
Very basic functionality for a Reactor implementation.
�N)�ABC�abstractmethod)�heapify�heappop�heappush)�format_stack)�	FrameType)�
TYPE_CHECKING�Any�Callable�Dict�List�NewType�Optional�Sequence�Set�Tuple�Union�cast)�classImplements�implementer)�abstract�defer�error�fdesc�main�threads)�ComplexResolverSimplifier�GAIResolver�SimpleResolverComplexifier)�Deferred�DeferredList)�IAddress�
IConnector�IDelayedCall�IHostnameResolver�	IProtocol�IReactorCore�IReactorFromThreads�IReactorPluggableNameResolver�IReactorPluggableResolver�IReactorThreads�IReactorTime�IReadDescriptor�IResolverSimple�IWriteDescriptor�_ISupportsExitSignalCapturing)�
ClientFactory)�log�reflect)�Failure)�platform�seconds�)�SignalHandling�_WithoutSignalHandling�_WithSignalHandling)�Client)�
threadable)�
ThreadPoolc��eZdZUdZdZeeed<dZee	eed<e
fdedede
fde	ed	eeefd
edgdfdedgdfdegefd
dfd�Zd
efd�Zdd�Zded
dfd�Zded
dfd�Zdd�Zd
efd�Zded
efd�Zded
efd�Zd
efd�Zy)�DelayedCallFN�_repr�creator�time�func.�args�kw�cancel�resetr7�returnc���||||f\|_|_|_|_||_||_||_dx|_|_d|_	|jrt�dd|_yy)aR
        @param time: Seconds from the epoch at which to call C{func}.
        @param func: The callable to call.
        @param args: The positional arguments to pass to the callable.
        @param kw: The keyword arguments to pass to the callable.
        @param cancel: A callable which will be called with this
            DelayedCall before cancellation.
        @param reset: A callable which will be called with this
            DelayedCall after changing this DelayedCall's scheduled
            execution time. The callable should adjust any necessary
            scheduling details to ensure this DelayedCall is invoked
            at the new appropriate time.
        @param seconds: If provided, a no-argument callable which will be
            used to determine the current time any time that information is
            needed.
        r�N���)
rCrDrErF�resetter�	cancellerr7�	cancelled�called�delayed_time�debugrrB)�selfrCrDrErFrGrHr7s        �7/usr/lib/python3/dist-packages/twisted/internet/base.py�__init__zDelayedCall.__init__Wsj��448��t�R�3G�0��	�4�9�d�i�����
�������'(�(���������:�:�'�>�#�2�.�D�L��c�4�|j|jzS)z�
        Return the time at which this call will fire

        @return: The number of seconds after the epoch at which this call is
            scheduled to be made.
        �rCrQ�rSs rT�getTimezDelayedCall.getTimezs���y�y�4�,�,�,�,rVc���|jrtj�|jrtj�|j|�d|_|jrt|�|_|`	|`
|`y)z�
        Unschedule this call

        @raise AlreadyCancelled: Raised if this call has already been
            unscheduled.

        @raise AlreadyCalled: Raised if this call has already been made.
        r8N)rOr�AlreadyCancelledrP�
AlreadyCalledrNrR�reprrArDrErFrYs rTrGzDelayedCall.cancel�s\���>�>��(�(�(�
�[�[��%�%�%��N�N�4� ��D�N��z�z�!�$�Z��
��	�4�9�d�grV�secondsFromNowc� �|jrtj�|jrtj�|j�|z}||jkr d|_||_|j|�y||jz
|_y)aY
        Reschedule this call for a different time

        @param secondsFromNow: The number of seconds from the time of the
            C{reset} call at which this call will be scheduled.

        @raise AlreadyCancelled: Raised if this call has been cancelled.
        @raise AlreadyCalled: Raised if this call has already been made.
        rKN)	rOrr\rPr]r7rCrQrM)rSr_�newTimes   rTrHzDelayedCall.reset�sr���>�>��(�(�(�
�[�[��%�%�%��l�l�n�~�5�G�����"�$'��!�#��	��
�
�d�#�$+�d�i�i�$7��!rV�secondsLaterc��|jrtj�|jrtj�|xj
|z
c_|j
dkr"|j
�|j|�yy)aQ
        Reschedule this call for a later time

        @param secondsLater: The number of seconds after the originally
            scheduled time for which to reschedule this call.

        @raise AlreadyCancelled: Raised if this call has been cancelled.
        @raise AlreadyCalled: Raised if this call has already been made.
        rKN)rOrr\rPr]rQ�activate_delayrM)rSrbs  rT�delayzDelayedCall.delay�sf���>�>��(�(�(�
�[�[��%�%�%�����-��� � �3�&��#�#�%��
�
�d�#�'rVc�P�|xj|jz
c_d|_y)NrKrXrYs rTrdzDelayedCall.activate_delay�s���	�	�T�&�&�&�	���rVc�8�|jxs|jS)z�Determine whether this call is still pending

        @return: True if this call has not yet been made or cancelled,
            False otherwise.
        )rOrPrYs rT�activezDelayedCall.active�s���N�N�1�d�k�k�2�2rV�otherc�`�t|t�r|j|jkStS)z�
        Implement C{<=} operator between two L{DelayedCall} instances.

        Comparison is based on the C{time} attribute (unadjusted by the
        delayed time).
        ��
isinstancer@rC�NotImplemented�rSris  rT�__le__zDelayedCall.__le__�s'���e�[�)��9�9��
�
�*�*�!�!rVc�`�t|t�r|j|jkStS)z�
        Implement C{<} operator between two L{DelayedCall} instances.

        Comparison is based on the C{time} attribute (unadjusted by the
        delayed time).
        rkrns  rT�__lt__zDelayedCall.__lt__�s'���e�[�)��9�9�u�z�z�)�)�!�!rVc
��|j�|jSt|d�rtt|jdd�}|�9t|jdd�}|� t|jdd�}|�|�d|��}|�"t	j
|j�}nd}|j
�}dt|�|j|z
|j|jfzg}|��|jd|d	f�|jrh|jd
j|jD�cgc]}t	j
|���c}��|jr|jd
�|jrc|jd
j|jj!�D��cgc]\}}|�dt	j
|�����!c}}��|jd�|j"�-|jd
dj|j"�z�|jd�dj|�Scc}wcc}}w)z�
        Implement C{repr()} for L{DelayedCall} instances.

        @returns: String containing details of the L{DelayedCall}.
        NrD�__qualname__�__name__�im_class�.z.<DelayedCall 0x%x [%ss] called=%s cancelled=%s� �(z, �=�)z

traceback at creation: 

%sz    �>�)rA�hasattr�getattrrDr4�	safe_reprr7�idrCrPrO�extendrE�append�joinrF�itemsrB)rSrD�imClass�now�L�e�k�vs        rT�__repr__zDelayedCall.__repr__�s����:�:�!��:�:���4�� ��4�9�9�n�d�;�D��|��t�y�y�*�d�;���#�%�d�i�i��T�B�G��*�")��!�D�6�2���|��(�(����3���D��l�l�n��<��$�x����S��$�+�+�t�~�~�F�
G�
����
�H�H�c�4��%�&��y�y�������$�)�)�#L�Q�G�$5�$5�a�$8�#L�M�N��7�7��H�H�T�N��w�w�����I�I�EI�W�W�]�]�_�U�6�A�q�A�3�a�� 1� 1�!� 4�5�6�U���

�H�H�S�M��<�<�#�
�H�H�8�F�K�K����<U�V�W�	����
��w�w�q�z���$M��Vs�&I�)$I
�rIN)rt�
__module__rsrRrAr�str�__annotations__rBr�runtimeSeconds�floatrr�objectr
rUrZrGrHrerd�boolrhrorqr��rVrTr@r@Ms7��
�E��E�8�C�=��(,�G�X�h�s�m�
$�+�(6�!/��!/��s�C�x� �!/��v��	!/�

��f���!/��-��$�.�/�
!/�����-�.�!/��"�e�)�$�!/�
�!/�F-��-�.�(8�E�8�d�8�.$�%�$�D�$�( �3��3�
"�F�
"�t�
"�
"�F�
"�t�
"�.�#�.rVr@c��eZdZdZdd�Zdededefd�Zdedeeddfd	�Z	d
e
eefdedeeddfd�Z	ddedee
deefd
�Zy)�ThreadedResolvera�
    L{ThreadedResolver} uses a reactor, a threadpool, and
    L{socket.gethostbyname} to perform name lookups without blocking the
    reactor thread.  It also supports timeouts indepedently from whatever
    timeout logic L{socket.gethostbyname} might have.

    @ivar reactor: The reactor the threadpool of which will be used to call
        L{socket.gethostbyname} and the I/O thread of which the result will be
        delivered.
    rINc� �||_i|_y�N)�reactor�_runningQueries)rSr�s  rTrUzThreadedResolver.__init__$s�����
�	
�rV�name�errc�N�tjd|�d|���}t|�S)N�address z not found: )r�DNSLookupErrorr5)rSr�r��lookupErrors    rT�_failzThreadedResolver._fail*s*���*�*�X�d�X�\�#��+O�P���{�#�#rV�lookupDeferredc��|j|\}}|j|=|j|j|d��y)Nz
timeout error)r��errbackr�)rSr�r��userDeferred�
cancelCalls     rT�_cleanupzThreadedResolver._cleanup.s>��#'�#7�#7��#G� ��j�� � ��0����T�Z�Z��o�>�?rV�resultc�$�	|j|\}}|j|=|j�t|t�r0|j	|j||j
���y|j|�y#t$rYywxYwr�)	r�rGrlr5r�r��getErrorMessage�callback�KeyError)rSr�r�r�r�r�s      rT�
_checkTimeoutzThreadedResolver._checkTimeout3s���	.�'+�';�';�N�'K�$�L�*��$�$�^�4������&�'�*��$�$�T�Z�Z��f�6L�6L�6N�%O�P��%�%�f�-���	��	�s�B�	B�B�timeoutc���|rt|�}nd}t�}tjt	t
|j�t	t|j�j�tj|�}t	t|j�j||j||�}||f|j|<|j|j ||�}|S)a1
        See L{twisted.internet.interfaces.IResolverSimple.getHostByName}.

        Note that the elements of C{timeout} are summed and the result is used
        as a timeout for the lookup.  Any intermediate timeout or retry logic
        is left up to the platform via L{socket.gethostbyname}.
        �<)�sumr!r�deferToThreadPoolrr)r�r,�
getThreadPool�socket�
gethostbynamer-�	callLaterr�r��addBothr�)rSr�r��timeoutDelayr�r�r��_s        rT�
getHostByNamezThreadedResolver.getHostByNameCs�����w�<�L��L�&.�j�� �2�2��$�d�l�l�3���$�,�,�/�=�=�?�� � ��	
���,����5�?�?��$�-�-��~�
�
�1=�j�/I����^�,�*�2�2�����n�
���rV)r��ReactorBaserIN�)r8���-)rtr�rs�__doc__rUr�r5r�r!r�rr�r�intr�r�rVrTr�r�s���	��$�#�$�C�$�G�$�@�S�@�(�3�-�@�D�@�
.��C��L�)�.�14�.�FN�s�m�.�	
�.�"3A����"*�3�-��	�#��rVr�c�0�eZdZ	ddedeedeefd�Zy)�BlockingResolverr�r�rIc���	tj|�}tj|�S#t$r3d|�d�}tj|�}tj|�cYSwxYw)Nr�z
 not found)r�r�r�succeed�OSErrorrr��fail)rSr�r��address�msgr�s      rTr�zBlockingResolver.getHostByNamedse��	*��*�*�4�0�G��=�=��)�)���	#��T�H�J�/�C��&�&�s�+�C��:�:�c�?�"�	#�s�,�9A(�'A(Nr�)rtr�rsr�rr�r!r�r�rVrTr�r�bs-��3A�
*��
*�"*�3�-�
*�	�#��
*rVr�.�_ThreePhaseEventTriggerHandlec
�|�eZdZdZdd�Zdededededef
d	�Z	d
eddfd�Z
d
eddfd�Zd
eddfd
�Zdd�Z
deddfd�Zy)�_ThreePhaseEventa�
    Collection of callables (with arguments) which can be invoked as a group in
    a particular order.

    This provides the underlying implementation for the reactor's system event
    triggers.  An instance of this class tracks triggers for all phases of a
    single type of event.

    @ivar before: A list of the before-phase triggers containing three-tuples
        of a callable, a tuple of positional arguments, and a dict of keyword
        arguments

    @ivar finishedBefore: A list of the before-phase triggers which have
        already been executed.  This is only populated in the C{'BEFORE'} state.

    @ivar during: A list of the during-phase triggers containing three-tuples
        of a callable, a tuple of positional arguments, and a dict of keyword
        arguments

    @ivar after: A list of the after-phase triggers containing three-tuples
        of a callable, a tuple of positional arguments, and a dict of keyword
        arguments

    @ivar state: A string indicating what is currently going on with this
        object.  One of C{'BASE'} (for when nothing in particular is happening;
        this is the initial value), C{'BEFORE'} (when the before-phase triggers
        are in the process of being executed).
    rINc�<�g|_g|_g|_d|_y)N�BASE)�before�during�after�staterYs rTrUz_ThreePhaseEvent.__init__�s��57���57���46��
���
rV�phase�callablerE�kwargsc�z�|dvrtd��t||�j|||f�t||||f�S)a�
        Add a trigger to the indicate phase.

        @param phase: One of C{'before'}, C{'during'}, or C{'after'}.

        @param callable: An object to be called when this event is triggered.
        @param args: Positional arguments to pass to C{callable}.
        @param kwargs: Keyword arguments to pass to C{callable}.

        @return: An opaque handle which may be passed to L{removeTrigger} to
            reverse the effects of calling this method.
        �r�r�r��
invalid phase)r�r~r�r�)rSr�r�rEr�s     rT�
addTriggerz_ThreePhaseEvent.addTrigger�sH��&�5�5��?�+�+���e��#�#�X�t�V�$<�=�,�e�X�t�V�-L�M�MrV�handlec�B�t|d|jz�|�y)aS
        Remove a previously added trigger callable.

        @param handle: An object previously returned by L{addTrigger}.  The
            trigger added by that call will be removed.

        @raise ValueError: If the trigger associated with C{handle} has already
            been removed or if C{handle} is not a valid handle.
        �removeTrigger_N)r~r�)rSr�s  rT�
removeTriggerz_ThreePhaseEvent.removeTrigger�s��	5���&����3�4�V�<rVc��	|\}}}}|dvrtd��t||�j|||f�y#ttf$rt	d��wxYw)zN
        Just try to remove the trigger.

        @see: removeTrigger
        r�r�zinvalid trigger handleN)r�r~�remove�	TypeError�
ValueError�rSr�r�r�rEr�s      rT�removeTrigger_BASEz#_ThreePhaseEvent.removeTrigger_BASE�sj��	B�,2�)�E�8�T�6��9�9���/�/��D�%� �'�'��4��(@�A���:�&�	7��5�6�6�	7�s	�7�Ac��|\}}}}|dk7r|j|�S|||f|jvrtjdtd��y|j|�y)z�
        Remove the trigger if it has yet to be executed, otherwise emit a
        warning that in the future an exception will be raised when removing an
        already-executed trigger.

        @see: removeTrigger
        r�zdRemoving already-fired system event triggers will raise an exception in a future version of Twisted.r�)�category�
stacklevelN)r��finishedBefore�warnings�warn�DeprecationWarningr�s      rT�removeTrigger_BEFOREz%_ThreePhaseEvent.removeTrigger_BEFORE�sg��)/�%��x��v��H���*�*�6�2�2��d�F�#�t�':�':�:��M�M�<�+��	
�
�#�#�F�+rVc��d|_g|_g}|jru|jjd�\}}}|jj	|||f�	||i|��}t|t�r|j	|�	|jr�ut|�j|j�y#t$rtj�Y�QwxYw)z8
        Call the triggers added to this event.
        �BEFORErN)
r�r�r��popr�rlr!�
BaseExceptionr3r�r"�addCallback�_continueFiring)rS�
beforeResultsr�rEr�r�s      rT�	fireEventz_ThreePhaseEvent.fireEvent�s�����
� ���02�
��k�k�%)�[�[�_�_�Q�%7�"�H�d�F����&�&��$��'?�@�
1�!�4�2�6�2���f�h�/�!�(�(��0��k�k�	�]�#�/�/��0D�0D�E��!�
����	�
�s�B7�7C�C�ignoredc���d|_g|_|j|jfD]&}|s�|j	d�\}}}	||i|��|r�!�(y#t
$rt
j�Y�%wxYw)zJ
        Call the during and after phase triggers for this event.
        r�rN)r�r�r�r�r�r�r3r�)rSr�r�r�rEr�s      rTr�z _ThreePhaseEvent._continueFiring�sw����
� ����[�[�$�*�*�,�	�E��).���1��&��$����d�-�f�-��	��
%���G�G�I��s�A�A1�0A1r�)rtr�rsr�rUr��_ThreePhaseEventTriggerCallabler�r�r�r�r�r�r�r�r�rVrTr�r�{s����:�N��N�2�N��	N�
�N�
'�
N�0
=�$A�
=�d�
=�
B�)F�
B�4�
B�,�+H�,�T�,�*F�&�v��$�rVr�c�z�eZdZUdZe�Zeed<ee�Z	e
ed<dedefd�Zde
de
fd�Ze
de
fd��Zy)	�PluggableResolverMixinz�
    A mixin which implements the pluggable resolver reactor interfaces.

    @ivar resolver: The installed L{IResolverSimple}.
    @ivar _nameResolver: The installed L{IHostnameResolver}.
    �resolver�
_nameResolverrIc�z�tj|�sJ�|j}||_t|�|_|S)z�
        See L{IReactorPluggableResolver}.

        @param resolver: see L{IReactorPluggableResolver}.

        @return: see L{IReactorPluggableResolver}.
        )r/�
providedByr��_SimpleResolverComplexifierr�)rSr��oldResolvers   rT�installResolverz&PluggableResolverMixin.installResolvers;���)�)�(�3�3�3��m�m�� ��
�8��B����rVc�L�|j}||_t|�|_|S)z�
        See L{IReactorPluggableNameResolver}.

        @param resolver: See L{IReactorPluggableNameResolver}.

        @return: see L{IReactorPluggableNameResolver}.
        )r��_ComplexResolverSimplifierr�)rSr��previousNameResolvers   rT�installNameResolverz*PluggableResolverMixin.installNameResolver%s*�� $�1�1��%���2�8�<��
�#�#rVc��|jS)zd
        Implementation of read-only
        L{IReactorPluggableNameResolver.nameResolver}.
        )r�rYs rT�nameResolverz#PluggableResolverMixin.nameResolver2s���!�!�!rVN)rtr�rsr�r�r�r/r�r�r�r&r�r�propertyrr�rVrTr�r�	sj���!1� 2�H�o�2�'B�8�'L�M�$�L����O��$�,=�$�BS�$��"�/�"��"rVr��_SystemEventIDc���eZdZUdZdZdZdZdZdZe	�Z
eed<dZdL�fd�Z
dZeed	<d
edefd�Zdefd�Zd
eddfd�Zd
eddfd�ZdMd
eddfd�ZdLd�ZdZdLd�ZdLd�Zdeeddfd�Zd
eddfd�Zdeddfd�Zd
eddfd�Z deddfd�Z!de"e#eeffd�Z$de"efd�Z%de"efd�Z&	dNde'de(e)de*e'fd �Z+dLd!�Z,dLd"�Z-dOd#e)d$ee.ddfd%�Z/dOd#e)d$ee.ddfd&�Z0dOd#e)d$ee.ddfd'�Z1dLd(�Z2dPdeddfd)�Z3d*e'ddfd+�Z4d,e'd*e'd-e5d.e6fd/e7d0e7de8fd1�Z9d2e8ddfd3�Z:d-e5d.e6fd/e7d0e7dee8fd4�Z;dMd
eddfd5�Z<dLd6�Z=e>e?�Z@ded-e5d.e6fd/e7d7e7deAf
d8�ZBd9eAddfd:�ZCd9eAddfd;�ZDde(eEfd<�ZFdLd=�ZGdeefd>�ZHdLd?�ZIeJj��rNeL�J�dZMdZNdZOdLd@�ZPdAe5d.e6fd/e7d0e7ddfdB�ZQdLdC�ZRdLdD�ZSdLdE�ZTdeLfdF�ZUdGe5d.e6fd/e7d0e7ddfdH�ZVdIe)ddfdJ�ZW�xZXSdAe5d.e6fd/e7d0e7ddfdK�ZQ�xZXS)Qr�a�
    Default base class for Reactors.

    @ivar _stopped: A flag which is true between paired calls to C{reactor.run}
        and C{reactor.stop}.  This should be replaced with an explicit state
        machine.
    @ivar _justStopped: A flag which is true between the time C{reactor.stop}
        is called and the time the shutdown system event is fired.  This is
        used to determine whether that event should be fired after each
        iteration through the mainloop.  This should be replaced with an
        explicit state machine.
    @ivar _started: A flag which is true from the time C{reactor.run} is called
        until the time C{reactor.run} returns.  This is used to prevent calls
        to C{reactor.run} on a running reactor.  This should be replaced with
        an explicit state machine.
    @ivar running: See L{IReactorCore.running}
    @ivar _registerAsIOThread: A flag controlling whether the reactor will
        register the thread it is running in as the I/O thread when it starts.
        If C{True}, registration will be done, otherwise it will not be.
    @ivar _exitSignal: See L{_ISupportsExitSignalCapturing._exitSignal}

    @ivar _installSignalHandlers: A flag which indicates whether any signal
        handlers will be installed during startup.  This includes handlers for
        SIGCHLD to monitor child processes, and SIGINT, SIGTERM, and SIGBREAK

    @ivar _signals: An object which knows how to install and uninstall the
        reactor's signal-handling behavior.
    TFN�_signals�twisted.internet.reactorrIc����t�|��g|_i|_g|_g|_d|_d|_d|_d|_	d|_
t�|_d|_
|jdd|j�|jdd|j �|jdd|j"�t%j&�r|j)�|j+�y)NrFr��startup�shutdown)�superrU�threadCallQueue�_eventTriggers�_pendingTimedCalls�_newTimedCalls�_cancellations�running�_started�_justStopped�_startedBefore�set�_internalReaders�waker�addSystemEventTrigger�_reallyStartRunning�crash�
disconnectAllr6�supportsThreads�_initThreads�installWaker)rS�	__class__s �rTrUzReactorBase.__init__ms����
����24���;=���57���13�����������
�!���#���+.�%�����
�
	
�"�"�8�Y��8P�8P�Q��"�"�8�Z����D��"�"�8�Z��9K�9K�L��#�#�%��������rV�_installSignalHandlers�installSignalHandlersc�:�|r|j�St�S)z�
        Get an appropriate signal handling object.

        @param installSignalHandlers: Indicate whether to even try to do any
            signal handling.  If C{False} then the result will be a no-op
            implementation.
        )�_signalsFactoryr:�rSr$s  rT�_makeSignalHandlingzReactorBase._makeSignalHandling�s��!��'�'�)�)�%�'�'rVc�X�t|j|j|j�S)z�
        Get a signal handling object that implements the basic behavior of
        stopping the reactor on SIGINT, SIGBREAK, and SIGTERM.
        )r;�sigInt�sigBreak�sigTermrYs rTr&zReactorBase._signalsFactory�s&��
#��K�K��M�M��L�L�
�	
rV�readerc�\�|jj|�|j|�y)z�
        Add a read descriptor which is part of the implementation of the
        reactor itself.

        The read descriptor will not be removed by L{IReactorFDSet.removeAll}.
        N)r�add�	addReader�rSr-s  rT�_addInternalReaderzReactorBase._addInternalReader�s$��	
���!�!�&�)����v�rVc�\�|jj|�|j|�y)zm
        Remove a read descriptor which is part of the implementation of the
        reactor itself.
        N)rr��removeReaderr1s  rT�_removeInternalReaderz!ReactorBase._removeInternalReader�s&��
	
���$�$�V�,����&�!rVc��|j|��	|j�|jj�y#|jj�wxYw)N)r$)�startRunning�mainLoopr	�	uninstallr's  rT�runzReactorBase.run�sC�����0E��F�	&��M�M�O��M�M�#�#�%��D�M�M�#�#�%�s	�?�Ac��|jr~	|jrN|j�|j�}|jxr|}|j	|�|jr�Ntjd�|jr�}yy#t$r,tjd�tj�Y�CwxYw)NzMain loop terminated.zUnexpected error in main loop.)	r�runUntilCurrentr�r�doIterationr3r�r�r�)rS�t2�ts   rTr8zReactorBase.mainLoop�s����m�m�
1��m�m��(�(�*�����B����+��A��$�$�Q�'�
�m�m����/�0��m�m��!�
����8�9����	�
�s�AB�2C�Cc�X�ttj|j�dz��)Nz did not implement installWaker��NotImplementedErrorr4�qualr"rYs rTr!zReactorBase.installWaker��%��!��L�L����(�+L�L�
�	
rVc�R�|jr|jj�yy)z)
        Wake up the event loop.
        N)r�wakeUprYs rTrFzReactorBase.wakeUp�s ���:�:��J�J����rVrec�X�ttj|j�dz��)zV
        Do one iteration over the readers and writers which have been added.
        z did not implement doIterationrA�rSres  rTr=zReactorBase.doIteration�s'��"��L�L����(�+K�K�
�	
rVc�X�ttj|j�dz��)Nz did not implement addReaderrAr1s  rTr0zReactorBase.addReader��%��!��L�L����(�+I�I�
�	
rV�writerc�X�ttj|j�dz��)Nz did not implement addWriterrA�rSrKs  rT�	addWriterzReactorBase.addWriter�rJrVc�X�ttj|j�dz��)Nz did not implement removeReaderrAr1s  rTr4zReactorBase.removeReader�rDrVc�X�ttj|j�dz��)Nz did not implement removeWriterrArMs  rT�removeWriterzReactorBase.removeWriter�rDrVc�X�ttj|j�dz��)Nz did not implement removeAllrArYs rT�	removeAllzReactorBase.removeAll�rJrVc�X�ttj|j�dz��)Nz did not implement getReadersrArYs rT�
getReaderszReactorBase.getReaders��%��!��L�L����(�+J�J�
�	
rVc�X�ttj|j�dz��)Nz did not implement getWritersrArYs rT�
getWriterszReactorBase.getWritersrVrVr�r�c��|stjd�Stj|�rtj|�S|jj||�S)z8
        Return a Deferred that will resolve a hostname.z0.0.0.0)rr�r�isIPAddressr�r�)rSr�r�s   rT�resolvezReactorBase.resolve	sJ��
��=�=��+�+�����%��=�=��&�&��}�}�*�*�4��9�9rVc�p�|jrtjd��d|_d|_d|_y)zD
        See twisted.internet.interfaces.IReactorCore.stop.
        z&Can't stop reactor that isn't running.TN)�_stoppedr�ReactorNotRunningrrrYs rT�stopzReactorBase.stops4���=�=��)�)�*R�S�S���
� ���"��rVc�Z�d|_d|_|jdd|j�y)z�
        See twisted.internet.interfaces.IReactorCore.crash.

        Reset reactor state tracking attributes and re-initialize certain
        state-transition helpers which were set up in C{__init__} but later
        destroyed (through use).
        Fr�rN)rrrrrYs rTrzReactorBase.crashs*����
�����"�"�8�Y��8P�8P�QrV�number�framec�r�tjd�|j|j�||_y)z�
        Handle a SIGINT interrupt.

        @param number: See handler specification in L{signal.signal}
        @param frame: See handler specification in L{signal.signal}
        zReceived SIGINT, shutting down.N�r3r��callFromThreadr_�_exitSignal�rSrarbs   rTr*zReactorBase.sigInt+s+��	���1�2����D�I�I�&�!��rVc�r�tjd�|j|j�||_y)z�
        Handle a SIGBREAK interrupt.

        @param number: See handler specification in L{signal.signal}
        @param frame: See handler specification in L{signal.signal}
        z!Received SIGBREAK, shutting down.Nrdrgs   rTr+zReactorBase.sigBreak6s+��	���3�4����D�I�I�&�!��rVc�r�tjd�|j|j�||_y)z�
        Handle a SIGTERM interrupt.

        @param number: See handler specification in L{signal.signal}
        @param frame: See handler specification in L{signal.signal}
        z Received SIGTERM, shutting down.Nrdrgs   rTr,zReactorBase.sigTermAs+��	���2�3����D�I�I�&�!��rVc��|j�}|D]:}tj||jt	t
j���<y)z2Disconnect every reader, and writer in the system.N)rSr3�callWithLogger�connectionLostr5r�CONNECTION_LOST)rS�selectablesr-s   rTrzReactorBase.disconnectAllLsC���n�n�&��!�	�F������-�-�w�t�7K�7K�/L�
�	rVc�F�|j�|j|�y)zG
        See twisted.internet.interfaces.IReactorCore.iterate.
        N)r<r=rHs  rT�iteratezReactorBase.iterateTs��	
��������rV�	eventTypec�`�|jj|�}|�|j�yy)zO
        See twisted.internet.interfaces.IReactorCore.fireSystemEvent.
        N)r�getr�)rSrq�events   rT�fireSystemEventzReactorBase.fireSystemEvent[s/���#�#�'�'�	�2�����O�O��rVr�r�.rEr�c���tj|�s
J|�d���||jvrt�|j|<t	||j|j
||g|��i|��f�S)zU
        See twisted.internet.interfaces.IReactorCore.addSystemEventTrigger.
        � is not callable)�builtinsr�rr�rr�)rSr�rqr�rEr�s      rTrz!ReactorBase.addSystemEventTriggercs���� � ��*�I�x�j�8H�,I�I�*��D�/�/�/�-=�-?�D���	�*���9��#�#�I�.�9�9��8��&*��.4��
�
�	
rV�	triggerIDc�J�|\}}|j|j|�y)zX
        See twisted.internet.interfaces.IReactorCore.removeSystemEventTrigger.
        N)rr�)rSryrqr�s    rT�removeSystemEventTriggerz$ReactorBase.removeSystemEventTriggerzs'��&��	�6����I�&�4�4�V�<rVc�\�|jr	||i|��y|jdd|g|��i|��S)zO
        See twisted.internet.interfaces.IReactorCore.callWhenRunning.
        Nr�r)rr)rSr�rEr�s    rT�callWhenRunningzReactorBase.callWhenRunning�sG���<�<��d�%�f�%��-�4�-�-���H��/3��7=��
rVc�p�|jrtj��|jrtj��|j
j
�||_|j|�|_d|_d|_	|jrtj�|jd�y)ax
        Method called when reactor starts: do some initialization and fire
        startup events.

        Don't call this directly, call reactor.run() instead: it should take
        care of calling this.

        This method is somewhat misnamed.  The reactor will not necessarily be
        in the running state by the time this method returns.  The only
        guarantee is that it will be on its way to the running state.

        @param installSignalHandlers: A flag which, if set, indicates that
            handlers for a number of (implementation-defined) signals should be
            installed during startup.
        TFrN)rr�ReactorAlreadyRunningr�ReactorNotRestartabler	r9r#r(r]�_registerAsIOThreadr=�registerAsIOThreadrur's  rTr7zReactorBase.startRunning�s��� �=�=��-�-�/�/�����-�-�/�/��
�
���!�&;��#��0�0�1F�G��
���
���
��#�#��)�)�+����Y�'rVc�`�d|_|jr|jj�yy)z�
        Method called to transition to the running state.  This should happen
        in the I{during startup} event trigger phase.
        TN)rr#r	�installrYs rTrzReactorBase._reallyStartRunning�s+��
����&�&�
�M�M�!�!�#�'rVrFc	��tj|�s
J|�d���|dk\s
J|�d���t|j�|z||||j|j
|j��}|jj|�|S)zI
        See twisted.internet.interfaces.IReactorTime.callLater.
        rwrz* is not greater than or equal to 0 seconds)r7)rxr�r@r7�_cancelCallLater�_moveCallLaterSoonerrr�)rSrer�rErF�delayedCalls      rTr�zReactorBase.callLater�s���� � ��*�I�x�j�8H�,I�I�*���z�O�e�W�$N�O�O�z�!��L�L�N�U�"�����!�!��%�%��L�L�
��	
���"�"�;�/��rVr�c��|j}	|j|�}||}|dk7r!|dz
dz}|||krn||||<|}|dk7r�!|||<y#t$rYywxYw)Nrr8�)r�indexr�)rSr��heap�pos�elt�parents      rTr�z ReactorBase._moveCallLaterSooner�s����&�&��	��*�*�[�)�C��s�)�C���(���'�a�����<�3�&�� ��L��S�	���
��(��D��I���	��	�s�;A�
A�	A�Ac�.�|xjdz
c_y�Nr8)r)rSr�s  rTr�zReactorBase._cancelCallLater�s�����q� �rVc�r�|j|jzD�cgc]}|js|��c}Scc}w)zQ
        See L{twisted.internet.interfaces.IReactorTime.getDelayedCalls}
        )rrrO)rS�xs  rT�getDelayedCallszReactorBase.getDelayedCalls�s<���-�-��0C�0C�C�
���;�;�
�
�	
��
s�4c���|jD]J}|jr|xjdzc_�%|j�t	|j
|��Lg|_yr�)rrOrrdrr)rS�calls  rT�_insertNewDelayedCallsz"ReactorBase._insertNewDelayedCalls�sU���'�'�	8�D��~�~��#�#�q�(�#��#�#�%���0�0�$�7�	8�!��rVc��|j�|jsy|jdj|j�z
}d}t	dt||��S)z�
        Determine the longest time the reactor may sleep (waiting on I/O
        notification, perhaps) before it must wake up to service a time-related
        event.

        @return: The maximum number of seconds the reactor may sleep.
        Nri�� )r�rrCr7�max�min)rSre�longests   rTr�zReactorBase.timeout�sZ��	
�#�#�%��&�&���'�'��*�/�/�$�,�,�.�@�����1�c�'�5�)�*�*rVc���|jrld}t|j�}|jD]\}}}	||i|��|dz
}||k(s�n|jd|�=|jr|j�|j
�|j�}|jr�|jdj|kr�t|j�}|jr|xjdzc_�_|jdkDr'|j�t|j|���	d|_|j"|j$i|j&��|jr|jdj|kr��|jd
kDrm|jt|j�dz	kDrHd|_|jD�	cgc]}	|	jr�|	��c}	|_t3|j�|j4rd|_|j7d�yy#t$rtj�Y��wxYw#t$r�tj�|j(�bd}|dz
}|dz
}|dj+|j(�j-�j/dd	�z
}|dz
}tj0|�Y��}wxYwcc}	w)
z.
        Run all pending timed calls.
        rr8NrK�
z? C: previous exception occurred in a DelayedCall created here:
z C:r|z
 C:�2Fr
)r�lenr�r3r�rFr�r7rrCrrOrrQrdrrPrDrErFrBr��rstrip�replacer�rrru)
rS�count�total�f�arFr�r�r�r�s
          rTr<zReactorBase.runUntilCurrents�������E���,�,�-�E� �0�0�
���1�b���q�K�B�K���
���E�>��
��$�$�V�e�V�,��#�#����
�	
�#�#�%��l�l�n���%�%�4�+B�+B�1�+E�+J�+J�c�+Q��4�2�2�3�D��~�~��#�#�q�(�#��� � �3�&��#�#�%���0�0�$�7��
������	�	�4�9�9�0����0��%�%�4�+B�+B�1�+E�+J�+J�c�+Q�8
���"�$��#�#�c�$�*A�*A�&B�a�&G�G�"#�D���2�2�'��!�+�+��'�D�#�
�D�+�+�,���� %�D��� � ��,���e%���G�G�I���6!�
����	��<�<�+��A��:��A���J�A��������.�5�5�7�?�?��g�N�N�A���I�A��G�G�A�J��
��$'s0�H'�/-I�K� K�'I�I�BK�Kc�x�|jttt|�|j��d|_y)NT)r�_GAIResolverrr,r��usingThreadsrYs rTr zReactorBase._initThreadshs1���$�$��T�/�4�8�$�:L�:L�M�
�!%�D�rVr�c��t|�s
J|�d���|jj|||f�|j�y)zl
            See
            L{twisted.internet.interfaces.IReactorFromThreads.callFromThread}.
            rwN)r�rr�rF�rSr�rEr�s    rTrezReactorBase.callFromThreadqsC���A�;�6�1�#�%5� 6�6�;�
� � �'�'��D�&�(9�:��K�K�MrVc��tddd�|_|j|jj�|_|jdd|j�|_y)zO
            Create the threadpool accessible with callFromThread.
            r�
r
r�r
N)r>�
threadpoolr}�start�_threadpoolStartupIDr�_stopThreadPool�threadpoolShutdownIDrYs rT�_initThreadPoolzReactorBase._initThreadPoolsR��)��B�0J�K�D�O�(,�(<�(<�T�_�_�=R�=R�(S�D�%�(,�(B�(B��*�d�&:�&:�)�D�%rVc�8�|jj�yr�)r	r9rYs rT�_uninstallHandlerzReactorBase._uninstallHandler�s���M�M�#�#�%rVc��|j|jg}td|�D]}	|j|��d|_d|_|j
�J�|j
j
�d|_y#t$rY�`wxYw)a4
            Stop the reactor threadpool.  This method is only valid if there
            is currently a threadpool (created by L{_initThreadPool}).  It
            is not intended to be called directly; instead, it will be
            called by a shutdown trigger created in L{_initThreadPool}.
            N)r�r��filterr{r�r�r_)rS�triggers�triggers   rTr�zReactorBase._stopThreadPool�s����1�1�4�3L�3L�M�H�!�$��1�
����1�1�'�:�
�
)-�D�%�(,�D�%��?�?�.�.�.��O�O� � �"�"�D�O��
"����s�A:�:	B�Bc�n�|j�|j�|j�J�|jS)z[
            See L{twisted.internet.interfaces.IReactorThreads.getThreadPool}.
            )r�r�rYs rTr�zReactorBase.getThreadPool�s4�����&��$�$�&����2�2�2��?�?�"rV�	_callablec�L�|j�j|g|��i|��y)z\
            See L{twisted.internet.interfaces.IReactorInThreads.callInThread}.
            N)r��callInThread)rSr�rEr�s    rTr�zReactorBase.callInThread�s'��
.�D��� �-�-�i�I�$�I�&�IrV�sizec�D�|j�j|��y)zc
            See L{twisted.internet.interfaces.IReactorThreads.suggestThreadPoolSize}.
            )�
maxthreadsN)r��adjustPoolsize)rSr�s  rT�suggestThreadPoolSizez!ReactorBase.suggestThreadPoolSize�s��
��� �/�/�4�/�@rVc�j�t|�s
J|�d���|jj|||f�y)Nrw)r�rr�r�s    rTrezReactorBase.callFromThread�s8���A�;�6�1�#�%5� 6�6�;�� � �'�'��D�&�(9�:rVr�)Tr�r�)rK)Yrtr�rsr�r�r]�	installedr�rfr:r	r9r�rUr#r�r(r&r.r2r5r:r8�_lockr!rFrr�r=r0r0rNr4rQrrrSrUrXr�rr�r!r[r_rr	r*r+r,rrprurrr�rrr{r}r7r�staticmethodr�r7r@r�r�r�r%r�r�r�r<r6rr>r�r�r�r rer�r�r�r�r�r��
__classcell__)r"s@rTr�r�?sG����:���H��I��L��K� 6�7�H�n�7�)�H��8$)��D�(�
(��
(�.�
(�	
��	
����T��"�O�"��"�&��&��&�1�$
�E�
�
 �
��%��
�T�
�
��
�D�
�

� 0�
�T�
�

�?�
�t�
�

�#3�
��
�

�4��o�7G�&G� H�I�
�

�D��1�
�

�D�!1�2�
�3A�
:��
:�"*�3�-�
:�	�#��
:�#�
R�	"�S�	"��)�)<�	"��	"�	"�s�	"�8�I�+>�	"�$�	"�	"�c�	"�(�9�*=�	"��	"�� �U� �T� ������
��
��
��3��8�$�	
�
�
��

�
�
�.=�.�=�T�=�� ��c��*��39��EK��	�.�	!��(�$�(�$�(�>
$�"�>�*�G����&.�s�C�x�&8��AG��OU��	��(�����(!�K�!�D�!�
��,�!7�
�!�+��%��+�8A-�H �x���!��%�%�%��
�#��#��	%�	��c�3�h�'�	�06�	�BH�	�
�	�	�	&�	#�&	#�:�	#�	J�%�c�3�h�/�	J�8>�	J�JP�	J�
�	J�	A�c�	A�d�	A�	;��c�3�h�'�	;�06�	;�BH�	;�
�	;rVr�c��eZdZdZdZdZdedededdfd�Z	dd	�Z
edd
��Zdd�Z
dd�Zdd
�Zdedeefd�Zdeddfd�Zdeddfd�Zdefd�Zdefd�Zy)�
BaseConnectorzm
    Basic implementation of L{IConnector}.

    State can be: "connecting", "connected", "disconnected"
    Nr�factoryr�r�rIc�<�d|_||_||_||_y)N�disconnected)r�r�r�r�)rSr�r�r�s    rTrUzBaseConnector.__init__�s ��$��
���������rVc��|jdk(r|j�y|jdk(r)|j�J�|jj�yy)z!Disconnect whatever our state is.�
connecting�	connectedN)r��stopConnecting�	transport�loseConnectionrYs rT�
disconnectzBaseConnector.disconnect�sK���:�:��%����!�
�Z�Z�;�
&��>�>�-�-�-��N�N�)�)�+�'rVc��yr�r�rYs rT�_makeTransportzBaseConnector._makeTransport�s��rVc��|jdk7rtd��d|_|js!|jj	�d|_|j�|_|j�R|jj|j|jjtj��|_
|jj|�y)z"Start connection to remote server.r�zcan't connect in this stater�r8N)r��RuntimeError�factoryStartedr��doStartr�r�r�r�r��failIfNotConnectedr�TimeoutError�	timeoutID�startedConnectingrYs rT�connectzBaseConnector.connect�s����:�:��'��<�=�=�!��
��"�"��L�L� � �"�"#�D��+/�+>�+>�+@����<�<�#�!�\�\�3�3����d�n�n�?�?��AS�AS�AU��D�N�	
���&�&�t�,rVc���|jdk7rtjd��|j�J�d|_|jj	tj
��|`y)zStop attempting to connect.r�zwe're not trying to connectNr�)r�r�NotConnectingErrorr�r��	UserErrorrYs rTr�zBaseConnector.stopConnecting�sU���:�:��%��*�*�+H�I�I��~�~�)�)�)�#��
����)�)�%�/�/�*;�<��NrVc�v�|j�	|jj�|`yy#t$rY�wxYwr�)r�rGr�rYs rT�
cancelTimeoutzBaseConnector.cancelTimeoutsA���>�>�%�
����%�%�'���&���
��
�s�,�	8�8�addrc�f�d|_|j�|jj|�S)Nr�)r�r�r��
buildProtocol)rSr�s  rTr�zBaseConnector.buildProtocols*�� ��
������|�|�)�)�$�/�/rV�reasonc���|j�d|_d|_|jj	||�|jdk(r"|jj�d|_yy�Nr�r)r�r�r�r��clientConnectionFailed�doStopr��rSr�s  rT�connectionFailedzBaseConnector.connectionFailed
sY���������#��
����+�+�D�&�9��:�:��'��L�L���!�"#�D��(rVc��d|_|jj||�|jdk(r"|jj�d|_yyr�)r�r��clientConnectionLostr�r�r�s  rTrlzBaseConnector.connectionLostsF��#��
����)�)�$��7��:�:��'��L�L���!�"#�D��(rVc�X�ttj|j�dz��)Nz! did not implement getDestinationrArYs rT�getDestinationzBaseConnector.getDestinations%��!��L�L����(�+Q�Q�
�	
rVc��djtj|j�t	|�|j
|j
��S)Nz<{} instance at 0x{:x} {} {}>)�formatr4rCr"r�r�r�rYs rTr�zBaseConnector.__repr__$s?��.�5�5��L�L����(��t�H��J�J����!�	
�	
rVr�)rIr<)rtr�rsr�r�r�r2r�r�rUr�rr�r�r�r�r#rr'r�r5r�rlr�r�r�r�rVrTr�r��s�����I��N��$��/4��?J��	
��,��
��
�-� ��0�(�0�x�	�/B�0�
$�w�$�4�$�$�W�$��$�
��
�

�#�
rVr�c��eZdZUdZdZejed<dZejed<dej
fd�Z
deefd�Z
y)�BasePortziBasic implementation of a ListeningPort.

    Note: This does not actually implement IListeningPort.
    N�
addressFamily�
socketTyperIc���tj|j|j�}|jd�t	j
|j
��|S)NF)r�r�r��setblockingr�_setCloseOnExec�fileno)rS�ss  rT�createInternetSocketzBasePort.createInternetSocket6sA���M�M�$�,�,�d�o�o�>��	�
�
�e��
���a�h�h�j�)��rVc�X�tdtj|j�z��)zRaises a RuntimeErrorzdoWrite called on a %s)r�r4rCr"rYs rT�doWritezBasePort.doWrite<s ���3�g�l�l�4�>�>�6R�R�S�SrV)rtr�rsr�r�r��
AddressFamilyr�r��
SocketKindr�rr5r�r�rVrTr�r�-sL���
+/�M�6�'�'�.�$(�J��!�!�(��f�m�m��T��'�*�TrVr��__all__)gr�rxr�r��abcrr�heapqrrr�	tracebackr�typesr	�typingr
rrr
rrrrrrrr�zope.interfacerr�twisted.internetrrrrrr�twisted.internet._resolverrrrr�r r��twisted.internet.deferr!r"�twisted.internet.interfacesr#r$r%r&r'r(r)r*r+r,r-r.r/r0r1�twisted.internet.protocolr2�twisted.pythonr3r4�twisted.python.failurer5�twisted.python.runtimer6r7r�r	r9r:r;�twisted.internet.tcpr<r=r�twisted.python.threadpoolr>r@r�r�r�r�r��_ThreePhaseEventTriggerr�r�r�r�_ThreadCallr�r��FileDescriptorr�rr�r�rVrT�<module>rsr��
�
�
��#�,�,�"��
�
�
�
�8�I�I���
:������"4�'�*�F�Q�Q��+�&��8����4��J�
�\��F�F��F�R
�_��G�G��G�T
�_��*�*��*�#+�3��8�"4���#�U�6�3�;�%7��c�6�k�9J�J���!(�#�	�#�.��f�c�k�0B�D��f��DU�
U�V�!��K�K�\
�
*�,E�F�."�."�G�."�b�)�5��6S�1S�+T�U���H�S�#�X�&��f�c�k�(:�D��f��<M�M�N��
�\�<�)F�G�@
;�(�@
;�H�@
;�F�8�����K��1�
�Z��b
�C�b
��b
�JT�x�&�&�T�(���c��rV

Zerion Mini Shell 1.0