
    5j                          S SK Jr  S SKJr  S SKJrJrJrJrJ	r	J
r
JrJrJrJr   " S S\5      r " S S\5      r\" S\S	9r " S
 S5      rg)    )OrderedDict)Lock)
AnyCallableDictListMappingOptionalSetTupleTypeVarUnionc                       \ rS rSrSrSrg)PyeeException   z@An exception internal to pyee. Deprecated in favor of PyeeError. N__name__
__module____qualname____firstlineno____doc____static_attributes__r       H/root/lseg-credit/backend/venv/lib/python3.13/site-packages/pyee/base.pyr   r      s    Jr   r   c                       \ rS rSrSrSrg)	PyeeError   zAn error internal to pyee.r   Nr   r   r   r   r   r      s    $r   r   Handler)boundc                      \ rS rSrSrS S jrS\\\4   4S jr	S\\\4   SS4S jr
 S!S	\S
\\   S\\\\/\4   4   4S jjrS	\S\\/\4   4S jrS	\S
\S\4S jrS	\S\S\4S jrS
\S\\S4   S\\\4   SS4S jrS\\   4S jrS	\S\SS4S jrS	\S\\S4   S\\\4   S\4S jrS	\S\S\S\4S jr S!S	\S
\\   S\4S jjrS	\S
\SS4S jrS	\S
\SS4S jrS!S	\\   SS4S jjrS	\S\ \   4S jr!Sr"g)"EventEmitter   aB  The base event emitter class. All other event emitters inherit from
this class.

Most events are registered with an emitter via the `on` and `once`
methods, and fired with the `emit` method. However, pyee event emitters
have two *special* events:

- `new_listener`: Fires whenever a new listener is created. Listeners for
  this event do not fire upon their own creation.

- `error`: When emitted raises an Exception by default, behavior can be
  overridden by attaching callback to the event.

  For example:

```py
@ee.on('error')
def on_error(message):
    logging.err(message)

ee.emit('error', Exception('something blew up'))
```

All callbacks are handled in a synchronous, blocking manner. As in node.js,
raised exceptions are not automatically handled for you---you must catch
your own exceptions, and treat them accordingly.
returnNc                 @    [        5       U l        [        5       U l        g N)dict_eventsr   _lockselfs    r   __init__EventEmitter.__init__;   s     F 	  6
r   c                 @    U R                   R                  5       nUS	 U$ )Nr)   )__dict__copyr+   states     r   __getstate__EventEmitter.__getstate__B   s     ""$'Nr   r2   c                 X    U R                   R                  U5        [        5       U l        g r&   )r/   updater   r)   r1   s     r   __setstate__EventEmitter.__setstate__G   s    U#V
r   eventfc                 L    Uc  U R                  U5      $ U R                  X5      $ )a  Registers the function `f` to the event name `event`, if provided.

If `f` isn't provided, this method calls `EventEmitter#listens_to`, and
otherwise calls `EventEmitter#add_listener`. In other words, you may either
use it as a decorator:

```py
@ee.on('data')
def data_handler(data):
    print(data)
```

Or directly:

```py
ee.on('data', data_handler)
```

In both the decorated and undecorated forms, the event handler is
returned. The upshot of this is that you can call decorated handlers
directly, as well as use them in remove_listener calls.

Note that this method's return type is a union type. If you are using
mypy or pyright, you will probably want to use either
`EventEmitter#listens_to` or `EventEmitter#add_listener`.
)
listens_toadd_listenerr+   r9   r:   s      r   onEventEmitter.onK   s)    : 9??5))$$U..r   c                 4   ^ ^ S[         S[         4UU 4S jjnU$ )a  Returns a decorator which will register the decorated function to
the event name `event`:

```py
@ee.listens_to("event")
def data_handler(data):
    print(data)
```

By only supporting the decorator use case, this method has improved
type safety over `EventEmitter#on`.
r:   r$   c                 ,   > TR                  TX 5        U $ r&   _add_event_handler)r:   r9   r+   s    r   r?   #EventEmitter.listens_to.<locals>.on{   s    ##E10Hr   )r   )r+   r9   r?   s   `` r   r<   EventEmitter.listens_tom   s"    	' 	g 	 	 	r   c                 *    U R                  XU5        U$ )zRegister the function `f` to the event name `event`:

```
def data_handler(data):
    print(data)

h = ee.add_listener("event", data_handler)
```

