+
    8LiM)                        R t ^ RIt^ RIt^ RIt^ RIt^ RIHtHt ^ RIH	t	H
t
HtHtHt ]P                  R8  d   ^ RIHt M^ RIHt ]P"                  ! ]4      t]P(                  ]P*                  ]P,                  uttt]P0                  ! ]P2                  4      t]P6                  ! 4       t]]R,          ]R,          ]R,          ]R,          3,          t ! R	 R
]4      tR# )z+Common code for event loop implementations.N)ABCabstractmethod)AnyCallableListOptionalUnion)Literalstdiosockettcpchildc                   2  a  ] tR t^$t o RtV 3R lR lt]V 3R lR l4       t]V 3R lR l4       tV 3R lR	 lt	]V 3R
 lR l4       t
V 3R lR lt]V 3R lR l4       tV 3R lR lt]V 3R lR l4       tR t]V 3R lR l4       tV 3R lR ltR t]V 3R lR l4       tV 3R lR lt]V 3R lR l4       tV 3R  lR! lt]V 3R" lR# l4       tV 3R$ lR% lt]V 3R& lR' l4       tV 3R( lR) ltV 3R* lR+ ltV 3R, lR- ltV 3R. lR/ ltV 3R0 lR1 ltR2tV t R3# )4BaseEventLoopa	  Abstract base class for all event loops.

Event loops act as the bottom layer for Nvim sessions created by this
library. They hide system/transport details behind a simple interface for
reading/writing bytes to the connected Nvim instance.

A lifecycle of event loop is as follows: (1. -> [2. -> 3.]* -> 4.)
  1. initialization (__init__): connection to Nvim is established.
  2. run(data_cb): run the event loop (blocks until the loop stops).
     Requests are sent to the remote neovim by calling send(), and
     responses (messages) from the remote neovim will be passed to the
     given `data_cb` callback function while the event loop is running.
     Note that run() may be called multiple times.
  3. stop(): stop the event loop.
  4. close(): close the event loop, destroying all the internal resources.

This class exposes public methods for interacting with the underlying
event loop and delegates implementation-specific work to the following
methods, which subclasses are expected to implement:

- `_init()`: Implementation-specific initialization
- `_connect_tcp(address, port)`: connect to Nvim using tcp/ip
- `_connect_socket(path)`: Same as tcp, but use a UNIX domain socket or
  named pipe.
- `_connect_stdio()`: Use stdin/stdout as the connection to Nvim
- `_connect_child(argv)`: Use the argument vector `argv` to spawn an
  embedded Nvim that has its stdin/stdout connected to the event loop.
- `_start_reading()`: Called after any of _connect_* methods. Can be used
  to perform any post-connection setup or validation.
- `_send(data)`: Send `data` (byte array) to Nvim (usually RPC request).
- `_run()`: Runs the event loop until stopped or the connection is closed.
  The following methods can be called upon some events by the event loop:
  - `_on_data(data)`: When Nvim sends some data (usually RPC response).
  - `_on_signal(signum)`: When a signal is received.
  - `_on_error(exc)`: When a non-recoverable error occurs (e.g:
    connection lost, or any other OSError)
  Note that these _on_{data,signal,error} methods are not 'final', may be
  changed around an execution of run(). The subclasses are expected to
  handle any early messages arriving while _on_data is not yet set.
- `_stop()`: Stop the event loop.
- `_interrupt(data)`: Like `stop()`, but may be called from other threads
  this.
- `_setup_signals(signals)`: Add implementation-specific listeners for
  for `signals`, which is a list of OS-specific signal numbers.
