+
    8Lig&                     f   R t ^ RIt^ RIt^ RIt^ RIt^ RIHt ^ RIHt ^ RI	H
t
Ht ^ RIHt ^ RIHtHt ^ RIHt Rt]P(                  ! ]4      t]P.                  ]P0                  ]P2                  uttt] ! R	 R]4      4       t ! R
 R]P:                  4      t]] 3t!R t" ! R R]
4      t#R t$R t%R# )z$Legacy python/python3-vim emulation.N)
PathFinder)
ModuleType)Nvimwalk)ErrorResponse)plugin
rpc_export)format_exc_skip
ScriptHostc                      a  ] tR t^t o RtR tR tR t]! RRR7      R 4       t	]! R	RR7      R
 4       t
]! RRR7      R 4       t]! RRR7      R 4       t]! RRR7      R 4       tR tRtV tR# )r
   zCProvides an environment for running python plugins created for Vim.c                   V P                  V4       \        R4      V n        V P                  Vn        \	        RV P                  P
                  4       \        P                  V4      V n        V P                  \        P                  R&   \	        RV P                  P
                  4       VP                  RP                  VP                  4      RR7       VP                  RP                  VP                  4      RR7       R	# )
z-Initialize the legacy python-vim environment.__main__z
import sysvimz
import vimz?au DirChanged * call rpcnotify({}, "python_chdir", v:event.cwd)T)async_z,call rpcnotify({}, "python_chdir", getcwd())N)setupr   modulescript_contextexec__dict__	LegacyVim	from_nvim
legacy_vimsysmodulescommandformat
channel_idselfnvims   &&;/usr/lib/python3/dist-packages/pynvim/plugin/script_host.py__init__ScriptHost.__init__   s    

4 ,"kk\4;;//0#--d3!__E\4;;//0MVDOO$T 	 	3 	CfT__-d 	 	<    c                  a SV n          \        S4      V n        \        P                  P                  V P                  4       RSn        \        P                  P                  SP                  4        \        P                  V n	        \        P                  V n        \        V3R l4      \        n        \        V3R l4      \        n
        R# )zSetup import hooks and global streams.

This will add import hooks for importing modules from runtime
directories and patch the sys module so 'print' calls will be
forwarded to Nvim.

_vim_path_c                 &   < SP                  V 4      # N)	out_writedatar   s   &r    <lambda>"ScriptHost.setup.<locals>.<lambda>E       1Er#   c                 &   < SP                  V 4      # r'   )	err_writer)   s   &r    r+   r,   F   r-   r#   N)r   	path_hookhookr   
path_hooksappendVIM_SPECIAL_PATHpathstdoutsaved_stdoutstderrsaved_stderrRedirectStreamr   s   &fr    r   ScriptHost.setup3   s     	dO	dii( ,--.JJJJ#$EF
#$EF
r#   c                   V P                   p \        P                  P                  VP                  4       \        P
                  P                  V P                  4        V P                  \        n        V P                  \        n
        R# )z-Restore state modified from the `setup` call.N)r   r   r5   remover4   r2   r1   r7   r6   r9   r8   r   s   & r    teardownScriptHost.teardownH   sW    yy--.dii(&&
&&
r#   python_executeT)syncc                0   V P                  W#4       VP                  R4      '       d&   VR,          p\        V P                  V4      4       R#  \	        WP
                  P                  4       R#   \         d   p\        \        ^4      4      ThRp?ii ; i)zHandle the `python` ex command.=:   NNN)
_set_current_range
startswithprintpython_evalr   r   r   	Exceptionr   r	   )r   scriptrange_start
range_stopexprexcs   &&&&  r    r@   ScriptHost.python_executeT   s}     	8S!! ":D$""4()	=--. 	= 23<	=s   A0 0B;BBpython_execute_filec                R   V P                  W#4       \        VR4      ;_uu_ 4       p\        VP                  4       VR4      p \	        WPP
                  P                  4        RRR4       R#   \         d   p\        \        ^4      4      ThRp?ii ; i  + '       g   i     R# ; i)zHandle the `pyfile` ex command.rbr   N)
