%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/landscape/lib/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/landscape/lib/__pycache__/reactor.cpython-312.pyc

�

�~�e�"���dZddlZddlZddlmZddlmZGd�de�ZGd�de�Z	Gd	�d
�Z
Gd�d�ZGd
�d�ZGd�de�Z
y)zB
Extend the regular Twisted reactor with event-handling features.
�N)�
deferToThread)�
format_objectc��eZdZdZy)�	InvalidIDz=Raised when an invalid ID is used with reactor.cancel_call().N��__name__�
__module__�__qualname__�__doc__���7/usr/lib/python3/dist-packages/landscape/lib/reactor.pyrrs��Gr
rc��eZdZdZy)�
CallHookErrorz-Raised when hooking on a reactor incorrectly.Nrrr
rrrs��7r
rc��eZdZdZd�Zy)�EventIDz�Unique identifier for an event handler.

    @param event_type: Name of the event type handled by the handler.
    @param pair: Binary tuple C{(handler, priority)} holding the handler
        function and its priority.
    c� �||_||_y�N)�_event_type�_pair)�self�
event_type�pairs   r�__init__zEventID.__init__s��%�����
r
N)rr	r
rrrr
rrrs���r
rc�6��eZdZdZ�fd�Zdd�Zd�Zd�Z�xZS)�EventHandlingReactorMixina�Fire events identified by strings and register handlers for them.

    Note that event handlers are executed synchronously when the C{fire} method
    is called, so unit-tests can generally exercise events without needing to
    run the real Twisted reactor (except of course if the event handlers
    themselves contain asynchronous calls that need the Twisted reactor
    running).
    c�0��t�|��i|_yr)�superr�_event_handlers)r�	__class__s �rrz"EventHandlingReactorMixin.__init__+s���
����!��r
c��||f}|jj|g�}|j|�|jd���t	||�S)a�Register an event handler.

        The handler will be invoked every time an event of the given type
        is fired (there's no need to re-register the handler after the
        event is fired).

        @param event_type: The name of the event type to handle.
        @param handler: The function handling the given event type.
        @param priority: The priority of the given handler function.

        @return: The L{EventID} of the registered handler.
        c��|dS)N�r)rs r�<lambda>z3EventHandlingReactorMixin.call_on.<locals>.<lambda>@s
��t�A�w�r
)�key)r�
setdefault�append�sortr)rr�handler�priorityr�handlerss      r�call_onz!EventHandlingReactorMixin.call_on/sN����"���'�'�2�2�:�r�B��������
�
�.�
�/��z�4�(�(r
c	�
�tjd|�g}t|jj	|d��}|D]>\}}	tjdt|�||�|j
||i|����@tjd|�|S#t$r4tjdt|�|||�|j��t$r%tjdt|�|||�Y��wxYw)acFire an event of a given type.

        Call all handlers registered for the given C{event_type}, in order
        of priority.

        @param event_type: The name of the event type to fire.
        @param args: Positional arguments to pass to the registered handlers.
        @param kwargs: Keyword arguments to pass to the registered handlers.
        zStarted firing %s.rz#Calling %s for %s with priority %d.zTKeyboard interrupt while running event handler %s for event type %r with args %r %r.zAError running event handler %s for event type %r with args %r %r.zFinished firing %s.)�logging�debug�listr�getrr'�KeyboardInterrupt�	exception�stop�	Exception)rr�args�kwargs�resultsr+r)r*s        r�firezEventHandlingReactorMixin.fireDs��	�
�
�*�J�7�����,�,�0�0��R�@�A��!)�	��G�X�
��
�
�9�!�'�*���	����w��7��7�8�	�<	�
�
�+�Z�8����-%�
��!�!�"�"�'�*������	�	����
��!�!�5�!�'�*����
�
�s�8B�A&D�Dc��t|�tur3|j|jj	|j
�yt
d|����)zfUnregister an event handler.

        @param id: the L{EventID} of the handler to unregister.
        z$EventID instance expected, received N)�typerrr�removerr�r�ids  r�cancel_callz%EventHandlingReactorMixin.cancel_callusD��
��8�w��� � ����0�7�7����A��B�2�&�I�J�Jr
)r)	rr	r
rrr,r9r?�
__classcell__�r s@rrr!s����"�)�*/�bKr
rc��eZdZd�Zy)�	ReactorIDc��||_yr)�_timeout)r�timeouts  rrzReactorID.__init__�s	����
r
N)rr	r
rrr
rrCrC�s�� r
rCc�j��eZdZdZ�fd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Z�xZS)�EventHandlingReactoraWrap and add functionalities to the Twisted reactor.

    This is essentially a facade around the twisted.internet.reactor and
    will delegate to it for mostly everything except event handling features
    which are implemented using EventHandlingReactorMixin.
    c���ddlm}ddlm}||_||_|j
