Ë
    V.jò  ã                  ó
  — U d Z ddlmZ ddlZddlZddlZddlZddlZddlZddlm	Z	m
Z
 ddlmZmZ ddlmZmZmZmZ g d¢ZerddlmZ dd	lmZ eZ G d
„ d«      Zeegdf   Zded<   	 	 	 	 dd„Z	 	 	 	 dd„Z G d„ de«      Zy)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)ÚAbstractEventLoopÚget_running_loop)ÚBaseSelectorÚSelectorKey)ÚTYPE_CHECKINGÚAnyÚCallableÚMapping)Únew_eventloop_with_inputhookÚset_eventloop_with_inputhookÚInputHookSelectorÚInputHookContextÚ	InputHook)ÚFileDescriptorLike)Ú	TypeAliasc                  ó    — e Zd ZdZdd„Zdd„Zy)r   z0
    Given as a parameter to the inputhook.
    c                ó    — || _         || _        y ©N)Ú_filenoÚinput_is_ready)ÚselfÚfilenor   s      údC:\xampp\htdocs\tradingbinance\backend\.venv\Lib\site-packages\prompt_toolkit/eventloop/inputhook.pyÚ__init__zInputHookContext.__init__:   s   € ØˆŒØ,ˆÕó    c                ó   — | j                   S r   )r   ©r   s    r   r   zInputHookContext.fileno>   s   € Ø�|‰|Ðr   N)r   Úintr   zCallable[[], bool]ÚreturnÚNone)r    r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   © r   r   r   r   5   s   „ ñó-ôr   r   r   r   c                ól   — t        t        j                  «       | «      }t        j                  |«      }|S )z;
    Create a new event loop with the given inputhook.
    )r   Ú	selectorsÚDefaultSelectorÚasyncioÚSelectorEventLoop)Ú	inputhookÚselectorÚloops      r   r   r   E   s.   € ô !¤×!:Ñ!:Ó!<¸iÓH€HÜ×$Ñ$ XÓ.€DØ€Kr   c                óF   — t        | «      }t        j                  |«       |S )zL
    Create a new event loop with the given inputhook, and activate it.
    )r   r*   Úset_event_loop)r,   r.   s     r   r   r   P   s!   € ô (¨	Ó2€DÜ×Ñ˜4Ô Ø€Kr   c                  ó‚   — e Zd ZdZ	 	 	 	 	 	 d
d„Z	 d	 	 	 	 	 	 	 dd„Zdd„Z	 d	 	 	 	 	 	 	 dd„Z	 d	 	 	 dd„Zdd„Z	dd	„Z
y)r   zµ
    Usage:

        selector = selectors.SelectSelector()
        loop = asyncio.SelectorEventLoop(InputHookSelector(selector, inputhook))
        asyncio.set_event_loop(loop)
    c                ób   — || _         || _        t        j                  «       \  | _        | _        y r   )r-   r,   ÚosÚpipeÚ_rÚ_w)r   r-   r,   s      r   r   zInputHookSelector.__init__f   s&   € ð !ˆŒØ"ˆŒÜŸ7™7›9ÑˆŒ�•r   Nc                ó>   — | j                   j                  |||¬«      S ©N)Údata)r-   Úregister©r   ÚfileobjÚeventsr9   s       r   r:   zInputHookSelector.registerm   s    € ð �}‰}×%Ñ% g¨v¸DÐ%ÓAÐAr   c                ó8   — | j                   j                  |«      S r   )r-   Ú
