grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026a BjŒj˜$ã@s$ddlmZmZGdd„deƒZdS)é)Ú EventLoopÚ ExitMainLoopc@s�eZdZdZdd„Zdd„Zdd„Zdd „Zd d „Zd d „Z dd„Z dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"S)#Ú TrioEventLoopzn Event loop based on the ``trio`` module. ``trio`` is an async library for Python 3.5 and later. cCs<ddl}d|_i|_g|_||_d|_|j|_|jj |_ dS)z Constructor.éN) ÚtrioÚ _idle_handleÚ_idle_callbacksÚ_pending_tasksÚ_trioÚ_nurseryÚsleepÚ_sleepÚhazmatZ wait_readableÚ_wait_readable)Úselfr©rú@/usr/lib64/python3.9/site-packages/urwid/_async_kw_event_loop.pyÚ__init__ szTrioEventLoop.__init__cCs| |j||¡S)aLCalls `callback()` a given time from now. No parameters are passed to the callback. Parameters: seconds: time in seconds to wait before calling the callback callback: function to call from the event loop Returns: a handle that may be passed to `remove_alarm()` )Ú _start_taskÚ _alarm_task)rÚsecondsÚcallbackrrrÚalarm.s zTrioEventLoop.alarmcCs |jd7_||j|j<|jS)zÚCalls `callback()` when the event loop enters the idle state. There is no such thing as being idle in a Trio event loop so we simulate it by repeatedly calling `callback()` with a short delay. r)rr)rrrrrÚ enter_idle;s zTrioEventLoop.enter_idlecCs | |¡S)zeRemoves an alarm. Parameters: handle: the handle of the alarm to remove ©Ú _cancel_scope©rZhandlerrrÚ remove_alarmEszTrioEventLoop.remove_alarmcCs&z |j|=Wnty YdS0dS)zuRemoves an idle callback. Parameters: handle: the handle of the idle callback to remove FT)rÚKeyErrorrrrrÚremove_enter_idleMs   zTrioEventLoop.remove_enter_idlecCs | |¡S)zðRemoves a file descriptor being watched for input. Parameters: handle: the handle of the file descriptor callback to remove Returns: True if the file descriptor was watched, False otherwise rrrrrÚremove_watch_fileYs zTrioEventLoop.remove_watch_filecCs|j }| ¡|S)z¾Cancels the given Trio cancellation scope. Returns: True if the scope was cancelled, False if it was cancelled already before invoking this function )Ú cancel_calledÚcancel)rÚscopeZexistedrrrrdszTrioEventLoop._cancel_scopecsn|j‰G‡fdd„d|jjjƒ}|ƒ}|jj |j¡�$|jj|j|gd�Wdƒn1s`0YdS)z‡Starts the event loop. Exits the loop when any callback raises an exception. If ExitMainLoop is raised, exits cleanly. cseZdZ‡fdd„ZdS)z5TrioEventLoop.run..TrioIdleCallbackInstrumentcs |dkrˆ ¡D] }|ƒqdS©Nr©Úvalues©rÚtimeoutZ idle_callback©Zidle_callbacksrrÚbefore_io_waitzs zDTrioEventLoop.run..TrioIdleCallbackInstrument.before_io_waitN©Ú__name__Ú __module__Ú __qualname__r*rr)rrÚTrioIdleCallbackInstrumentysr/)Z instrumentsN) rr ÚabcÚ InstrumentÚ MultiErrorÚcatchÚ_handle_main_loop_exceptionÚrunÚ _main_task©rr/Zemulate_idle_callbacksrr)rr5os zTrioEventLoop.runc ƒsš|j‰G‡fdd„d|jjjƒ}|ƒ}|jj |j¡�P|jj |¡z |  ¡IdHW|jj  |¡n|jj  |¡0Wdƒn1sŒ0YdS)aÝStarts the main loop and blocks asynchronously until the main loop exits. This allows one to embed an urwid app in a Trio app even if the Trio event loop is already running. Example:: with trio.open_nursery() as nursery: event_loop = urwid.TrioEventLoop(nursery=nursery) loop = urwid.MainLoop(widget, event_loop=event_loop) with loop.start(): await event_loop.run_async() cseZdZ‡fdd„ZdS)z;TrioEventLoop.run_async..TrioIdleCallbackInstrumentcs |dkrˆ ¡D] }|ƒqdSr$r%r'r)rrr*–s zJTrioEventLoop.run_async..TrioIdleCallbackInstrument.before_io_waitNr+rr)rrr/•sr/N) rr r0r1r2r3r4rZadd_instrumentr6Zremove_instrumentr7rr)rÚ run_async„s zTrioEventLoop.run_asynccCs| |j||¡S)abCalls `callback()` when the given file descriptor has some data to read. No parameters are passed to the callback. Parameters: fd: file descriptor to watch for input callback: function to call when some input is available Returns: a handle that may be passed to `remove_watch_file()` )rÚ _watch_task)rÚfdrrrrÚ watch_file¤s zTrioEventLoop.watch_filecÃs>|�&| |¡IdH|ƒWdƒn1s00YdS)a0Asynchronous task that sleeps for a given number of seconds and then calls the given callback. Parameters: scope: the cancellation scope that can be used to cancel the task seconds: the number of seconds to wait callback: the callback to call N)r )rr#rrrrrr±s zTrioEventLoop._alarm_taskcCs |j ¡t|tƒrdS|SdS)a=Handles exceptions raised from the main loop, catching ExitMainLoop instead of letting it propagate through. Note that since Trio may collect multiple exceptions from tasks into a Trio MultiError, we cannot simply use a try..catch clause, we need a helper function like this. N)rÚclearÚ isinstancer)rÚexcrrrr4¾s  z)TrioEventLoop._handle_main_loop_exceptionc Ãspzb|j ¡4IdHš0|_| ¡|j ¡IdHWdƒIdHqZ1IdHsP0YWd|_nd|_0dS)zzMain Trio task that opens a nursery and then sleeps until the user exits the app by raising ExitMainLoop. N)r Z open_nurseryr Ú_schedule_pending_tasksZ sleep_forever)rrrrr6Ìs <zTrioEventLoop._main_taskcCs8|jD] \}}}|jj||g|¢RŽq|jdd…=dS)z‚Schedules all pending asynchronous tasks that were created before the nursery to be executed on the nursery soon. N)r r Ú start_soon)rÚtaskr#Úargsrrrr?×sz%TrioEventLoop._schedule_pending_taskscGs>|j ¡}|jr(|jj||g|¢RŽn|j |||f¡|S)apStarts an asynchronous task in the Trio nursery managed by the main loop. If the nursery has not started yet, store a reference to the task and the arguments so we can start the task when the nursery is open. Parameters: task: a Trio task to run Returns: a cancellation scope for the Trio task )r Z CancelScoper r@r Úappend)rrArBr#rrrrßs zTrioEventLoop._start_taskcÃsF|�.|js$| |¡IdH|ƒqWdƒn1s80YdS)aPAsynchronous task that watches the given file descriptor and calls the given callback whenever the file descriptor becomes readable. Parameters: scope: the cancellation scope that can be used to cancel the task fd: the file descriptor to watch callback: the callback to call N)r!r)rr#r:rrrrr9òs zTrioEventLoop._watch_taskN)r,r-r.Ú__doc__rrrrrr rr5r8r;rr4r6r?rr9rrrrrs"         rN)Z main_looprrrrrrrÚs