�|j|_t�|�%�y)Nr)�reactor)�LoopingCall)
�twisted.internetrJ�twisted.internet.taskrK�_LoopingCall�_reactor�_cleanup�callFromThreadrr)rrJrKr s   �rrzEventHandlingReactor.__init__�s:���,�5�'�����
��
�
��%�4�4���
���r
c�*�tj�S)z5Get current time.

        @see L{time.time}
        )�time�rs rrSzEventHandlingReactor.time�s��
�y�y�{�r
c�:�|jj|i|��S)z�Call a function later.

        Simply call C{callLater(*args, **kwargs)} and return its result.

        @see: L{twisted.internet.interfaces.IReactorTime.callLater}.

        )rO�	callLater)rr6r7s   r�
call_laterzEventHandlingReactor.call_later�s ��'�t�}�}�&�&��7��7�7r
c�X�|j|g|��i|��}|j|d��|S)z�Call a function repeatedly.

        Create a new L{twisted.internet.task.LoopingCall} object and
        start it.

        @return: the created C{LoopingCall} object.
        F)�now)rN�start)r�seconds�fr6r7�lcs      r�
call_everyzEventHandlingReactor.call_every�s5���T�
�
�q�
2�4�
2�6�
2��
����e��$��	r
c���t|t�rtj||�St||j�r|j�S|j
�r|j�yy)aCancel a scheduled function or event handler.

        @param id: The function call or handler to remove. It can be an
            L{EventID}, a L{LoopingCall} or a C{IDelayedCall}, as returned
            by L{call_on}, L{call_every} and L{call_later} respectively.
        N)�
isinstancerrr?rNr4�active�cancelr=s  rr?z EventHandlingReactor.cancel_call�sT���b�'�"�,�8�8��r�B�B��b�$�+�+�,��7�7�9��
�9�9�;��I�I�K�r
c�:�|jj|�y)zASchedule a function to be called when the reactor starts running.N)rO�callWhenRunning)rr\s  r�call_when_runningz&EventHandlingReactor.call_when_running�s���
�
�%�%�a�(r
c�D�|jj|g|��i|��y)a1Cause a function to be executed by the reactor thread.

        @param f: The callable object to execute.
        @param args: The arguments to call it with.
        @param kwargs: The keyword arguments to call it with.

        @see: L{twisted.internet.interfaces.IReactorThreads.callFromThread}
        N)rOrQ)rr\r6r7s    r�call_in_mainz!EventHandlingReactor.call_in_main�s"��	%��
�
�$�$�Q�8��8��8r
c�~����fd�}�fd�}t|g|��i|��}|j|�|j|�y)a
        Execute a callable object in a new separate thread.

        @param callback: A function to call in case C{f} was successful, it
            will be passed the return value of C{f}.
        @param errback: A function to call in case C{f} raised an exception,
            it will be pass a C{(type, value, traceback)} tuple giving
            information about the raised exception (see L{sys.exc_info}).

        @note: Both C{callback} and C{errback} will be executed in the
            the parent thread.
        c����r�|�Syrr)�result�callbacks �r�
on_successz7EventHandlingReactor.call_in_thread.<locals>.on_success�s������'�'�r
c���|j|j|jf}�r�|�ytj|d|��y)Nr#)�exc_info)r;�value�tbr.�error)�failurern�errbacks  �r�
on_failurez7EventHandlingReactor.call_in_thread.<locals>.on_failure�s8������g�m�m�W�Z�Z�@�H����"��
�
�h�q�k�H�=r
N)r�addCallback�
addErrback)	rrkrsr\r6r7rlrt�deferreds	 ``      r�call_in_threadz#EventHandlingReactor.call_in_thread�s?���	(�	>�!��4�T�4�V�4�����Z�(����J�'r
c�>�|jj||d��S)z!Start listening on a Unix socket.T)�wantPID)rO�
listenUNIX�r�socket�factorys   r�listen_unixz EventHandlingReactor.listen_unix�s���}�}�'�'����'�F�Fr
c�:�|jj||�S)zConnect to a Unix socket.)rO�connectUNIXr|s   r�connect_unixz!EventHandlingReactor.connect_unix�s���}�}�(�(���9�9r
c�|�|jd�|jj�|jd�y)z2Start the reactor, a C{"run"} event will be fired.�runr4N)r9rOr�rTs rr�zEventHandlingReactor.run�s,��	
�	�	�%���
�
�����	�	�&�r
c�X�|jj�|j�y)z2Stop the reactor, a C{"stop"} event will be fired.N)rOr4rPrTs rr4zEventHandlingReactor.stop�s���
�
�����
�
�r
c��|jj�D]#}|j�s�|j��%yr)rO�getDelayedCallsrarb)r�calls  rrPzEventHandlingReactor._cleanups2���M�M�1�1�3�	�D��{�{�}����
�	r
)rr	r
rrrSrWr^r?rergrxrr�r�r4rPr@rAs@rrHrH�sJ������8�
��)�	9�(�:G�:���
r
rH)rr.rS�twisted.internet.threadsr�landscape.lib.formatrr5rrrrrCrHrr
r�<module>r�sd�����2�.�H�	�H�8�I�8�
�
�\K�\K�~ � �
B�4�Br

Zerion Mini Shell 1.0