%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/words/xish/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/words/xish/__pycache__/utility.cpython-312.pyc

�

Ϫ�f?4��p�dZddlmZddlmZGd�d�ZGd�d�ZGd�d	�ZGd
�d�Zy)
z+
Event Dispatching and Callback utilities.
�)�log)�xpathc��eZdZdZd�Zd�Zy)�_MethodWrapperz3
    Internal class for tracking method calls.
    c�.�||_||_||_y�N)�method�args�kwargs)�selfr	r
rs    �</usr/lib/python3/dist-packages/twisted/words/xish/utility.py�__init__z_MethodWrapper.__init__s�������	����c��|j|z}|jj�}|j|�|j|i|��yr)r
r�copy�updater	)rr
r�nargs�nkwargss     r
�__call__z_MethodWrapper.__call__sA���	�	�D� ���+�+�"�"�$�����v������U�&�g�&rN)�__name__�
__module__�__qualname__�__doc__rr�rr
rrs����
'rrc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�CallbackLista�
    Container for callbacks.

    Event queries are linked to lists of callables. When a matching event
    occurs, these callables are called in sequence. One-time callbacks
    are removed from the list after the first time the event was triggered.

    Arguments to callbacks are split spread across two sets. The first set,
    callback specific, is passed to C{addCallback} and is used for all
    subsequent event triggers.  The second set is passed to C{callback} and is
    event specific. Positional arguments in the second set come after the
    positional arguments of the first set. Keyword arguments in the second set
    override those in the first set.

    @ivar callbacks: The registered callbacks as mapping from the callable to a
                     tuple of a wrapper for that callable that keeps the
                     callback specific arguments and a boolean that signifies
                     if it is to be called only once.
    @type callbacks: C{dict}
    c��i|_yr��	callbacks�rs r
rzCallbackList.__init__6s	����rc�^�||jvrt|g|��i|��|f|j|<yy)a�
        Add callback.

        The arguments passed are used as callback specific arguments.

        @param onetime: If C{True}, this callback is called at most once.
        @type onetime: C{bool}
        @param method: The callback callable to be added.
        @param args: Positional arguments to the callable.
        @type args: C{list}
        @param kwargs: Keyword arguments to the callable.
        @type kwargs: C{dict}
        N)rr)r�onetimer	r
rs     r
�addCallbackzCallbackList.addCallback9s7������'�&4�V�&M�d�&M�f�&M�w�%W�D�N�N�6�"�(rc�<�||jvr|j|=yy)zV
        Remove callback.

        @param method: The callable to be removed.
        Nr)rr	s  r
�removeCallbackzCallbackList.removeCallbackKs!���T�^�^�#����v�&�$rc���t|jj��D]!\}\}}	||i|��|s�|j|=�#y#t$rt	j
�Y�2wxYw)aD
        Call all registered callbacks.

        The passed arguments are event specific and augment and override
        the callback specific arguments as described above.

        @note: Exceptions raised by callbacks are trapped and logged. They will
               not propagate up to make sure other callbacks will still be
               called, and the event dispatching always succeeds.

        @param args: Positional arguments to the callable.
        @type args: C{list}
        @param kwargs: Keyword arguments to the callable.
        @type kwargs: C{dict}
        N)�listr�items�
BaseExceptionr�err)rr
r�key�
methodwrapperr"s      r
�callbackzCallbackList.callbackUsl��".2�$�.�.�2F�2F�2H�-I�	(�)�C�)�-��
��t�.�v�.���N�N�3�'�	(��!�
����	�
�s�A	�	A)�(A)c�2�t|j�dk(S)z[
        Return if list of registered callbacks is empty.

        @rtype: C{bool}
        r)�lenrr s r
