rh ddlmZddlmZddlmZmZmZmZm Z m Z ddl m Z eGddZ GddZeZd ed eegeffd Zd ed ed efdZe de Zded efdZdS)) dataclass)wraps)AnyCallableIteratorListTypeTypeVar) EventEmitterc$eZdZUeed<eed<dS)HandlereventmethodN)__name__ __module__ __qualname__str__annotations__rT/var/lib/jenkins/jobs/Dev/workspace/my-venv/lib/python3.11/site-packages/pyee/cls.pyr r s' JJJ rr c<eZdZddZddZdeefdZdZdS)HandlersreturnNcg|_dSN _handlersselfs r__init__zHandlers.__init__s (*rc:|j|dSr)rappend)r handlers rr#zHandlers.appends g&&&&&rc*t|jSr)iterrrs r__iter__zHandlers.__iter__sDN###rcg|_dSrrrs rresetzHandlers.resets r)rN) rrrr!r#rr r'r)rrrrrsk++++''''$(7+$$$$rrrrc0dtdtffd }|S)zr Register an event handler on an evented class. See the `evented` class decorator for a full example. rrcZtt||S)N)rr)rr#r )rrs r decoratorzon..decorator%s)uV<<<=== r)r)rr,s` ronr-s7 (x rr rcPtdtffd }|S)Nrcg|Ri|Srr)argskwargsrr s rboundz_bind..bound-s#vd,T,,,V,,,r)rr)r rr2s`` r_bindr3,sE 6]]-#------]- LrCls)r2clsc ttt|jt |jdt dt dt ddffd }||_|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 r0r1rNc|g|Ri|t|dst|_D]5}|j|jt ||j6dS)N event_emitter)hasattrr r8r-rr3r)r r0r1hhandlersog_inits rinitzevented..initis&t&&&v&&&t_-- 0!-D  B BA   ! !!'5qx+@+@ A A A A B Br)listrr)r!rr)r5r=r;r<s @@reventedr?7sZ#9ooH OO G 3<B3BsBcBdBBBBBBBCL JrN) dataclassesr functoolsrtypingrrrrr r pyeer r rrrr-r3r4r?rrrrDsm!!!!!!????????????????           HJJ  c hz834    SSge4   ========r