
    {	                     j    d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	 ddl
mZ dd	lZd
Z G d de      Zy	)zk
Win32 asyncio event loop.

Windows notes:
- Somehow it doesn't seem to work with the 'ProactorEventLoop'.
    )unicode_literals   )	EventLoopINPUT_TIMEOUT   )ConsoleInputReader)EventLoopCallbacks)AsyncioTimeoutN)Win32AsyncioEventLoopc                   ^    e Zd Zd
dZej
                  d        Zd Zd Zd Z	d
dZ
d Zd	 Zy)r   Nc                 x    t               | _        d| _        d| _        |xs t	        j
                         | _        y NF)r   _console_input_readerrunningclosedasyncioget_event_looploop)selfr   s     9lib/third_party/prompt_toolkit/eventloop/asyncio_win32.py__init__zWin32AsyncioEventLoop.__init__   s0    %7%9"4G224	    c              #   b  K   t        |t              sJ | j                  rt        d      t	        t
        |j                  | j                        }d| _        	 | j                  rY|j                          	 t        | j                  j                  d| j                  j                              }	 t        |       |j%                          y# t        $ r}|j                   d   }Y d}~nd}~ww xY w|D ]  }|j#                  |        | j                  r\# |j%                          w xY ww)z)
        The input 'event loop'.
        zEvent loop already closed.TNr   )
isinstancer	   r   	Exceptionr
   r   input_timeoutr   r   resetiterrun_in_executorr   readnextStopIterationargsfeed_keystop)r   stdin	callbackstimeoutgekeysks           r   run_as_coroutinez&Win32AsyncioEventLoop.run_as_coroutine   s      )%7888;;899 	0G0GS	,,%TYY66tT=W=W=\=\]^A"1g  LLN % %66!9D% A&&q)  ,, LLNsC   AD/D 6AC >D/	C1C,'D ,C11'D D,,D/c                     d| _         y r   )r   r   s    r   r%   zWin32AsyncioEventLoop.stop=   s	    r   c                 F    d| _         | j                  j                          y )NT)r   r   closer/   s    r   r1   zWin32AsyncioEventLoop.close@   s     ""((*r   c                 <    | j                   j                  d |       y N)r   r   )r   callbacks     r   r   z%Win32AsyncioEventLoop.run_in_executorG   s    		!!$1r   c                 :    | j                   j                  |       y r3   )r   call_soon_threadsafe)r   r4   _max_postpone_untils      r   call_from_executorz(Win32AsyncioEventLoop.call_from_executorJ   s    		&&x0r   c                 <    | j                   j                  ||       y)z; Start watching the file descriptor for read availability. N)r   
add_reader)r   fdr4   s      r   r:   z Win32AsyncioEventLoop.add_readerM   s    		R*r   c                 :    | j                   j                  |       y)z: Stop watching the file descriptor for read availability. N)r   remove_reader)r   r;   s     r   r=   z#Win32AsyncioEventLoop.remove_readerQ   s    		#r   r3   )__name__
__module____qualname__r   r   	coroutiner-   r%   r1   r   r8   r:   r=    r   r   r   r      s@    5  @+21+$r   r   )__doc__
__future__r   baser   r   terminal.win32_inputr   r'   r	   asyncio_baser
   r   __all__r   rB   r   r   <module>rI      s1    ( * 5 ) ( 
>$I >$r   