�isEmptyzCallbackList.isEmptyos���4�>�>�"�a�'�'rN)	rrrrrr#r%r-r0rrr
rr s!���*�X�$'�(�4(rrc�B�eZdZdZd
d�Zd�Zdd�Zdd�Zd�Zd�Z	dd	�Z
y)
�EventDispatcherav
    Event dispatching service.

    The C{EventDispatcher} allows observers to be registered for certain events
    that are dispatched. There are two types of events: XPath events and Named
    events.

    Every dispatch is triggered by calling L{dispatch} with a data object and,
    for named events, the name of the event.

    When an XPath type event is dispatched, the associated object is assumed to
    be an L{Element<twisted.words.xish.domish.Element>} instance, which is
    matched against all registered XPath queries. For every match, the
    respective observer will be called with the data object.

    A named event will simply call each registered observer for that particular
    event name, with the data object. Unlike XPath type events, the data object
    is not restricted to L{Element<twisted.words.xish.domish.Element>}, but can
    be anything.

    When registering observers, the event that is to be observed is specified
    using an L{xpath.XPathQuery} instance or a string. In the latter case, the
    string can also contain the string representation of an XPath expression.
    To distinguish these from named events, each named event should start with
    a special prefix that is stored in C{self.prefix}. It defaults to
    C{//event/}.

    Observers registered using L{addObserver} are persistent: after the
    observer has been triggered by a dispatch, it remains registered for a
    possible next dispatch. If instead L{addOnetimeObserver} was used to
    observe an event, the observer is removed from the list of observers after
    the first observed event.

    Observers can also be prioritized, by providing an optional C{priority}
    parameter to the L{addObserver} and L{addOnetimeObserver} methods. Higher
    priority observers are then called before lower priority observers.

    Finally, observers can be unregistered by using L{removeObserver}.
    c�J�||_i|_i|_d|_g|_y)Nr)�prefix�_eventObservers�_xpathObservers�_dispatchDepth�_updateQueue)r�eventprefixs  r
rzEventDispatcher.__init__�s)��!���!���!��������rc�
�t|tj�r|j}||fS|j|dt|j�k(r|j}||fStj|�}|j}||fSr)�
isinstancer�
XPathQueryr6r4r/r5�internQuery)r�event�	observerss   r
�_getEventAndObserversz%EventDispatcher._getEventAndObservers�s����e�U�-�-�.��,�,�I��i����{�{�e�$6�c�$�+�+�&6�7�7� �0�0�	��i����)�)�%�0�� �0�0�	��i��rc�6�|jd|||g|��i|��y)z�
        Register a one-time observer for an event.

        Like L{addObserver}, but is only triggered at most once. See there
        for a description of the parameters.
        TN��_addObserver�rr>�
observerfn�priorityr
rs      r
�addOnetimeObserverz"EventDispatcher.addOnetimeObserver�s$��	����$��z�8�M�d�M�f�Mrc�6�|jd|||g|��i|��y)a�
        Register an observer for an event.

        Each observer will be registered with a certain priority. Higher
        priority observers get called before lower priority observers.

        @param event: Name or XPath query for the event to be monitored.
        @type event: C{str} or L{xpath.XPathQuery}.
        @param observerfn: Function to be called when the specified event
                           has been triggered. This callable takes
                           one parameter: the data object that triggered
                           the event. When specified, the C{*args} and
                           C{**kwargs} parameters to addObserver are being used
                           as additional parameters to the registered observer
                           callable.
        @param priority: (Optional) priority of this observer in relation to
                         other observer that match the same event. Defaults to
                         C{0}.
        @type priority: C{int}
        FNrBrDs      r
