
    Yh:!                         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Jr  \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overload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       ;/var/www/html/env/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S4S jrS\S\\\	4   4S jr
S\S\\\	4   SS4S	 jr\S\S
\S\\/\4   4S j5       r\S\S
\S\S\4S j5       r S#S\S
\S\\   S\\\\/\4   4   4S jjrS\S
\S\\/\4   4S jrS\S
\S\S\4S jrS\S
\S\S\4S jrS\S\S\\	S4   S\\\	4   SS4
S jrS\S\\   4S jrS\S
\S\	SS4S jrS\S
\S\\	S4   S\\\	4   S\4
S jrS\S
\S\	S\	S\4
S jr S#S\S
\S\\   S\4S jjrS\S
\S\SS4S jrS\S
\S\SS4S jr S#S\S
\\   SS4S  jjr!S\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.
selfreturnNc                 @    [        5       U l        [        5       U l        g N)dict_eventsr   _lockr%   s    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__E   s     ""$'Nr   r3   c                 X    U R                   R                  U5        [        5       U l        g r(   )r0   updater   r+   r2   s     r   __setstate__EventEmitter.__setstate__J   s    U#V
r   eventc                     g r(   r   r%   r:   s     r   onEventEmitter.onN   s    DGr   fc                     g r(   r   r%   r:   r?   s      r   r=   r>   P   s    ;>r   c                 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_listenerrA   s      r   r=   r>   S   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?   r:   r%   s    r   r=   #EventEmitter.listens_to.<locals>.on   s    ##E10Hr   )r    )r%   r:   r=   s   `` r   rC   EventEmitter.listens_tou   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`.
rG   rA   s      r   rD   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%   r:   rM   rN   s       r   rH   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?   rS   rT   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 )Nr]   z%Uncaught, unspecified 'error' event: )
isinstance	Exceptionr   )r%   r:   r]   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   valuesrV   )r%   r:   rS   rT   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)ri   ra   )r%   r:   rS   rT   rg   s        r   rQ   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 $ )NrS   rT   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)rS   rT   r:   r?   r%   s     r   g.EventEmitter.once.<locals>._wrapper.<locals>.g   sh     ZZ ,dll56I1I--eQ7#  Z 8	   $)&))  Zs   8A  
A.)r   rH   )r?   rq   r:   r%   s   ` r   _wrapper#EventEmitter.once.<locals>._wrapper   s@    *** * * ##E1a0Hr   )r   )r%   r:   r?   rs   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lenrA   s      r   rp   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+   rp   rA   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<   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`.)rd   r*   re   r   rZ   r<   s     r   	listenersEventEmitter.listeners  s)    DLL$$UKM:??ABBr   )r*   r+   r(   )%r   r   r   r   r   Selfr-   r	   strr   r4   r8   r   r   r    r=   r
   r   rC   rD   rH   r   r   rV   r   r[   ra   boolri   rQ   ru   rp   r|   r   r   r   r   r   r   r   r#   r#   !   s    8"t " "4 GCH$5 
4 S(9 d  GGcGhy'/A&BG G>>c>g>'> > 8< / / /#+G#4 /	w'G!344	5 /D c hy'7I.J (4   G  ' 'c 'h '8 ' CHo S#X	
 
($ (3s8 (Q4 Q QC QD Q CHo S#X	
 
   	
 
: !% H 
	B$t $C $H $ $,d ,3 ,8 , ,
&4 & & &C CS CT(^ Cr   r#   N)collectionsr   	threadingr   typingr   r   r   r   r	   r
   r   r   r   r   r   r   r`   r   r   r    r#   r   r   r   <module>r      s^    $     KI K% % )8
,zC zCr   