
    &i                        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dS )    )	dataclass)wraps)AnyCallableIteratorListTypeTypeVar)EventEmitterc                   $    e Zd ZU eed<   eed<   dS )HandlereventmethodN)__name__
__module____qualname__str__annotations__r        H/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/pyee/cls.pyr   r      s'         JJJr   r   c                   <    e Zd ZddZddZdee         fdZd ZdS )HandlersreturnNc                     g | _         d S N	_handlersselfs    r   __init__zHandlers.__init__   s    (*r   c                 :    | j                             |           d S 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    DN###r   c                     g | _         d S 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      sk        + + + +' ' ' '$(7+ $ $ $ $    r   r   r   r   c                 0     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                 Z    t                               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-      s7    ( x       r   r    r   c                 P     t                    dt          f fd            }|S )Nr   c                       g| R i |S r   r   )argskwargsr   r    s     r   boundz_bind.<locals>.bound-   s#    vd,T,,,V,,,r   )r   r   )r    r   r2   s   `` r   _bindr3   ,   sE    
6]]-# - - - - - - ]- Lr   Cls)r2   clsc           	          t          t                    t                                           | 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|R i | t          | d          st                      | _        D ]5}| j                            |j        t          | |j                             6d S )Nevent_emitter)hasattrr   r8   r-   r   r3   r   )r    r0   r1   hhandlersog_inits       r   initzevented.<locals>.initi   s    &t&&&v&&&t_-- 	0!-D 	B 	BA!!!'5qx+@+@AAAA	B 	Br   )listr   r)   r!   r   r   )r5   r=   r;   r<   s     @@r   eventedr?   7   s    Z #9ooHOOG
3<B3 Bs Bc Bd B B B B B 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      sm   ! ! ! ! ! !       ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? ?              
        HJJ	
c 
hz834 
 
 
 
 S S     ge4   = = = = = = = =r   