
    Zg              
       (   S r SSKrSSKrSSKJrJr  SSKJrJrJ	r	J
r
JrJrJrJrJrJr  SSKJr  \R&                  S:  a	  SSKJrJr  OSSKJrJr  SSKJr  S	r\" S
5      r\\S   \4   r " S S\5      r " S S\5      r " S S\5      r  " S S5      r!\" S\S9r"S\"S\\"\#4   4S jr$ " S S5      r% " S S\	\   5      r&\S'S\'S\S\4S jj5       r(\S'S\S\S\\\4   4S  jj5       r(S'S\S\S\\\4   4S! jjr(S"\S#\4   S\S$\S%\S\4
S& jr)g)(z$Code shared between the API classes.    N)ABCabstractmethod)
AnyCallableGenericIteratorListOptionalTupleTypeVarUnionoverload)unpackb)      )LiteralProtocol)unicode_errors_default TTc                       \ rS rSrSrg)	NvimError   r   N)__name__
__module____qualname____firstlineno____static_attributes__r       3/usr/lib/python3/dist-packages/pynvim/api/common.pyr   r      s    r   r   c                   .    \ rS rSrS\S\S\S\4S jrSrg)	IRemote   nameargskwargsreturnc                     [         eNNotImplementedErrorselfr$   r%   r&   s       r    requestIRemote.request   s    !!r   r   N)r   r   r   r   strr   r.   r   r   r   r    r"   r"      s#    "C " "s "s "r   r"   c                       \ rS rSrSrS\S\\\4   4S jr	\
\S\4S j5       5       rS\4S jrS	\S\4S
 jrS\4S jrS\S\S\S\4S jrSrg)Remote    zBase class for Nvim objects(buffer/window/tabpage).

Each type of object has it's own specialized class with API wrappers around
the msgpack-rpc session. This implements equality which takes the remote
object handle into consideration.
session	code_datac                 >   Xl         X l        [        US   5      U l        [	        X R
                  5      U l        [        X R
                  S-   U R
                  S-   U R
                  S-   5      U l        [        X R
                  S-   U R
                  S-   5      U l	        g)zInitialize from session and code_data immutable object.

The `code_data` contains serialization information required for
msgpack-rpc calls. It must be immutable for Buffer equality to work.
   get_varset_vardel_var
get_option
set_optionN)
_sessionr5   r   handle	RemoteApi_api_prefixapi	RemoteMapvarsoptions)r-   r4   r5   s      r    __init__Remote.__init__)   s      "il+T#3#34d$4$4y$@"..:"..:<	 !'7'7,'F!%!1!1L!@Br   r'   c                     [        5       er)   r*   r-   s    r    r@   Remote._api_prefix9   s     "##r   c                 T    SU R                   R                  < SU R                  < S3$ )z&Get text representation of the object.<z(handle=z)>)	__class__r   r>   rH   s    r    __repr__Remote.__repr__>   s"     NN##KK
 	
