Xj |ddlmZddlmZmZmZmZmZmZddl m Z m Z ddl m Z ddlmZmZeZdgZGddeZy) ) iscoroutine)AnyCallablecastDictOptionalTuple)DeferredensureDeferred)Failure) EventEmitter PyeeErrorTwistedEventEmitterc xeZdZdZdeddffd Zdededeedfd e e efddf d Z ded e d eddffd Z xZ S)raAn event emitter class which can run twisted coroutines and handle returned Deferreds, in addition to synchronous blocking functions. For example: ```py @ee.on('event') @inlineCallbacks def async_handler(*args, **kwargs): yield returns_a_deferred() ``` or: ```py @ee.on('event') async def async_handler(*args, **kwargs): await returns_a_deferred() ``` When async handlers fail, Failures are first emitted on the `failure` event. If there are no `failure` handlers, the Failure's associated exception is then emitted on the `error` event. If there are no `error` handlers, the exception is raised. For consistency, when handlers raise errors synchronously, they're captured, wrapped in a Failure and treated as an async failure. This is unlike the behavior of EventEmitter, which have no special error handling. For twisted coroutine event handlers, calling emit is non-blocking. In other words, you do not have to await any results from emit, and the coroutine is scheduled in a fire-and-forget fashion. Similar behavior occurs for "sync" functions which return Deferreds. selfreturnNc*tt| y)N)superr__init__)r __class__s `/mnt/ssd/data/Dropbox/adrian/vault-secondbrain/venv/lib/python3.12/site-packages/pyee/twisted.pyrzTwistedEventEmitter.__init__5s !413fargs.kwargscd} ||i|}t|r t|}nt|tr|}n|sydtddffd }|j |y#t $rjdt YywxYw)Nfailurerc0|rjd|yy)Nr)emit)rrs rerrbackz.TwistedEventEmitter._emit_run..errbackKsIIi1r)rr isinstancer r addErrback Exceptionr)rrrrdresultr s` r _emit_runzTwistedEventEmitter._emit_run8s &* "''F6""6*FH- 2 2T 2 LL ! , IIi + ,sA#B?Beventerrorc|dk(rdt|tr |jyt|tr|j d|y|j dt d|yt ttt|j||y#t$r}|j d|Yd}~yd}~wwxYw)Nrr(zUnexpected failure object: ) r!r raiseExceptionr#rrrrrr_emit_handle_potential_error)rr'r(excrs rr+z0TwistedEventEmitter._emit_handle_potential_errorQs I %),((*E9- '5) '9/J5'-R#ST e/6 7 T Tu !,IIgs++,sB B?#B::B?)__name__ __module__ __qualname____doc__Selfrrr rrstrr&r+ __classcell__)rs@rrrs!F4t44"" "CHo"S#X "  "24CDrN)asynciortypingrrrrrr twisted.internet.deferr r twisted.python.failurer pyee.baser rr1__all__rrrr;s6 ==;*-  ! !N,Nr