�addObserverzEventDispatcher.addObserver�s$��*	����%��
�H�N�t�N�v�Nrc	�>���������jdkDr%�jj�������fd��y�j��\�}�|vrt	�}�|i|�<n!|�}	�|	vrt	�}||��<n|	�}|j
��g���i���y)Nrc�6���j����g���i���SrrB)r
r>rrEr"rFrs�������r
�<lambda>z.EventDispatcher._addObserver.<locals>.<lambda>�s.���)��)�)��U�J���;?��CI��r)r7r8�appendr@rr#)
rr"r>rErFr
rr?�cbl�priorityObserverss
```````   r
rCzEventDispatcher._addObserver�s��������"����$�$���
�

��5�5�e�<���y��9�$��.�C�#(�#�,�I�h�� )�(� 3���-�-�"�n��-0�	�(�#�E�*�'��.��������=�d�=�f�=rc������jdkDr!�jj���fd��y�j��\�}g}|j	�D]X\}}|j	�D]@\}}�|k(s�|j��|j
�s�.|j||f��B�Z|D]\}}|||=�
y)a_
        Remove callable as observer for an event.

        The observer callable is removed for all priority levels for the
        specified event.

        @param event: Event for which the observer callable was registered.
        @type event: C{str} or L{xpath.XPathQuery}
        @param observerfn: Observer callable to be unregistered.
        rc�(���j���Sr)�removeObserver)r>rErs���r
rLz0EventDispatcher.removeObserver.<locals>.<lambda>s���T�-@�-@��
�-S�rN)r7r8rMr@r(r%r0)	rr>rEr?�
emptyListsrFrO�query�callbacklists	```      r
rRzEventDispatcher.removeObserver�s��������"����$�$�%S�T���5�5�e�<���y��
�+4�?�?�+<�	=�'�H�'�'8�'>�'>�'@�
=�#��|��E�>� �/�/�
�;�#�+�+�-�"�)�)�8�U�*;�<�	
=�	=� *�	+�O�H�e��(�#�E�*�	+rNc�d��d}|xjdz
c_�dk7r|j}�fd�}n|j}d�}t|j	��}|j�|j
�g}|D]^}||j�D]F\}	}
||	|�s�|
j|�d}|
j�s�4|j||	f��H�`|D]\}}	|||	=�
|xjdzc_|jdk(r|jD]	}|��g|_|S)a�
        Dispatch an event.

        When C{event} is L{None}, an XPath type event is triggered, and
        C{obj} is assumed to be an instance of
        L{Element<twisted.words.xish.domish.Element>}. Otherwise, C{event}
        holds the name of the named event being triggered. In the latter case,
        C{obj} can be anything.

        @param obj: The object to be dispatched.
        @param event: Optional event name.
        @type event: C{str}
        F�Nc���|�k(Srr)rT�objr>s  �r
rLz*EventDispatcher.dispatch.<locals>.<lambda>(s���u��~�rc�$�|j|�Sr)�matches)rTrYs  r
rLz*EventDispatcher.dispatch.<locals>.<lambda>,s��u�}�}�S�'9�rTr)r7r5r6r'�keys�sort�reverser(r-r0rMr8)rrYr>�foundTargetr?�match�
prioritiesrSrFrTrU�fs  `         r
�dispatchzEventDispatcher.dispatchsJ��������q� ���D�=��,�,�I�5�E��,�,�I�9�E��)�.�.�*�+�
����������
�"�	=�H�'0��':�'@�'@�'B�
=�#��|����$� �)�)�#�.�"&�K�#�+�+�-�"�)�)�8�U�*;�<�
=�	=� *�	+�O�H�e��(�#�E�*�	+�	
���q� ��
���!�#��&�&�
����
� "�D���r)z//event/)rr)rrrrrr@rGrIrCrRrcrrr
r2r2ys-��&�P�
 �N�O�.>�4+�>7rr2c��eZdZdZd�Zy)�XmlPipeaw
    XML stream pipe.

    Connects two objects that communicate stanzas through an XML stream like
    interface. Each of the ends of the pipe (sink and source) can be used to
    send XML stanzas to the other side, or add observers to process XML stanzas
    that were sent from the other side.

    XML pipes are usually used in place of regular XML streams that are
    transported over TCP. This is the reason for the use of the names source
    and sink for both ends of the pipe. The source side corresponds with the
    entity that initiated the TCP connection, whereas the sink corresponds with
    the entity that accepts that connection. In this object, though, the source
    and sink are treated equally.

    Unlike Jabber
    L{XmlStream<twisted.words.protocols.jabber.xmlstream.XmlStream>}s, the sink
    and source objects are assumed to represent an eternal connected and
    initialized XML stream. As such, events corresponding to connection,
    disconnection, initialization and stream errors are not dispatched or
    processed.

    @since: 8.2
    @ivar source: Source XML stream.
    @ivar sink: Sink XML stream.
    c���t��_t��_�fd��j_�fd��j_y)Nc�:���jj|�Sr)�sinkrc�rYrs �r
rLz"XmlPipe.__init__.<locals>.<lambda>ks���t�y�y�'9�'9�#�'>�rc�:���jj|�Sr)�sourcercris �r
rLz"XmlPipe.__init__.<locals>.<lambda>ls���T�[�[�%9�%9�#�%>�r)r2rkrh�sendr s`r
rzXmlPipe.__init__hs.���%�'���#�%��	�>�����>��	�	�rN)rrrrrrrr
rereLs���6?rreN)	r�twisted.pythonr�twisted.words.xishrrrr2rerrr
�<module>ros@���
�$�'�'�"V(�V(�rP�P�f ?� ?r

Zerion Mini Shell 1.0