
    㾙h                         d dl mZ d dlmZ d dlmZmZmZmZm	Z	m
Z
 d dlmZ e G d d             Z G d d      Z e       Zd	ed
eegef   fdZdeded
efdZ e
de	      Zded
efdZy)    )	dataclass)wraps)AnyCallableIteratorListTypeTypeVar)EventEmitterc                   "    e Zd ZU eed<   eed<   y)HandlereventmethodN)__name__
__module____qualname__str__annotations__r        D/var/www/Befach/backend/env/lib/python3.12/site-packages/pyee/cls.pyr   r      s    Jr   r   c                   4    e Zd ZddZddZdee   fdZd Zy)HandlersreturnNc                     g | _         y N	_handlersselfs    r   __init__zHandlers.__init__   s	    (*r   c                 :    | j                   j                  |       y r   )r   append)r    handlers     r   r#   zHandlers.append   s    g&r   c                 ,    t        | j                        S r   )iterr   r   s    r   __iter__zHandlers.__iter__   s    DNN##r   c                     g | _         y r   r   r   s    r   resetzHandlers.reset   s	    r   )r   N)	r   r   r   r!   r#   r   r   r'   r)   r   r   r   r   r      s"    +'$(7+ $r   r   r   r   c                 ,     dt         dt         f fd}|S )zr
    Register an event handler on an evented class. See the `evented` class
    decorator for a full example.
    r   r   c                 H    t         j                  t        |              | S )N)r   r   )r   r#   r   )r   r   s    r   	decoratorzon.<locals>.decorator%   s    uV<=r   )r   )r   r,   s   ` r   onr-      s    ( x  r   r    r   c                 @     t              dt        f fd       }|S )Nr   c                       g| i |S r   r   )argskwargsr   r    s     r   boundz_bind.<locals>.bound-   s    d,T,V,,r   )r   r   )r    r   r2   s   `` r   _bindr3   ,   s'    
6]-# - - Lr   Cls)r2   clsc           	          t        t              t        j                          | j                  t	        | j                        dt
        dt
        dt
        ddffd       }|| _        | S )aQ  
    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    r0   r1   r   Nc                      | g|i | t        | d      st               | _        D ]<  }| j                  j                  |j                  t        | |j                               > y )Nevent_emitter)hasattrr   r8   r-   r   r3   r   )r    r0   r1   hhandlersog_inits       r   initzevented.<locals>.initi   sX    &t&v&t_-!-DA!!!''5qxx+@A r   )listr   r)   r!   r   r   )r5   r=   r;   r<   s     @@r   eventedr?   7   sm    Z #9oHOOG
3<<B3 Bs Bc Bd B B CLJr   N)dataclassesr   	functoolsr   typingr   r   r   r   r	   r
   pyeer   r   r   r   r   r-   r3   r4   r?   r   r   r   <module>rD      s    !  ? ?    
  J	
c 
hz834 
 S S  e4 = = =r   