
    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
  S SKJr  \ " S S5      5       r " S S5      r\" 5       rS	\S
\\/\4   4S jrS\S\S
\4S jr\
" S\	S9rS\S
\4S jrg)    )	dataclass)wraps)AnyCallableIteratorListTypeTypeVar)EventEmitterc                   *    \ rS rSr% \\S'   \\S'   Srg)Handler   eventmethod N)__name__
__module____qualname____firstlineno__str__annotations__r   __static_attributes__r       :/var/www/html/env/lib/python3.13/site-packages/pyee/cls.pyr   r      s    Jr   r   c                   B    \ rS rSrS	S jrS	S jrS\\   4S jrS r	Sr
g)
Handlers   returnNc                     / U l         g N	_handlersselfs    r   __init__Handlers.__init__   s	    (*r   c                 :    U R                   R                  U5        g r    )r"   append)r$   handlers     r   r(   Handlers.append   s    g&r   c                 ,    [        U R                  5      $ r    )iterr"   r#   s    r   __iter__Handlers.__iter__   s    DNN##r   c                     / U l         g r    r!   r#   s    r   resetHandlers.reset   s	    r   r!   )r   N)r   r   r   r   r%   r(   r   r   r-   r0   r   r   r   r   r   r      s"    +'$(7+ $r   r   r   r   c                 0   ^  S[         S[         4U 4S jjnU$ )zf
Register an event handler on an evented class. See the `evented` class
decorator for a full example.
r   r   c                 B   > [         R                  [        TU S95        U $ )N)r   r   )r"   r(   r   )r   r   s    r   	decoratoron.<locals>.decorator%   s    uV<=r   )r   )r   r4   s   ` r   onr6      s    ( x  r   r$   r   c                 D   ^ ^ [        T5      S[        4UU 4S jj5       nU$ )Nr   c                     > T" T/U Q70 UD6$ r    r   )argskwargsr   r$   s     r   bound_bind.<locals>.bound-   s    d,T,V,,r   )r   r   )r$   r   r;   s   `` r   _bindr=   ,   s'    
6]-# - - Lr   Cls)r;   clsc           	         ^^ [        [        5      m[        R                  5         U R                  m[	        U R                  5      S[
        S[
        S[
        SS4UU4S jj5       nXl        U $ )a  
Configure an evented class.

Evented classes are classes which use an EventEmitter to call instance
methods during runtime. To achieve this without this helper, you would
instantiate an `EventEmitter` in the `__init__` method and then call
`event_emitter.on` for every method on `self`.

This decorator and the `on` function help make things look a little nicer
by defining the event handler on the method in the class and then adding
the `__init__` hook in a wrapper:

```py
from pyee.cls import evented, on

@evented
class Evented:
    @on("event")
    def event_handler(self, *args, **kwargs):
        print(self, args, kwargs)

evented_obj = Evented()

evented_obj.event_emitter.emit(
    "event", "hello world", numbers=[1, 2, 3]
)
```

The `__init__` wrapper will create a `self.event_emitter: EventEmitter`
automatically but you can also define your own event_emitter inside your
class's unwrapped `__init__` method. For example, to use this
decorator with a `TwistedEventEmitter`::

```py
@evented
class Evented:
    def __init__(self):
        self.event_emitter = TwistedEventEmitter()

    @on("event")
    async def event_handler(self, *args, **kwargs):
        await self.some_async_action(*args, **kwargs)
```
r$   r9   r:   r   Nc                    > T" U /UQ70 UD6  [        U S5      (       d  [        5       U l        T H<  nU R                  R                  UR                  [        XR                  5      5        M>     g )Nevent_emitter)hasattrr   rB   r6   r   r=   r   )r$   r9   r:   hhandlersog_inits       r   initevented.<locals>.initi   sY    &t&v&t_--!-DA!!!''5xx+@A r   )listr"   r0   r%   r   r   )r?   rG   rE   rF   s     @@r   eventedrJ   7   sk    Z #9oHOOG
3<<B3 Bs Bc Bd B B LJr   N)dataclassesr   	functoolsr   typingr   r   r   r   r	   r
   pyeer   r   r   r"   r   r6   r=   r>   rJ   r   r   r   <module>rO      s    !  ? ?    
  J	
c 
hz834 
 S S  e4 = = =r   