r   otherc                 Z    [        US5      =(       a    UR                  U R                  :H  $ )z6Return True if `self` and `other` are the same object.r5   )hasattrr5   )r-   rO   s     r    __eq__Remote.__eq__E   s&    {+ 6OOt~~5	7r   c                 6    U R                   R                  5       $ )z&Return hash based on remote object id.)r5   __hash__rH   s    r    rU   Remote.__hash__J   s    ~~&&((r   r$   r%   r&   c                 B    U R                   R                  " X/UQ70 UD6$ )zWrapper for nvim.request.)r=   r.   r,   s       r    r.   Remote.requestN   s!    }}$$TA$A&AAr   )r=   rA   r5   r>   rD   rC   N)r   r   r   r   __doc__r"   r   intr   rE   propertyr   r0   r@   rM   boolrR   rU   r.   r   r   r   r    r2   r2       s    B BE#s(O B  $S $  $
# 
7C 7D 7
)# )BC B Bs Bs Br   r2   c                   F    \ rS rSrSrS\S\4S jrS\S\S\	4   4S	 jr
S
rg)r?   S   z>Wrapper to allow api methods to be called like python methods.obj
api_prefixc                     Xl         X l        g)z2Initialize a RemoteApi with object and api prefix.N)_objr@   )r-   r_   r`   s      r    rE   RemoteApi.__init__V   s    	%r   r$   r'   .c                 r    [         R                  " U R                  R                  U R                  U-   5      $ )z#Return wrapper to named api method.)	functoolspartialrb   r.   r@   )r-   r$   s     r    __getattr__RemoteApi.__getattr__[   s*      !2!2D4D4Dt4KLLr   )r@   rb   N)r   r   r   r   rY   r"   r0   rE   r   r   rg   r   r   r   r    r?   r?   S   s7    H&G & &
M Mc(: Mr   r?   E)boundexcr'   c                    [        U [        5      (       av  U R                  S   R                  S5      (       a  [	        U R                  S   5      $ U R                  S   R                  S5      (       a  [	        U R                  S   5      $ U $ )Nr   zKey not found:zInvalid option name:)
isinstancer   r%   
startswithKeyError)rk   s    r    transform_keyerrorrp   c   sn    #y!!88A;!!"233CHHQK((88A;!!"899CHHQK((Jr   c            
          \ rS rSrSrSrSr  SS\S\S\	\   S\	\   4S jjr
S	\S
\4S jrS	\S\S
S4S jrS	\S
S4S jrS	\S
\4S jr\S	\S\S
\4S j5       r\SS	\S\	\   S
\	\   4S jj5       rSS	\S\	\   S
\	\   4S jjrSrg)rB   l   a"  Represents a string->object map stored in Nvim.

This is the dict counterpart to the `RemoteSequence` class, but it is used
as a generic way of retrieving values from the various map-like data
structures present in Nvim.

It is used to provide a dict-like API to vim variables and options.
Nr_   
get_method
set_method
del_methodc                    [         R                  " UR                  U5      U l        U(       a&  [         R                  " UR                  U5      U l        U(       a'  [         R                  " UR                  U5      U l        gg)z3Initialize a RemoteMap with session, getter/setter.N)re   rf   r.   _get_set_del)r-   r_   rs   rt   ru   s        r    rE   RemoteMap.__init__y   sW     %%ckk:>	!))#++zBDI!))#++zBDI r   keyr'   c                 `     U R                  U5      $ ! [         a  n[        U5      eSnAff = f)zReturn a map value by key.N)rw   r   rp   r-   r{   rk   s      r    __getitem__RemoteMap.__getitem__   s0    	*99S>! 	*$S))	*s    
-(-valuec                 ^    U R                   (       d  [        S5      eU R                  X5        g)z3Set a map value by key(if the setter was provided).This dict is read-onlyN)rx   	TypeError)r-   r{   r   s      r    __setitem__RemoteMap.__setitem__   s!    yy455		#r   c                     U R                   (       d  [        S5      e U R                  U5      $ ! [         a  n[        U5      eSnAff = f)z4Delete a map value by associating None with the key.r   N)ry   r   r   rp   r}   s      r    __delitem__RemoteMap.__delitem__   sC    yy455	*99S>! 	*$S))	*s   / 
A	AA	c                 H     U R                  U5        g! [         a     gf = f)z#Check if key is present in the map.TF)rw   	Exception)r-   r{   s     r    __contains__RemoteMap.__contains__   s'    	IIcN 		s    
!!defaultc                     g r)   r   r-   r{   r   s      r    getRemoteMap.get   s    .1r   c                     g r)   r   r   s      r    r   r      s    ILr   c                 J     U R                  U5      $ ! [         a    Us $ f = f)z6Return value for key if present, else a default value.)r~   ro   r   s      r    r   r      s,    	##C(( 	N	s    "")ry   rw   rx   )NNr)   )r   r   r   r   rY   rx   ry   r"   r0   r
   rE   r   r~   r   r   r\   r   r   r   r   r   r   r   r    rB   rB   l   s    DD %)$(CC C SM	C
 SMC*s *s *s 3 4 *s *t *   1s1Q111 1LsLXa[LHQKL Ls Xa[ HQK  r   rB   c                       \ rS rSrSrS\S\4S jrS\4S jr	\
S\S\4S	 j5       r\
S\S\\   4S
 j5       rS\\\4   S\\\\   4   4S jrS\\   4S jrS\S\4S jrSrg)RemoteSequence   ad  Represents a sequence of objects stored in Nvim.

This class is used to wrap msgpack-rpc functions that work on Nvim
sequences(of lines, buffers, windows and tabpages) with an API that
is similar to the one provided by the python-vim interface.

For example, the 'windows' property of the `Nvim` class is a RemoteSequence
sequence instance, and the expression `nvim.windows[0]` is translated to
session.request('nvim_list_wins')[0].

One important detail about this class is that all methods will fetch the
sequence into a list and perform the necessary manipulation
locally(iteration, indexing, counting, etc).
r4   methodc                 P    [         R                  " UR                  U5      U l        g)z1Initialize a RemoteSequence with session, method.N)re   rf   r.   _fetch)r-   r4   r   s      r    rE   RemoteSequence.__init__   s    ''@r   r'   c                 4    [        U R                  5       5      $ )z)Return the length of the remote sequence.)lenr   rH   s    r    __len__RemoteSequence.__len__   s    4;;=!!r   idxc                     g r)   r   r-   r   s     r    r~   RemoteSequence.__getitem__   s    *-r   c                     g r)   r   r   s     r    r~   r      s    25r   c                     [        U[        5      (       d  U R                  5       U   $ U R                  5       UR                  UR                   $ )z Return a sequence item by index.)rm   slicer   startstopr   s     r    r~   r      s;    #u%%;;=%%{{}SYYsxx00r   c              #   F   #    U R                  5       nU H  nUv   M	     g7f)z$Return an iterator for the sequence.Nr   )r-   itemsitems      r    __iter__RemoteSequence.__iter__   s     DJ s   !r   c                 &    XR                  5       ;   $ )z,Check if an item is present in the sequence.r   )r-   r   s     r    r   RemoteSequence.__contains__   s    {{}$$r   r   N)r   r   r   r   rY   r"   r0   rE   rZ   r   r   r   r~   r   r	   r   r   r   r\   r   r   r   r   r    r   r      s    A A A" " -s-q- -5u5a5 51uUCZ0 1U1d1g:5F 1(1+ % %t %r   r   r_   modec                     g r)   r   r_   r   s     r    decode_if_bytesr      s    BEr   c                     g r)   r   r   s     r    r   r      s    HKr   c                 f    USL a  [         n[        U [        5      (       a  U R                  SUS9$ U $ )zDecode obj if it is bytes.Tzutf-8)errors)r   rm   bytesdecoder   s     r    r   r      s3    t|%#uzz'$z//Jr   fn.r%   r&   c                    ^ ^ [        U5      [        [        4;   a  [        UU 4S jU 5       5      $ [        U5      [        L a$  [        UU 4S jUR	                  5        5       5      $ T " U/TQ70 UD6$ )zARecursively walk an object graph applying `fn`/`args` to objects.c              3   >   >#    U  H  n[        TU/TQ76 v   M     g 7fr)   walk).0or%   r   s     r    	<genexpr>walk.<locals>.<genexpr>   s     41DQ&&s   c              3   \   >#    U  H!  u  p[        TU/TQ76 [        TU/TQ76 4v   M#     g 7fr)   r   )r   kvr%   r   s      r    r   r      s9      ! BFT"a'$'b!);d);<s   ),)typelisttupledictr   )r   r_   r%   r&   s   ` ` r    r   r      se    CyT5M!4444CyD !IIK! ! 	!c#D#F##r   )T)*rY   re   sysabcr   r   typingr   r   r   r   r	   r
   r   r   r   r   msgpackr   version_infotyping_extensionsr   r   pynvim.compatr   __all__r   r0   TDecodeModer   r   r"   r2   r?   ri   ro   rp   rB   r   r   r   r   r   r   r    <module>r      sv   *  
 #% % % f33( 0
 CLGDM3&'		 	"h "
0BS 0Bf
M 
M Cy!A %8"4 D DN-%WQZ -%` 
 E Ek ES E 
 E 
 K K+ Kq#v K 
 K + q#v $Xc3h $c $# $ $ $r   