rhddlmZmZddlmZddlmZmZmZm Z m Z m Z m Z m Z mZddlZddlmZmZeZdgZejZGddeZdS))AbstractAsyncContextManagerasynccontextmanager) TracebackType) AnyAsyncGenerator AwaitableCallablecastDictOptionalTupleTypeN) EventEmitter PyeeErrorTrioEventEmitterc veZdZdZ ddedeededffd Zdeded e e d fd e e e fd ege dff d Zdeded e e d fd e e e fd df dZeded edfdZded dfdZdedeeedeedeed eef dZxZS)rarAn event emitter class which can run trio tasks in a trio nursery. By default, this class will lazily create both a nursery manager (the object returned from `trio.open_nursery()` and a nursery (the object yielded by using the nursery manager as an async context manager). It is also possible to supply an existing nursery manager via the `manager` argument, or an existing nursery via the `nursery` argument. Instances of TrioEventEmitter are themselves async context managers, so that they may manage the lifecycle of the underlying trio nursery. For example, typical usage of this library may look something like this:: ```py async with TrioEventEmitter() as ee: # Underlying nursery is instantiated and ready to go @ee.on('data') async def handler(data): print(data) ee.emit('event') # Underlying nursery and manager have been cleaned up ``` Unlike the case with the EventEmitter, all exceptions raised by event handlers are automatically emitted on the `error` event. This is important for trio coroutines specifically but is also handled for synchronous functions for consistency. For trio coroutine event handlers, calling emit is non-blocking. In other words, you should not attempt to await emit; the coroutine is scheduled in a fire-and-forget fashion. Nselfnurserymanagerz)AbstractAsyncContextManager[trio.Nursery]ctt|d|_d|_|r|rt d||_dS|r ||_dSt j|_dS)Nz?You may either pass a nursery or a nursery manager but not both)superr__init___nursery_managerrtrio open_nursery)rrr __class__s U/var/lib/jenkins/jobs/Dev/workspace/my-venv/lib/python3.11/site-packages/pyee/trio.pyrzTrioEventEmitter.__init__@s %%..000+/ OS  0 X$DMMM  0#DMMM -//DMMMfargs.kwargsreturnc dfd }|S)Nr#cK id{VdS#t$r!}d|Yd}~dSd}~wwxYw)Nerror) Exceptionemit)excr!r r"rs rrunnerz.TrioEventEmitter._async_runner..runnerYs~ (a(((((((((((( ( ( ( '3''''''''' (s A;A)r#N)rr r!r"r*s```` r _async_runnerzTrioEventEmitter._async_runnerSs:  ( ( ( ( ( ( ( ( (  rc|jstd|j||||dS)NzUninitialized trio nursery)rr start_soonr,)rr r!r"s r _emit_runzTrioEventEmitter._emit_runasK } :899 9   !3!3AtV!D!DEEEEEr)rNcK|j|WVdS|j@|j4d{V}||_|WVdddd{VdS#1d{VswxYwYdStd)aReturns an async contextmanager which manages the underlying nursery to the EventEmitter. The `TrioEventEmitter`'s async context management methods are implemented using this function, but it may also be used directly for clarity. Nz(Uninitialized nursery or nursery manager)rrr)rrs rcontextzTrioEventEmitter.contextks  = $JJJJJJ ] &}        '                                FGG Gs A AAcK||_tt|jd{VS)N)r1_contextr r __aenter__)rs rr4zTrioEventEmitter.__aenter__}sJ LLNN #t}--88:::::::::rtypevalue tracebackcK|jtd|j|||d{V}d|_d|_d|_|S)Nz(Attempting to exit uninitialized context)r3r __aexit__rr)rr5r6r7rvs rr9zTrioEventEmitter.__aexit__sd = FGG G=**4 BB B B B B B B    r)NN)__name__ __module__ __qualname____doc__Selfr Nurseryrr r rr strrr,r/rrr1r4r BaseExceptionrboolr9 __classcell__)rs@rrrs  H&*IM000'"0EF000000&    CHo S#X  "io% &    FF FCHoFS#X F  FFFFHH 0 1HHHH";t;(:;;;;  tM*+  & M*  $        r) contextlibrrtypesrtypingrrrr r r r r rr pyee.baserrr?__all__r@rr+rrrJsHGGGGGGG                       --------    ,rrrrr|rrrrrr