- `_teardown_signals()`: Removes signal listeners set by `_setup_signals`
c                ,   < V ^8  d   QhRS[ RS[RS[/# )   transport_typeargskwargs)TTransportTyper   )format__classdict__s   "D/usr/lib/python3/dist-packages/pynvim/msgpack_rpc/event_loop/base.py__annotate__BaseEventLoop.__annotate__T   s"      ~ c S     c                B   Wn         \        R \        P                  P	                  4        4       4      V n        RV n        RV n         \        V RP                  V4      4      ! V/ VB  T P                  4        R#   \         d   pT P                  4        ThRp?ii ; i)aZ  Initialize and connect the event loop instance.

The only arguments are the transport type and transport-specific
configuration, like this:

>>> BaseEventLoop('tcp', '127.0.0.1', 7450)
>>> BaseEventLoop('socket', '/tmp/nvim-socket')
>>> BaseEventLoop('stdio')
>>> BaseEventLoop('child', ['nvim', '--embed', '--headless', '-u', 'NONE'])

Implementation-specific initialization should be made in the __init__
constructor of the subclass, which must call the constructor of the
super class (BaseEventLoop), in which one of the `_connect_*` methods
(based on `transport_type`) and then `_start_reading()`.
c              3   ^   "   T F#  w  rVP                  R 4      '       g   K  W!3x  K%  	  R# 5i)SIGN)
startswith).0vks   &  r   	<genexpr>)BaseEventLoop.__init__.<locals>.<genexpr>e   s)      61H!"e!4 %qf1Hs   --Nz_connect_{})_transport_typedictsignal__dict__items	_signames_on_data_errorgetattrr   	Exceptionclose_start_reading)selfr   r   r   es   &&*, r   __init__BaseEventLoop.__init__T   s       . 61F1F1H 6 6;?/3	D-..~>?PP 	  	JJLG	s   	!A< <BBBc                   < V ^8  d   QhRR/# r   returnN )r   r   s   "r   r   r   q        $ $ $r   c                    \        4       hNNotImplementedErrorr1   s   &r   r0   BaseEventLoop._start_readingp       !##r   c                $   < V ^8  d   QhRS[ RR/# r   datar7   Nbytes)r   r   s   "r   r   r   u   s     $ $% $D $r   c                    \        4       hr;   r<   r1   rC   s   &&r   _sendBaseEventLoop._sendt   r@   r   c                *   < V ^8  d   QhRS[ RS[RR/# r   addressportr7   Nstrint)r   r   s   "r   r   r   x   s"     ) )3 )c )d )r   c                *     V P                  W4       R# )z@Connect to tcp/ip `address`:`port`. Delegated to `_connect_tcp`.N)_connect_tcpr1   rL   rM   s   &&&r   connect_tcpBaseEventLoop.connect_tcpx   s    '(r   c                *   < V ^8  d   QhRS[ RS[RR/# rK   rN   )r   r   s   "r   r   r      s"     $ $C $s $t $r   c                    \        4       hr;   r<   rS   s   &&&r   rR   BaseEventLoop._connect_tcp~   r@   r   c                $   < V ^8  d   QhRS[ RR/# r   pathr7   NrO   )r   r   s   "r   r   r      s     # #3 #4 #r   c                *     V P                  V4       R# )z<Connect to socket at `path`. Delegated to `_connect_socket`.N)_connect_socketr1   r[   s   &&r   connect_socketBaseEventLoop.connect_socket   s    T"r   c                $   < V ^8  d   QhRS[ RR/# rZ   r\   )r   r   s   "r   r   r      s     $ $C $D $r   c                    \        4       hr;   r<   r_   s   &&r   r^   BaseEventLoop._connect_socket   r@   r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r      s      t r   c                (     V P                  4        R# )z:Connect using stdin/stdout. Delegated to `_connect_stdio`.N)_connect_stdior>   s   &r   connect_stdioBaseEventLoop.connect_stdio   s    r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r      r9   r   c                    \        4       hr;   r<   r>   s   &r   rg   BaseEventLoop._connect_stdio   r@   r   c                *     V P                  V4       R# )z;Connect a new Nvim instance. Delegated to `_connect_child`.N)_connect_childr1   argvs   &&r   connect_childBaseEventLoop.connect_child   s    D!r   c                4   < V ^8  d   QhRS[ S[,          RR/# )r   rp   r7   N)r   rO   )r   r   s   "r   r   r      s     $ $49 $ $r   c                    \        4       hr;   r<   ro   s   &&r   rn   BaseEventLoop._connect_child   r@   r   c                $   < V ^8  d   QhRS[ RR/# rB   rD   )r   r   s   "r   r   r      s       4 r   c                *     V P                  V4       R# )z!Queue `data` for sending to Nvim.N)rH   rG   s   &&r   sendBaseEventLoop.send   s    