unregister)r   r<   s     r   r?   zInputHookSelector.unregisterr   s   € Ø�}‰}×'Ñ'¨Ó0Ð0r   c                ó>   — | j                   j                  ||d ¬«      S r8   )r-   Úmodifyr;   s       r   rA   zInputHookSelector.modifyu   s    € ð �}‰}×#Ñ# G¨V¸$Ð#Ó?Ð?r   c                ó8  ‡ ‡‡‡— t        t        t        «       dg «      «      dkD  r‰ j                  j	                  ‰¬«      S dŠd Šd
ˆˆˆ ˆfd„}t        j                  |¬«      }|j                  «        dˆfd„}‰ j                  t        ‰ j                  |«      «       	 t        j                  dk7  r#t	        j                  ‰ j                  gg g d «       t        j                  ‰ j                  d	«       |j!                  «        ‰€J ‚‰S # t        $ r Y Œ!w xY w)NÚ_readyr   ©ÚtimeoutFc                 ó‚   •— ‰j                   j                  ‰¬«      Št        j                  ‰j                  d«       dŠ y )NrD   ó   xT)r-   Úselectr3   Úwriter6   )ÚreadyÚresultr   rE   s   €€€€r   Úrun_selectorz.InputHookSelector.select.<locals>.run_selector†   s1   ø€ à—]‘]×)Ñ)°'Ð)Ó:ˆFÜ�H‰H�T—W‘W˜dÔ#Ø‰Er   )Útargetc                 ó   •— ‰ S r   r&   )rJ   s   €r   r   z0InputHookSelector.select.<locals>.input_is_ready�   s   ø€ ØˆLr   Úwin32i   ©r    r!   )r    Úbool)ÚlenÚgetattrr   r-   rH   Ú	threadingÚThreadÚstartr,   r   r5   ÚsysÚplatformr3   ÚreadÚOSErrorÚjoin)r   rE   rL   Úthr   rJ   rK   s   ``   @@r   rH   zInputHookSelector.selectz   sô   û€ ô
 ŒwÔ'Ó)¨8°RÓ8Ó9¸AÒ=Ø—=‘=×'Ñ'°Ð'Ó8Ð8àˆØˆ÷	ð 	ô ×Ñ \Ô2ˆØ
�‰Œ
õ	ð 	�‰Ô'¨¯©°Ó@ÔAð	ô �|‰|˜wÒ&Ü—‘˜tŸw™w˜i¨¨R°Ô6ä�G‰G�D—G‘G˜TÔ"ð 	�‰Œ	ØÐ!Ð!Ð!Øˆøô ò 	ñ ð		ús   Â!AD Ä	DÄDc                óè   — | j                   r>t        j                  | j                   «       t        j                  | j                  «       dx| _         | _        | j                  j                  «        y)z%
        Clean up resources.
        éÿÿÿÿN)r5   r3   Úcloser6   r-   r   s    r   r_   zInputHookSelector.close³   sI   € ð �7Š7Ü�H‰H�T—W‘WÔÜ�H‰H�T—W‘WÔàÐˆŒ�$”'Ø�‰×ÑÕr   c                ó6   — | j                   j                  «       S r   )r-   Úget_mapr   s    r   ra   zInputHookSelector.get_map¾   s   € Ø�}‰}×$Ñ$Ó&Ð&r   )r-   r   r,   ú"Callable[[InputHookContext], None]r    r!   r   )r<   r   r=   Ú
_EventMaskr9   r	   r    r   )r<   r   r    r   )rE   zfloat | Noner    z$list[tuple[SelectorKey, _EventMask]]rP   )r    z(Mapping[FileDescriptorLike, SelectorKey])r"   r#   r$   r%   r   r:   r?   rA   rH   r_   ra   r&   r   r   r   r   ]   s°   „ ñð%Ø$ð%Ø1Sð%à	ó%ð LPðBØ)ðBØ3=ðBØEHðBà	óBó
1ð LPð@Ø)ð@Ø3=ð@ØEHð@à	ó@ð '+ð7Ø#ð7à	-ó7ór	ô'r   r   )r,   rb   r    r   )r%   Ú
__future__r   r*   r3   rH   r(   rW   rT   r   r   r   r   Útypingr   r	   r
   r   Ú__all__Ú	_typeshedr   Útyping_extensionsr   r   rc   r   r   Ú__annotations__r   r   r   r&   r   r   Ú<module>rj      s    ðòõ2 #ã Û 	Û Û Û 
Û ß 7ß /ß 8Ó 8ò€ñ Ý,Ý+à€J÷
ñ 
ð  Ð!1Ð 2°DÐ 8Ñ9€	ˆ9Ó 9ðØ1ðàóð
Ø1ð
àó
ôb'˜õ b'r   