rE   opencompilereadr   r   r   rI   r   r	   )r   	file_pathrK   rL   frJ   rN   s   &&&&   r    rP   ScriptHost.python_execute_filef   s     	8)T""aQVVXy&9FAV[[112	 #"
  A#OA$67S@A #""s)   BA--B8BBBB&	python_do_rangec                V   V P                  W4       V P                  pV^,          pRpRV: RV: 2p\        W`P                  P                  4       V P                  P                  V,          pW8  Ed   Tp\        VR,           V4      p	VP                  P                  P                  P                  WR4      p
Rp. pV^,           p\        V
4       F  w  rV! W4      pVfp   V'       dL   V\        V4      ,           ^,
          pVP                  P                  P                  P                  VVRV4       V\        V4      ^,           ,          p. pMW\        V\        4      '       d   VP                  V4       M/\!        RRVP"                  P$                  ,          ,           4      p MV^,          pK  	  T	pV'       dE   V\        V4      ,           pVP                  P                  P                  P                  VVRV4       V'       g   EK  VhV P                  P                  V R# )	zHandle the `pydo` ex command.	_vim_pydozdef z(line, linenr):
 i  TNzpydo should return a string zor None, found %s instead)rE   r   r   r   r   mincurrentbufferapi	get_lines	enumeratelen	set_lines
isinstancestrr3   	TypeError	__class____name__)r   startstopcoder   fnamefunction_deffunctionsstartsstoplines	exceptionnewlineslinenrilineresultends   &&&&              r    rY   ScriptHost.python_do_ranger   s    	,yy
 8=dD\;;//0;;''.l
 Fd+ELL''++55fTJEIHaZF$U+!$/>$s8}4q8++//99&#:>Jc(ma//F!H,,OOF+ )*H,G,2,<,<,E,E-F+F !GI !% ,( Es8},##''11&#tXNyKK  'r#   rH   c                     \        WP                  P                  4      #   \         d   p\	        \        ^4      4      ThRp?ii ; i)z!Handle the `pyeval` vim function.N)evalr   r   rI   r   r	   )r   rM   rN   s   && r    rH   ScriptHost.python_eval   s>    	=kk2233 	= 23<	=s   ! AAApython_chdirFc                2    \         P                  ! V4       R# )z!Handle working directory changes.N)oschdir)r   cwds   &&r    r}   ScriptHost.python_chdir   s     	r#   c                r    V P                   P                  pVP                  P                  W4      Vn        R # r'   )r   r]   r^   range)r   ri   rj   r]   s   &&& r    rE   ScriptHost._set_current_range   s'    //)),,U9r#   )r1   r   r   r   r9   r7   N)rh   
__module____qualname____firstlineno____doc__r!   r   r>   r   r@   rP   rY   rH   r}   rE   __static_attributes____classdictcell____classdict__s   @r    r
   r
      s      N<0G*
