ó
    ×›‘h?4  ã                   óp   • S r SSKJr  SSKJr   " S S5      r " S S5      r " S S	5      r " S
 S5      rg)z+
Event Dispatching and Callback utilities.
é    )Úlog)Úxpathc                   ó$   • \ rS rSrSrS rS rSrg)Ú_MethodWrapperé   z+
Internal class for tracking method calls.
c                 ó(   • Xl         X l        X0l        g ©N)ÚmethodÚargsÚkwargs)Úselfr
   r   r   s       Ú^C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/words/xish/utility.pyÚ__init__Ú_MethodWrapper.__init__   s   € ØŒØŒ	Ø�ó    c                 óœ   • U R                   U-   nU R                  R                  5       nUR                  U5        U R                  " U0 UD6  g r	   )r   r   ÚcopyÚupdater
   )r   r   r   ÚnargsÚnkwargss        r   Ú__call__Ú_MethodWrapper.__call__   s?   € Ø—	‘	˜DÑ ˆØ—+‘+×"Ñ"Ó$ˆØ�‰�vÔØ�Š�UÐ&˜gÓ&r   )r   r   r
   N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   Ú__static_attributes__© r   r   r   r      s   † ñòõ
'r   r   c                   ó6   • \ rS rSrSrS rS rS rS rS r	Sr
g	)
ÚCallbackListé    aœ  
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                 ó   • 0 U l         g r	   ©Ú	callbacks©r   s    r   r   ÚCallbackList.__init__6   s	   € Øˆ�r   c                 ó`   • X R                   ;  a  [        U/UQ70 UD6U4U R                   U'   gg)ai  
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)r%   r   )r   Úonetimer
   r   r   s        r   ÚaddCallbackÚCallbackList.addCallback9   s5   € ð Ÿ™Ó'Ü&4°VÐ&M¸dÒ&MÀfÑ&MÈwÐ%WˆD�N‰N˜6Ò"ð (r   c                 ó>   • XR                   ;   a  U R                   U	 gg)z>
Remove callback.

@param method: The callable to be removed.
Nr$   )r   r
   s     r   ÚremoveCallbackÚCallbackList.removeCallbackK   s   € ð —^‘^Ó#Ø—‘˜vÑ&ð $r   c                 óê   • [        U R                  R                  5       5       H'  u  nu  pE U" U0 UD6  U(       d  M  U R                  U	 M)     g! [         a    [        R
                  " 5          N<f = f)aì  
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   ÚcallbackÚCallbackList.callbackU   sh   € ô" .2°$·.±.×2FÑ2FÓ2HÖ-IÑ)ˆCÑ)�-ðÙ˜tÐ. vÒ.÷ ˆwØ—N‘N 3Ò'ò .Jøô !ó Ü—’–	ðús   ­AÁA2Á1A2c                 ó2   • [        U R                  5      S:H  $ )zC
Return if list of registered callbacks is empty.

@rtype: C{bool}
r   )Úlenr%   r&   s    r   ÚisEmptyÚCallbackList.isEmptyo   s   € ô �4—>‘>Ó" aÑ'Ð'r   r$   N)r   r   r   r   r   r   r*   r-   r6   r:   r   r   r   r   r!   r!       s!   † ñò*òXò$'ò(õ4(r   r!   c                   óR   • \ rS rSrSrSS jrS rSS jrSS jrS r	S r
SS
 jrSrg	)ÚEventDispatcheréy   aþ  
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                 óH   • Xl         0 U l        0 U l        SU l        / U l        g )Nr   )ÚprefixÚ_eventObserversÚ_xpathObserversÚ_dispatchDepthÚ_updateQueue)r   Úeventprefixs     r   r   ÚEventDispatcher.__init__¢   s'   € Ø!ŒØ!ˆÔØ!ˆÔØˆÔàˆÕr   c                 ó  • [        U[        R                  5      (       a  U R                  nX4$ U R                  US [        U R                  5       :X  a  U R                  nX4$ [        R                  " U5      nU R                  nX4$ r	   )Ú
isinstancer   Ú
XPathQueryrB   r@   r9   rA   ÚinternQuery)r   ÚeventÚ	observerss      r   Ú_getEventAndObserversÚ%EventDispatcher._getEventAndObserversª   s†   € Ü�eœU×-Ñ-×.Ñ.à×,Ñ,ˆIð ÐÐð �{‰{˜eÐ$6¤c¨$¯+©+Ó&6Ð7Ó7à ×0Ñ0�	ð ÐÐô ×)Ò)¨%Ó0�Ø ×0Ñ0�	àÐÐr   c                 ó4   • U R                   " SXU/UQ70 UD6  g)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   rK   Ú
observerfnÚpriorityr   r   s         r   ÚaddOnetimeObserverÚ"EventDispatcher.addOnetimeObserver¹   s    € ð 	×Ò˜$ °8ÐM¸dÒMÀfÓMr   c                 ó4   • U R                   " SXU/UQ70 UD6  g)av  
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}
FNrP   rR   s         r   ÚaddObserverÚEventDispatcher.addObserverÂ   s    € ð* 	×Ò˜% °HÐN¸tÒNÀvÓNr   c           	      óH  ^ ^^^^^^• T R                   S:”  a&  T R                  R                  UUUUUUU 4S j5        g T R                  T5      u  mnTU;  a  [	        5       nTU0UT'   O"UT   n	TU	;  a  [	        5       nX‡T   T'   OU	T   nUR
                  " TT/TQ70 TD6  g )Nr   c                  ó6   >• TR                   " TTTT/T Q70 TD6$ r	   rP   )r   rK   r   rS   r)   rT   r   s   €€€€€€€r   Ú<lambda>Ú.EventDispatcher._addObserver.<locals>.<lambda>Þ   s)   ø€ ˜×)Ò)Ø˜U J°ðØ;?òØCIòr   )rC   rD   ÚappendrM   r!   r*   )
r   r)   rK   rS   rT   r   r   rL   ÚcblÚpriorityObserverss
   ```````   r   rQ   ÚEventDispatcher._addObserverÙ   s²   þ€ ð ×Ñ Ó"Ø×Ñ×$Ñ$÷ò ôð
 à×5Ñ5°eÓ<Ñˆˆyà˜9Ó$Ü“.ˆCØ#(¨# ,ˆI�hÒà )¨(Ñ 3ÐØÐ-Ó-Ü"“n�Ø-0˜(Ñ# EÒ*à'¨Ñ.�à�Š˜ Ð=¨dÒ=°fÓ=r   c                 ó¢  ^ ^^• T R                   S:”  a"  T R                  R                  UUU 4S j5        gT R                  T5      u  mn/ nUR	                  5        H`  u  pVUR	                  5        HG  u  pxTU:X  d  M  UR                  T5        UR                  5       (       d  M5  UR                  XW45        MI     Mb     U H
  u  pWX5   U	 M     g)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.