4r   c                (    V P                  V4       R# )ztCall a function in the event loop thread.

This is the only safe way to interact with a session from other
threads.
N)_threadsafe_callr1   fns   &&r   threadsafe_callBaseEventLoop.threadsafe_call   s     	b!r   c                8   < V ^8  d   QhRS[ . S[3,          RR/# )r   r}   r7   N)r   r   )r   r   s   "r   r   r      s$     $ $8BG#4 $ $r   c                    \        4       hr;   r<   r|   s   &&r   r{   BaseEventLoop._threadsafe_call   r@   r   c                :   < V ^8  d   QhRS[ S[.R3,          RR/# )r   data_cbNr7   )r   rE   )r   r   s   "r   r   r      s&      8UGTM2 t r   c                V   V P                   '       d6   V P                   p\        V P                   \        4      '       d   RV n         VhWn        \        P
                  ! 4       \        8X  d0   V P                  \        P                  \        P                  .4        V P                  4         \        P
                  ! 4       \        8X  d:   V P                  4        \        P                  ! \        P                  \        4       RV n        V P                   '       d   V P                   hR# )zARun the event loop, and receives response messages to a callback.N)r,   
isinstanceKeyboardInterruptr+   	threadingcurrent_threadmain_thread_setup_signalsr'   SIGINTSIGTERM_run_teardown_signalsdefault_int_handler)r1   r   errs   && r   runBaseEventLoop.run   s    ;;;++C$++'899
 #I  ##%4 ?@		##%4""$MM&--)<= ;;; ++ r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r      s     $ $d $r   c                    \        4       hr;   r<   r>   s   &r   r   BaseEventLoop._run   r@   r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r      s      d r   c                &    V P                  4        R# zStop the event loop.N)_stopr>   s   &r   stopBaseEventLoop.stop   s    

r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r      s     $ $t $r   c                    \        4       hr;   r<   r>   s   &r   r   BaseEventLoop._stop   r@   r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r      s      t r   c                &    V P                  4        R# r   )_closer>   s   &r   r/   BaseEventLoop.close   s    r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r      s     $ $ $r   c                    \        4       hr;   r<   r>   s   &r   r   BaseEventLoop._close   r@   r   c                8   < V ^8  d   QhRS[ P                  RR/# )r   signumr7   N)r'   Signals)r   r   s   "r   r   r      s       D r   c                &   R P                  V P                  V,          4      p V\        P                  8X  d   V P                  R8X  d   R# V\        P                  8X  d   \        4       V n        M\        V4      V n        V P                  4        R# )zReceived signal {}r
   N)	r   r*   r'   r   r%   r   r,   r.   r   )r1   r   msgs   && r   
_on_signalBaseEventLoop._on_signal   sh    "))$..*@A V]]"t';';w'F V]]"+-DK#C.DK		r   c                $   < V ^8  d   QhRS[ RR/# )r   excr7   N)r.   )r   r   s   "r   r   r      s      Y 4 r   c                P     V P                   f   Wn         V P                  4        R # r;   )r,   r   )r1   r   s   &&r   	_on_errorBaseEventLoop._on_error   s    ;; K		r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r     s      t r   c                &    V P                  4        R # r;   )r   r>   s   &r   _on_interruptBaseEventLoop._on_interrupt  s    		r   c                H   < V ^8  d   QhRS[ S[P                  ,          RR/# )r   signalsr7   N)r   r'   r   )r   r   s   "r   r   r   	  s$      d6>>&: t r   c                    R # r;   r8   )r1   r   s   &&r   r   BaseEventLoop._setup_signals	      r   c                   < V ^8  d   QhRR/# r6   r8   )r   r   s   "r   r   r     s      4 r   c                    R # r;   r8   r>   s   &r   r   BaseEventLoop._teardown_signals  r   r   )r,   r+   r*   r%   N)!__name__
__module____qualname____firstlineno____doc__r3   r   r0   rH   rT   rR   r`   r^   rh   rg   rq   rn   rx   r~   r{   r   r   r   r   r/   r   r   r   r   r   r   __static_attributes____classdictcell__)r   s   @r   r   r   $   s`    -^ 8 $ $ $ $) ) $ $# # $ $  $ $" $ $ " $ $ B $ $  $ $  $ $ $    r   r   )      )r   loggingr'   sysr   abcr   r   typingr   r   r   r   r   version_infotyping_extensionsr	   	getLoggerr   loggerdebuginfowarningwarn	getsignalr   r   r   r   r   r   r8   r   r   <module>r      s    1   
  # 7 7f)			8	$\\6;; tT &&v}}5 &&(GHENGiC ir   