)L i UdZddlmZddlZddlZddlZddlZddlZddlZddlm Z m Z ddlm Z m Z ddl mZmZmZmZgdZerddlmZdd lmZeZGd d ZeegdfZd ed < ddZ ddZGdde Zy)a8 Similar to `PyOS_InputHook` of the Python API, we can plug in an input hook in the asyncio event loop. The way this works is by using a custom 'selector' that runs the other event loop until the real selector is ready. It's the responsibility of this event hook to return when there is input ready. There are two ways to detect when input is ready: The inputhook itself is a callable that receives an `InputHookContext`. This callable should run the other event loop, and return when the main loop has stuff to do. There are two ways to detect when to return: - Call the `input_is_ready` method periodically. Quit when this returns `True`. - Add the `fileno` as a watch to the external eventloop. Quit when file descriptor becomes readable. (But don't read from it.) Note that this is not the same as checking for `sys.stdin.fileno()`. The eventloop of prompt-toolkit allows thread-based executors, for example for asynchronous autocompletion. When the completion for instance is ready, we also want prompt-toolkit to gain control again in order to display that. ) annotationsN)AbstractEventLoopget_running_loop) BaseSelector SelectorKey) TYPE_CHECKINGAnyCallableMapping)new_eventloop_with_inputhookset_eventloop_with_inputhookInputHookSelectorInputHookContext InputHook)FileDescriptorLike) TypeAliasc eZdZdZddZddZy)rz0 Given as a parameter to the inputhook. c ||_||_yN)_filenoinput_is_ready)selffilenors h/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/prompt_toolkit/eventloop/inputhook.py__init__zInputHookContext.__init__:s ,c|jSr)rrs rrzInputHookContext.fileno>s ||rN)rintrzCallable[[], bool]returnNone)r r)__name__ __module__ __qualname____doc__rrrrrr5s-rrrrclttj|}tj|}|S)z; Create a new event loop with the given inputhook. )r selectorsDefaultSelectorasyncioSelectorEventLoop) inputhookselectorloops rr r Es. !!:!:!|jj|||SN)data)r-registerrfileobjeventsr9s rr:zInputHookSelector.registerms }}%%gvD%AArc8|jj|Sr)r- unregister)rr<s rr?zInputHookSelector.unregisterrs}}''00rc>|jj||dSr8)r-modifyr;s rrAzInputHookSelector.modifyus }}##GV$#??rc8tttdgdkDrjj Sddd fd }t j |}|jd fd }jtj| tjdk7r#t jjgggdtjjd |j!JS#t$rY!wxYw) N_readyrtimeoutFcjjtjjddy)NrDxT)r-selectr3writer6)readyresultrrEsr run_selectorz.InputHookSelector.select..run_selectors1]]))'):F HHTWWd #Er)targetcSrr&)rJsrrz0InputHookSelector.select..input_is_readysLrwin32ir r!)r bool)lengetattrrr-rH threadingThreadstartr,rr5sysplatformr3readOSErrorjoin)rrErLthrrJrKs`` @@rrHzInputHookSelector.selectzs w')8R8 9A ==='''8 8     \ 2    '@A ||w& twwiR6 GGDGGT "  !!!     s!AD DDc|jr>tj|jtj|jdx|_|_|jjy)z% Clean up resources. N)r5r3closer6r-rs rr_zInputHookSelector.closesI 77 HHTWW  HHTWW $' rc6|jjSr)r-get_maprs rrazInputHookSelector.get_maps}}$$&&r)r-rr,"Callable[[InputHookContext], None]r r!r)r<rr= _EventMaskr9r r r)r<rr r)rEz float | Noner z$list[tuple[SelectorKey, _EventMask]]rP)r z(Mapping[FileDescriptorLike, SelectorKey]) r"r#r$r%rr:r?rArHr_rar&rrrr]s%$%1S% %LPB)B3=BEHB B 1LP@)@3=@EH@ @ '+7#7 -7r 'rr)r,rbr r)r% __future__rr*r3rHr(rWrTrrrrtypingrr r r __all__ _typeshedrtyping_extensionsrrrcrr__annotations__r r rr&rrrjs2#  7/88 ,+J   !1 2D 89 991 1  b' b'r