'  t,= -=" %D1	A 2	A !-3( .3(j D)= *= U+ ,: :r#   c                   2   a  ] tR t^t o R tR tR tRtV tR# )r:   c                    Wn         R # r'   redirect_handler)r   r   s   &&r    r!   RedirectStream.__init__   s     0r#   c                (    V P                  V4       R # r'   r   )r   r*   s   &&r    writeRedirectStream.write   s    d#r#   c                F    V P                  R P                  V4      4       R# )
N)r   join)r   seqs   &&r    
writelinesRedirectStream.writelines   s    diin-r#   r   N)	rh   r   r   r   r!   r   r   r   r   r   s   @r    r:   r:      s     1$. .r#   r:   c                 H    \        V \        4      '       d   \        V 4      # V # r'   )rd   	num_typesre   )objs   &r    
num_to_strr      s    #y!!3x
r#   c                   &   a  ] tR t^t o R tRtV tR# )r   c                F    V P                  R V4      p\        \        V4      # )vim_eval)requestr   r   )r   rM   r   s   && r    r{   LegacyVim.eval   s    ll:t,J$$r#    N)rh   r   r   r   r{   r   r   r   s   @r    r   r      s     % %r#   r   c                 |   a aaaa V 3R  loV3R lo ! R R\         4      o ! VVV3R lR\         4      oVV 3R lpV# )c                  J   < S P                  4       '       d   . # \        S 4      # r'   )_thread_invaliddiscover_runtime_directories)r   s   r    
_get_pathspath_hook.<locals>._get_paths   s"    !!I+D11r#   c                   < ^ RI pVP                  R4      pV^ 8  d]   VRV pW^,           R pVP                  WR4      pVP                  ! V R\        V4      )  V,           .VO5!  pS	! WVP                  4      # VP                  W4      # )    N.)impfindfind_modulerb   __path__)
fullnameoldtailr5   r   idxnametailfmrr   _find_modules
   &&&      r    r   path_hook.<locals>._find_module   s    ll374C=D78$D//$-C__XnG}%=%DKsKF@@??822r#   c                   0   a  ] tR t^t o R tRR ltRtV tR# )"path_hook.<locals>.VimModuleLoaderc                    Wn         R # r'   r   )r   r   s   &&r    r!   +path_hook.<locals>.VimModuleLoader.__init__   s     Kr#   Nc                     \         P                  V,          #   \         d     Mi ; i^ RIpTP                  ! T.T P
                  O5!  # )r   N)r   r   KeyErrorr   load_moduler   )r   r   r5   r   s   &&& r    r   .path_hook.<locals>.VimModuleLoader.load_module   sC    {{8,, ??8:dkk::s    ''r   r'   )rh   r   r   r   r!   r   r   r   r   s   @r    VimModuleLoaderr      s     	!	; 	;r#   r   c                   Z   <a  ] tR t^t o ]RVVV3R ll4       t]RV3R ll4       tRtV tR# ) path_hook.<locals>.VimPathFinderNc                f   <  S! S! Y T;'       g    S! 4       4      4      #   \          d     R# i ; i)zMethod for Python 2.7 and 3.3.N)ImportError)r   r5   r   r   r   s   &&r    r   ,path_hook.<locals>.VimPathFinder.find_module   s=    & T5I5IZ\JL L s   ! ! 00c                >   < \         P                  ! V S! 4       V4      # )zMethod for Python 3.4+.)r   	find_spec)r   targetr   s   &&r    r   *path_hook.<locals>.VimPathFinder.find_spec   s     ''*,GGr#   r   r'   )	rh   r   r   r   staticmethodr   r   r   r   )r   r   r   r   s   @r    VimPathFinderr      s2     		 	 
	 
	H 
	Hr#   r   c                 6   < V SP                   8X  d   S# \        hr'   )r4   r   )r5   r   r   s   &r    r1   path_hook.<locals>.hook  s    4(((  r#   )object)r   r1   r   r   r   r   s   f @@@@r    r0   r0      s9    2

3;& ;H H H Kr#   c                 F   . pV P                  4        F  p\        P                  P                  V4      '       g   K*  R FZ  p\        P                  P	                  W#4      p\        P                  P                  V4      '       g   KI  VP                  V4       K\  	  K  	  V# )pythonx)r   python3)list_runtime_pathsr   r5   existsr   r3   )r   rvrtpsubdirr5   s   &    r    r   r     sq    	B&&(ww~~c"",F77<<,Dww~~d##		$ - ) Ir#   )r
   )&r   iologgingr   r   importlib.machineryr   typesr   
pynvim.apir   r   pynvim.msgpack_rpcr   pynvim.plugin.decoratorsr   r   pynvim.utilr	   __all__	getLoggerrh   loggerdebuginfowarningwarnr   r
   IOBaser:   intfloatr   r   r   r0   r   r   r#   r    <module>r      s    * 	  	 
 *  ! , 7 '
 
		8	$\\6;; tT a: a: a:H.RYY . %L	% %4n	r#   