
    &th%                         d dl mZ d dlmZ d dl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 Z ede          Zded
efdZdS )    )	dataclasswraps)Callable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        \/var/www/html/mycamper/aliexpress-site/backend/venv/lib/python3.11/site-packages/pyee/cls.pyr   r      s'         JJJr   r   c                   &    e Zd Zd Zd Zd Zd ZdS )Handlersc                     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   N)r   r   r   r   r!   r%   r'   r   r   r   r   r      sP        + + +' ' '$ $ $    r   r   r   returnc                 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   c                 @     t                     fd            }|S )Nc                       g| R i |S r   r   )argskwargsr   r   s     r   boundz_bind.<locals>.bound-   s#    vd,T,,,V,,,r   r   )r   r   r1   s   `` r   _bindr2   ,   s9    
6]]- - - - - ]- Lr   Cls)r1   clsc                     t          t                    t                                           | j        t	          | j                  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)
    ```
    c                      | g|R i | t          | d          st                      | _        D ]5}| j                            |j        t          | |j                             6d S )Nevent_emitter)hasattrr
   r7   r,   r   r2   r   )r   r/   r0   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   )r4   r<   r:   r;   s     @@r   eventedr>   7   sp    Z #9ooHOOG
3<B B B B B B CLJr   N)dataclassesr   	functoolsr   typingr   r   r   r	   pyeer
   r   r   r   r   r,   r2   r3   r>   r   r   r   <module>rC      sG   ! ! ! ! ! !       0 0 0 0 0 0 0 0 0 0 0 0              
        HJJ	
c 
hz834 
 
 
 
   ge4   = = = = = = = =r   