rh ddlmZddlmZmZmZmZmZmZddl m Z m Z ddl m Z ddlmZmZeZdgZGddeZdS) ) iscoroutine)AnyCallablecastDictOptionalTuple)DeferredensureDeferred)Failure) EventEmitter PyeeErrorTwistedEventEmitterc eZdZdZdeddffd 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. selfreturnNcVtt|dS)N)superr__init__)r __class__s X/var/lib/jenkins/jobs/Dev/workspace/my-venv/lib/python3.11/site-packages/pyee/twisted.pyrzTwistedEventEmitter.__init__5s& !4((1133333fargs.kwargscBd} ||i|}t|rt|}nt|tr|}n|sdSdtddffd }||dS#t $r&dt YdSwxYw)Nfailurerc<|rd|dSdS)Nr)emit)rrs rerrbackz.TwistedEventEmitter._emit_run..errbackKs/2IIi1111122r)rr isinstancer r addErrback Exceptionr)rrrrdresultr s` r _emit_runzTwistedEventEmitter._emit_run8s &* "Q'''F6"" "6**FH--   2 2T 2 2 2 2 2 2 LL ! ! ! ! ! , , , IIi + + + + + + ,sA..,BBeventerrorc|dkrt|trE |dS#t$r!}|d|Yd}~dSd}~wwxYwt|tr|d|dS|dt d|dSt ttt| ||dS)Nrr(zUnexpected failure object: ) r!r raiseExceptionr#rrrrrr_emit_handle_potential_error)rr'r(excrs rr+z0TwistedEventEmitter._emit_handle_potential_errorQs I  %)) U,((***** ,,,IIgs+++++++++,E9-- U '5))))) '9-R5-R-R#S#STTTTT e/66 7 7 T Tu     s4 AAA)__name__ __module__ __qualname____doc__Selfrrr rrstrr&r+ __classcell__)rs@rrrs!!F4t4444444"" "CHo"S#X "  """"24CDrN)asynciortypingrrrrrr twisted.internet.deferr r twisted.python.failurer pyee.baser rr1__all__rrrr;s ================;;;;;;;;******--------  ! !NNNNN,NNNNNr