By not supporting the decorator use case, this method has improved
type safety over `EventEmitter#on`.
rC   r>   s      r   r=   EventEmitter.add_listener   s     	!,r   kvc                     U R                  SX5        U R                     XR                  ;  a  [        5       U R                  U'   X0R                  U   U'   S S S 5        g ! , (       d  f       g = f)Nnew_listener)emitr)   r(   r   )r+   r9   rI   rJ   s       r   rD   EventEmitter._add_event_handler   sN    		.%+ ZZLL(&1mU#%&LL" ZZs   8A  
A.args.kwargsc                     U" U0 UD6  g r&   r   )r+   r:   rO   rP   s       r   	_emit_runEventEmitter._emit_run   s     	
46r   c                 H    [        U R                  R                  5       5      $ )z6Get a set of events that this emitter is listening to.)setr(   keysr*   s    r   event_namesEventEmitter.event_names   s    4<<$$&''r   errorc                 Z    US:X  a%  [        U[        5      (       a  Ue[        SU 35      eg )NrY   z%Uncaught, unspecified 'error' event: )
isinstance	Exceptionr   )r+   r9   rY   s      r   _emit_handle_potential_error)EventEmitter._emit_handle_potential_error   s4    G%++"Gw OPP	 r   c                    SnU R                      [        U R                  R                  U[	        5       5      R                  5       5      nS S S 5        W H  nU R                  XbU5        SnM     U$ ! , (       d  f       N-= f)NFT)r)   listr(   getr   valuesrR   )r+   r9   rO   rP   handledfuncsr:   s          r   _call_handlersEventEmitter._call_handlers   sg     ZZ))%?FFHIE ANN1F+G   Zs   <A22
B c                 r    U R                  XU5      nU(       d  U R                  X(       a  US   OS5        U$ )a  Emit `event`, passing `*args` and `**kwargs` to each attached
function. Returns `True` if any functions are attached to `event`;
otherwise returns `False`.

Example:

```py
ee.emit('data', '00101001')
```

Assuming `data` is an attached function, this will call
`data('00101001')'`.
r   N)re   r]   )r+   r9   rO   rP   rc   s        r   rM   EventEmitter.emit   s6    & %%e6:--eT!W$Or   c                 J   ^ ^ S[         S[         4UU 4S jjnUc  U$ U" U5      $ )z[The same as `ee.on`, except that the listener is automatically
removed after being called.
r:   r$   c                 h   >^  S[         S[         S[         4UU U4S jjnTR                  TT U5        T $ )NrO   rP   r$   c                     > TR                      TTR                  ;   a&  TTR                  T   ;   a  TR                  TT5        O
 S S S 5        g  S S S 5        T" U 0 UD6$ ! , (       d  f       N= fr&   )r)   r(   _remove_listener)rO   rP   r9   r:   r+   s     r   g.EventEmitter.once.<locals>._wrapper.<locals>.g   sh     ZZ ,dll56I1I--eQ7#  Z 8	   $)&))  Zs   8A  
A.)r   rD   )r:   rm   r9   r+   s   ` r   _wrapper#EventEmitter.once.<locals>._wrapper   s@    *** * * ##E1a0Hr   )r   )r+   r9   r:   ro   s   ``  r   onceEventEmitter.once   s1    	 	X 	 	& 9OA;r   c                     U R                   U   R                  U5        [        U R                   U   5      (       d  U R                   U	 gg)zNaked unprotected removal.N)r(   poplenr>   s      r   rl   EventEmitter._remove_listener   s>    U"4<<&''U# (r   c                 r    U R                      U R                  X5        SSS5        g! , (       d  f       g= f)z&Removes the function `f` from `event`.N)r)   rl   r>   s      r   remove_listenerEventEmitter.remove_listener  s!    ZZ!!%+ ZZs   (
6c                     U R                      Ub  [        5       U R                  U'   O[        5       U l        SSS5        g! , (       d  f       g= f)zdRemove all listeners attached to `event`.
If `event` is `None`, remove all listeners on all events.
N)r)   r   r(   r'   r+   r9   s     r   remove_all_listeners!EventEmitter.remove_all_listeners  s4     ZZ &1mU##v	 ZZs   +A
Ac                 x    [        U R                  R                  U[        5       5      R	                  5       5      $ )z:Returns a list of all listeners registered to the `event`.)r`   r(   ra   r   rV   r{   s     r   	listenersEventEmitter.listeners  s)    DLL$$UKM:??ABBr   )r(   r)   )r$   Nr&   )#r   r   r   r   r   r,   r	   strr   r3   r7   r
   r   r   r   r?   r<   r=   rD   r   r   rR   r   rW   r]   boolre   rM   rq   rl   rx   r|   r   r   r   r   r   r   r"   r"      s.   8"gc3h/ 
'#s("3  
 26 / /%g. /	w'G!344	5 /D 'G1C(D (# ' g  ' ' 'X ' CHo S#X	
 
(SX (Q# Qc Qd Q CHo S#X	
 
   	
 
: !% H 
	B$c $h $4 $,S ,X ,$ ,
&(3- &4 &Cs CtH~ Cr   r"   N)collectionsr   	threadingr   typingr   r   r   r   r	   r
   r   r   r   r   r\   r   r   r   r"   r   r   r   <module>r      sR    $   KI K% % )8
,uC uCr   