r   c                  ó(   >• TR                  T T5      $ r	   )ÚremoveObserver)rK   rS   r   s   €€€r   r\   Ú0EventDispatcher.removeObserver.<locals>.<lambda>  s   ø€ ¨T×-@Ñ-@ÀÈ
Ô-Sr   N)rC   rD   r^   rM   r1   r-   r:   )	r   rK   rS   rL   Ú
emptyListsrT   r`   ÚqueryÚcallbacklists	   ```      r   rd   ÚEventDispatcher.removeObserveró   s¾   ú€ ð ×Ñ Ó"Ø×Ñ×$Ñ$Ö%SÔTØà×5Ñ5°eÓ<Ñˆˆyàˆ
Ø+4¯?©?Ö+<Ñ'ˆHØ'8×'>Ñ'>Ö'@Ñ#�Ø˜E•>Ø ×/Ñ/°
Ô;Ø#×+Ñ+×-Ó-Ø"×)Ñ)¨8Ð*;Ö<ó	 (Añ ,=ó  *‰OˆHØÑ# EÒ*ò  *r   Nc                 ó†  ^• SnU =R                   S-  sl         TS:w  a  U R                  nU4S jnOU R                  nS n[        UR	                  5       5      nUR                  5         UR                  5         / nU Hi  nXH   R                  5        HP  u  pšU" X‘5      (       d  M  U
R                  U5        SnU
R                  5       (       d  M>  UR                  X‰45        MR     Mk     U H
  u  p‰XH   U		 M     U =R                   S-  sl         U R                   S:X  a!  U R                   H
  nU" 5         M     / U l        U$ )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                 ó   >• U T:H  $ r	   r   )rg   ÚobjrK   s     €r   r\   Ú*EventDispatcher.dispatch.<locals>.<lambda>(  s	   ø€  u°¢~r   c                 ó$   • U R                  U5      $ r	   )Úmatches)rg   rm   s     r   r\   rn   ,  s   €  u§}¡}°SÔ'9r   Tr   )rC   rA   rB   r0   ÚkeysÚsortÚreverser1   r6   r:   r^   rD   )r   rm   rK   ÚfoundTargetrL   ÚmatchÚ
prioritiesrf   rT   rg   rh   Úfs     `         r   ÚdispatchÚEventDispatcher.dispatch  s1  ø€ ð ˆà×Ò˜qÑ Õà�D‹=à×,Ñ,ˆIÜ5‰Eð ×,Ñ,ˆIÙ9ˆEä˜)Ÿ.™.Ó*Ó+ˆ
Ø�‰ÔØ×ÑÔàˆ
Û"ˆHØ'0Ñ':×'@Ñ'@Ö'BÑ#�Ù˜×$Ó$Ø ×)Ñ)¨#Ô.Ø"&�KØ#×+Ñ+×-Ó-Ø"×)Ñ)¨8Ð*;Ö<ó (Cñ #ó  *‰OˆHØÑ# EÒ*ñ  *ð 	×Ò˜qÑ Õð
 ×Ñ !Ó#à×&Ô&�Ù–ñ 'à "ˆDÔàÐr   )rC   rA   rD   rB   r@   )z//event/)r   r	   )r   r   r   r   r   r   rM   rU   rX   rQ   rd   rx   r   r   r   r   r=   r=   y   s-   † ñ&ôPò ôNôOò.>ò4+÷>7r   r=   c                   ó   • \ rS rSrSrS rSrg)ÚXmlPipeiL  a#  
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                 ó–   ^ • [        5       T l        [        5       T l        U 4S jT R                  l        U 4S jT R                  l        g )Nc                 ó:   >• TR                   R                  U 5      $ r	   )Úsinkrx   ©rm   r   s    €r   r\   Ú"XmlPipe.__init__.<locals>.<lambda>k  s   ø€  t§y¡y×'9Ñ'9¸#Ô'>r   c                 ó:   >• TR                   R                  U 5      $ r	   )Úsourcerx   r   s    €r   r\   r€   l  s   ø€  T§[¡[×%9Ñ%9¸#Ô%>r   )r=   r‚   r~   Úsendr&   s   `r   r   ÚXmlPipe.__init__h  s.   ø€ Ü%Ó'ˆŒÜ#Ó%ˆŒ	Ü>ˆ�‰ÔÜ>ˆ�	‰	�r   )r~   r‚   N)r   r   r   r   r   r   r   r   r   r   r{   r{   L  s   † ñõ6?r   r{   N)	r   Útwisted.pythonr   Útwisted.words.xishr   r   r!   r=   r{   r   r   r   Ú<module>r‡      s@   ðñõ
 Ý $÷'ñ '÷"V(ñ V(÷rPñ P÷f ?ò  ?r   