+
    i[;  c                  sX   ^ RI Ht ^ RIt^ RI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 ^ RIHt ^ RIHt ^ RIHt R	t]'       d   ^ R
IHtHtHtHt RR.RR.RRR./tR R lt ! R R4      t ! R R4      t ! R R]4      t]! RR7       ! R R4      4       t ! R R4      t R# )     )annotationsN)
FileFinder)StringIO)contextmanager)	dataclass)chain)	TokenInfoF)AnyIterableIteratorMappingZcollectionsZabcospathzxml.parsers.expatZerrorsZmodelc                   V ^8  d   QhRR/# )   returnModuleCompleter Zformat   "2/usr/lib64/python3.14/_pyrepl/_module_completer.py__annotate__r      s     < < <    c                 s    \        R R/R7      # )__package__N)	namespace)r   r   r   r   make_default_module_completerr      s    mT%:;;r   c                  s    ] tR t^$tRtRR R lltR R ltR R ltR	 R
 ltR R lt	R R lt
R R ltR R ltR R ltR R ltR R lt]R R l4       tRtR# )r   a$  A completer for Python import statements.

Examples:
    - import <tab>
    - import foo<tab>
    - import foo.<tab>
    - import foo as bar, baz<tab>

    - from <tab>
    - from foo<tab>
    - from foo import <tab>
    - from foo import bar<tab>
    - from foo import (bar as baz, qux<tab>
Nc                    V ^8  d   QhRRRR/# )r   r   zMapping[str, Any] | Noner   Noner   r   r   r   r   ModuleCompleter.__annotate__4   s     C C": Cd Cr   c                	s    T;'       g    / V n         . V n        \        P                  R ,          V n        \
        P                  P                  \        P                  ^ ,          4      V n	        R# )NNNN)
r   _global_cachesysr   _curr_sys_pathr   Zdirname	importlibZ__path___stdlib_path)selfr      &&r   __init__ZModuleCompleter.__init__4   sG    "b79),!GGOOI,>,>q,ABr   c               r   )r   linestrr   zlist[str] | Noner   r   r   r   r   r   :   s     
 
C 
,< 
r   c                s    \        V4      P                  4       pV'       g   R#  V P                  ! V!  #   \         d    . u # i ; i)z7Return the next possible import completions for 'line'.N)ImportParserparsecomplete	Exception)r$   r'   Zresult   && r   get_completionsZModuleCompleter.get_completions:   sE    d#))+	==&)) 	 I	s   5 AAc               $    V ^8  d   QhRRRRRR/# )r   	from_name
str | Nonenamer   	list[str]r   r   r   r   r   r   F   s!     2 2* 2J 29 2r   c                	sd   VfK   Vf   Q hV P                  V4      w  r4V P                  W44      pV Uu. uF  q`P                  W64      NK  	  up# VfE   V P                  V4      w  r4V P                  W44      pV Uu. uF  q`P                  W64      NK  	  up# V P                  W4      # u upi u upi N)get_path_and_prefixfind_modulesformat_completion)r$   r0   r2   r   prefixmodulesmodule   &&&    r   r+   ZModuleCompleter.completeF   s    ###33D9LD''5GGNOwV**48wOO<33I>LD''5GGNOwV**48wOO   11 P Ps   B(;B-c               r/   r   r   r(   r8   r   r3   r   r   r   r   r   r   W   s!     > > >c >i >r   c                s    V P                  W4      pV Uu. uF  qDP                  4       '       g   K  VNK  	  up# u upi )z7Find all modules under 'path' that start with 'prefix'.)_find_modulesZisidentifier)r$   r   r8   r9   mods   &&&  r   r6   ZModuleCompleter.find_modulesW   s7    $$T2  '=w*:*:*<w===s   ;;c               r/   r<   r   r   r   r   r   r   ^   s&     ,B ,B# ,Bs ,By ,Br   c                	s  a  V'       g   \         P                   Uu. uF  pS P                  W24      '       g   K  VNK   	  ppS P                   Uu. uF3  pS P                  VP                  V4      '       g   K'  VP                  NK5  	  pp\        WF,           4      # VP                  R 4      '       d4   S P                  P                  RR4      pS P                  W4      pVf   . # S P                  p\         P                  P                  VP                  R 4      ^ ,          4      p	V	'       ds   V	P                  p
V
'       d]   V Uu. uFO  pVP                  V
P                  8X  g   K   VP                  P                  VP                  R4      V
8X  g   KM  VNKQ  	  ppM. pRpVP                  R 4       F  pV Uu. uF,  pVP                  '       g   K  VP                  V8X  g   K*  VNK.  	  ppVf;   \         ;QJ d    V 3R lV 4       F  '       d   K   RM	  RM! V 3R lV 4       4      pS P#                  V4      pK  	  V Uu. uF  qUP                  NK  	  ppV'       d&   VP%                  \&        P                  VR4      4       V Uu. uF  pS P                  VV4      '       g   K  VNK!  	  up# u upi u upi u upi u upi u upi u upi ).r    Nc              3  sF   <"   T F  pSP                  V4      x  K  	  R # 5ir4   )_is_stdlib_module).0mod_infor$   s   & r   	<genexpr>Z0ModuleCompleter._find_modules.<locals>.<genexpr>   s"      'ELD**844Ws   !FTr   )r    Zbuiltin_module_namesis_suggestion_matchglobal_cacher2   Zsorted
startswithr   Zgetresolve_relative_namer9   ZsplitZ__spec__module_finder	find_specispkgZalliter_submodulesZextendHARDCODED_SUBMODULES)r$   r   r8   r2   Zbuiltin_modulesr:   Zthird_party_modulespackager9   Zimported_modulespecr>   Zis_stdlib_importZsegmentrC   Zmodule_namesmodule_names   f&&              r   r=   ZModuleCompleter._find_modules^   s   030H0H J0H"&":":4"H  $t0HO J=A=N=N #U=N6&*&>&>v{{F&S $/6;;=N #U/?@@??3nn((;G--d<D|	040A0A++//$**S/!*<= #++D*1 T'3!hh$))3 "00::388TJdR 3' T (,zz#G07 GH"..  -5]]g-E  xG G'#&3 'EL'333 'EL' $  **73G ' 3::'': 4 8 8r BC/; B|++K@ | B 	BQJ#U$TG ;BsL   J5J5$J:9J:J?)(J?J?;KK'KK	K,Kc               r   )r   module_infozpkgutil.ModuleInfor   boolr   r   r   r   r   r      s     I I-? ID Ir   c                	s    \        VP                  \        4      ;'       d$    VP                  P                  V P                  8H  # r4   )Z
isinstancerI   r   r   r#   )r$   rQ   r%   r   rA   Z!ModuleCompleter._is_stdlib_module   s>    ;44jA H H--22d6G6GG	Ir   c               r/   )r   rP   r(   r8   r   rR   r   r   r   r   r   r      s!     / /s /C /D /r   c                	s`    V'       d   VP                  V4      # VP                  R 4      '       * # )Z_)rG   )r$   rP   r8      &&&r   rE   Z#ModuleCompleter.is_suggestion_match   s,    ))&11 ))#...r   c               r   )r   parent_moduleslist[pkgutil.ModuleInfo]r   zIterator[pkgutil.ModuleInfo]r   r   r   r   r   r      s     6 6.F 6Kg 6r   c                s   V Uu. uF<  q"P                   '       g   K  VP                  P                  VP                  R4      NK>  	  pp\	        \
        P                  ! R V 4       4      4      p\        P                  ! V4      # u upi )z8Iterate over all submodules of the given parent modules.Nc              3  sN   "   T F  q'       g   K  \        VR . 4      x  K  	  R# 5i)Zsubmodule_search_locationsN)Zgetattr)rB   rO      & r   rD   Z2ModuleCompleter.iter_submodules.<locals>.<genexpr>   s(      3
 <GD6;;s   	%%)	rK   rI   rJ   r2   Zsetr   Zfrom_iterablepkgutiliter_modules)r$   rT   ZinfoZspecsZsearch_locations   &&   r   rL   ZModuleCompleter.iter_submodules   s     ,;+Tzz ?##--dii>+ 	 ;u22 3
3
  
  ##$455;s
   B*Bc               r   )r   dotted_namer(   r   ztuple[str, str]r   r   r   r   r   r      s      s  r   c                s*   RV9  d   RV3# VP                  R4      '       d\   VP                  R4      pR\        V4      \        V4      ,
          ,          pRV9  d   W23# VP                  R^4      w  rEW4,           V3# VP                  R^4      w  rEWE3# )z
Split a dotted name into an import path and a
final prefix that is to be completed.

Examples:
    'foo.bar' -> 'foo', 'bar'
    'foo.' -> 'foo', ''
    '.foo' -> '.', 'foo'
r?   r@   )rG   Zlstriplenrsplit)r$   rZ   strippedZdotsr   r8   s   &&    r   r5   Z#ModuleCompleter.get_path_and_prefix   s     k!{?"!!#&&"))#.H#k*S]:;D("~%#??32LD;&&"))#q1|r   c               s$    V ^8  d   QhRRRRRR/# )r   r   r(   r:   r   r   r   r   r   r   r      s!     " "c "3 "3 "r   c                	sX    VR 8X  g   VP                  R4      '       d   V V 2# V RV 2# )r@   r?   )endswith)r$   r   r:   rS   r   r7   Z!ModuleCompleter.format_completion   s7    2:s++VF8$$q!!r   c               r/   )r   r2   r(   rN   r   r1   r   r   r   r   r   r      s!     2 2# 2 2
 2r   c                s    ^ pV F  pVR8w  d    MV^,          pK  	  VP                  RV^,
          4      p\        V4      V8  d   R# V^ ,          pWR pV'       d   V RV 2# T# )zpResolve a relative module name to an absolute name.

Example: resolve_relative_name('.foo', 'bar') -> 'bar.foo'
r?   N)r\   r[   )r$   r2   rN   ZlevelZ	characterZbitsZbaser;   r   rH   Z%ModuleCompleter.resolve_relative_name   sv     ICQJE  ~~c519-t9uAwF|#'$q1T1r   c               r   )r   r   rU   r   r   r   r   r   r      s     " "6 "r   c                s    V P                   '       d    V P                  \        P                  8w  d@   \        P                  R,          V n        \	        \
        P                  ! 4       4      V n         V P                   # )zGlobal module cacher   )r   r!   r    r   ZlistrW   rX   r$      &r   rF   ZModuleCompleter.global_cache   sS     !!!T%8%8CHH%D"%((1+D!%g&:&:&<!=D!!!r   )r!   r   r#   r   r4   )__name__
__module____qualname____firstlineno____doc__r&   r.   r+   r6   r=   rA   rE   rL   r5   r7   rH   ZpropertyrF   __static_attributes__r   r   r   r   r   $   sV    C
2">,B\I/6,"
2$ " "r   r   c                  s.   ] tR t^tRt]P                  ]P                  ]P                  ]P                  ]P                  ]P                  0t0 RmtR R ltR R ltR R ltR R	 ltR
 R ltR R ltR R ltR R ltR R ltR R ltR R ltRtR# )r)   aE  
Parses incomplete import statements that are
suitable for autocomplete suggestions.

Examples:
    - import foo          -> Result(from_name=None, name='foo')
    - import foo.         -> Result(from_name=None, name='foo.')
    - from foo            -> Result(from_name='foo', name=None)
    - from foo import bar -> Result(from_name='foo', name='bar')
    - from .foo import (  -> Result(from_name='.foo', name='')

Note that the parser works in reverse order, starting from the
last token in the input string. This makes the parser more robust
when parsing multiple statements.
c               r   )r   coder(   r   r   r   r   r   r   r   ImportParser.__annotate__   s     / /S /T /r   c                	s   Wn         . p \        P                  ! \        V4      P                  4       F1  pVP
                  V P                  9  g   K   VP                  V4       K3  	  \        VRRR1,          4      V n        R#   \        P                   d   pR \        T4      9  d   . p Rp?LHRp?i\         d    . p LZi ; i)zunexpected EOFN)rg   tokenizeZgenerate_tokensr   Zreadlinetype_ignored_tokensappendZ
TokenErrorr(   ZSyntaxError
TokenQueuetokens)r$   rg   ro   ZtZerY   r   r&   ZImportParser.__init__   s    		--htn.E.EF66!5!55MM!$ G !". "" 	s1v-
  	F	s*   AB B CB00C=CCc               r   )r   r   z$tuple[str | None, str | None] | Noner   r   r   r   r   rh      s     ' '; 'r   c                	sf    V P                  4       ;p'       g   R # VP                  VP                  3# r4   )_parser0   r2   )r$   ZresrV   r   r*   ZImportParser.parse   s)    {{}$$}}chh&&r   c               r   )r   r   zResult | Noner   r   r   r   r   rh     s     ' ' 'r   c                	sD   V P                   P                  4       ;_uu_ 4        V P                  4       uuR R R 4       #   + '       g   i     M; iT P                   P                  4       ;_uu_ 4        T P                  4       uuR R R 4       #   + '       g   i     R # ; ir4   )ro   
save_stateparse_from_importparse_importr_   r`   r   rp   ZImportParser._parse  s^    [[##%%))+ &%%%[[##%%$$& &%%%s   >A	3BB	c               r   r   r   Resultr   r   r   r   r   rh   
  s     ) )f )r   c                	s   V P                   P                  4       P                  R 4      '       d.   V P                   P                  R4      '       d   \        RR7      # V P                  P                  R4      '       d   RpM<V P                   P                  R4      '       d   \        R4      hV P                  4       pVP                  R4      '       d   \        R4      hV P                  P                  R4      '       d-   V P                  P                  4        V P                  4        KM  V P                  P                  R 4      '       d   \        VR7      # \        R4      h)import r@   )r2   ,rs   r?   )rg   rstripr^   ru   ro   peek_string
ParseErrorparse_dotted_namerG   popparse_dotted_as_name)r$   r2   rV   r   rs   ZImportParser.parse_import
  s    99&&x00TYY5G5G5L5Lr?";;""3''Dyy!!#&& 00))+D??3^,,kk%%c**KKOO%%';;""8,,t$$((r   c               r   rt   r   r   r   r   r   rh     s     6 66 6r   c                	s   V P                   P                  4       pVP                  R 4      '       d=   V P                   P                  R4      '       d   \        V P	                  4       RR7      # VP                  R4      '       d.   V P                   P                  R4      '       d   \        RR7      # V P
                  P                  R4      '       g"   V P
                  P                  R4      '       d   \        V P	                  4       RR7      # V P                   P                  R4      '       d   \        R4      hV P                  4       pR	V9   d(   V P
                  P                  R4       \        VR7      # V P
                  P                  R4      '       d   \        VR7      # V P	                  4       p\        W2R7      # )
rv   rw   r@   )r0   r2   from)r0   (rx   rr   r?   )
rg   ry   r^   ru   parse_empty_from_importro   rz   r{   r|   
pop_string)r$   r]   r2   r0   s   &   r   rr   ZImportParser.parse_from_import  sJ   99##%X&&499+=+=c+B+BD$@$@$BLLV$$););C)@)@B'';;""3''4;;+B+B3+G+GD$@$@$BLL99c""011%%'$;KK""6*D));;""6**D))002		55r   c               r   r   r   r(   r   r   r   r   r   rh   /  s     ! ! !r   c                	sd   V P                   P                  R 4      '       d+   V P                   P                  4        V P                  4        V P                   P                  R4      '       d   V P                   P                  4        V P                   P	                  R4       V P                  4       # )rx   r   rv   )ro   rz   r}   parse_as_namesr   
parse_fromr_   r`   r   r   Z$ImportParser.parse_empty_from_import/  ss    ;;""3''KKOO!;;""3''KKOOx(  r   c               r   r   r   r   r   r   r   rh   8  s      C r   c                	s\    V P                  4       pV P                  P                  R 4       V# )r   )r|   ro   r   )r$   r0   rV   r   r   ZImportParser.parse_from8  s(    **,	v&r   c               r   r   r   r   r   r   r   rh   =  s     , ,c ,r   c                	sN   V P                   P                  4        V P                   P                  R 4      '       d   V P                   P                  4        V P                   P	                  4       ;_uu_ 4        V P                  4       uuRRR4       #   + '       g   i     R# ; iasN)ro   pop_namerz   r}   rq   r|   r_   r`   r   r~   Z!ImportParser.parse_dotted_as_name=  sc    ;;""4((KKOO[[##%%))+ &%%%s   8BB$	c               r   r   r   r   r   r   r   rh   D  s     # #3 #r   c                	sL   . pV P                   P                  R 4      '       d,   VP                  R 4       V P                   P                  4        V P                   P	                  4       '       dg   V P                   P                  4       ;p'       dE   VP                  V P                  9  d*   VP                  V P                   P                  4       4       V'       g   \        R4      hV P                   P                  R 4      '       d   VP                  R 4       V P                   P                  4        V P                   P	                  4       '       di   V P                   P                  4       ;p'       dG   VP                  V P                  9  d,   VP                  V P                   P                  4       4       K   V P                   P                  R 4      '       d.   VP                  R 4       V P                   P                  4        KN  RP                  VRRR1,          4      # )r?   r|   r@   Nri   )ro   rz   rm   r}   	peek_namepeekstring	_keywordsr   r{   Zjoin)r$   r2   toks   &  r   r|   ZImportParser.parse_dotted_nameD  se   ;;""3''KKKKOOKK!!##((***

$..0KK,,./011kk%%c**KKKKOO%%'' KK,,..S.JJdnn4DKK0023kk%%c**KKKKOOwwtDbDz""r   c               r   r   r   r   r   r   r   r   r   rh   ^  s     ! ! !r   c                	s    V P                  4        V P                  P                  R 4      '       d-   V P                  P                  4        V P                  4        KM  R# )rx   N)parse_as_namero   rz   r}   r_   r`   r   r   ZImportParser.parse_as_names^  sB    kk%%c**KKOO  +r   c               r   r   r   r   r   r   r   rh   d  s     # #t #r   c                	s    V P                   P                  4        V P                   P                  R 4      '       d7   V P                   P                  4        V P                   P                  4        R# R# r   )ro   r   rz   r}   r_   r`   r   r   ZImportParser.parse_as_named  sJ    ;;""4((KKOOKK  " )r   )rg   ro   N>   r   r   rv   )ra   rb   rc   rd   re   tokenZINDENTZDEDENTZCOMMENTZNLZNEWLINEZ	ENDMARKERrl   r   r&   r*   rp   rs   rr   r   r   r~   r|   r   r   rf   r   r   r   r)   r)      sy      	ellEMM%--O )I/$'
')$6&!
,#4!# #r   r)   c                  s    ] tR tRtRtR# )r{   ik  r   N)ra   rb   rc   rd   rf   r   r   r   r{   r{   k  s    r   r{   T)Zfrozenc                  s4    ] tR tRt$ RtR]R&   RtR]R&   RtR# )ru   io  Nr1   r0   r2   r   )ra   rb   rc   rd   r0   Z__annotations__r2   rf   r   r   r   ru   ru   o  s     Iz D*r   ru   c                  s    ] tR tRtRtR R lt]R R l4       tR R ltR	 R
 lt	R R lt
R R ltR R ltR R ltR R ltRtR# )rn   iu  z@Provides helper functions for working with a sequence of tokens.c               r   )r   ro   zlist[TokenInfo]r   r   r   r   r   r   r   TokenQueue.__annotate__x  s     # # #4 #r   c                	s.    Wn         ^ V n        . V n        R# )r    N)ro   indexstack)r$   ro   r%   r   r&   ZTokenQueue.__init__x  s    '-
 "
r   c               r   )r   r   r   r   r   r   r   r   r   ~  s      C r   c              #  	s   "    V P                   P                  V P                  4       R x  V P                   P                  4        R #   \         d$    T P                   P                  4       T n         R # i ; i5ir4   )r   rm   r   r}   r{   r_   r`   r   rq   ZTokenQueue.save_state}  sU     	JJdjj) JJNN  	*)DJ	*s'   A:)A	 A:	*A73A:6A77A:c               r   r   r   rR   r   r   r   r   r   r     s     - -$ -r   c                	sF    V P                   \        V P                  4      8  # r4   )r   r[   ro   r_   r`   r   __bool__ZTokenQueue.__bool__  s    zzC,,,r   c               r   )r   r   zTokenInfo | Noner   r   r   r   r   r     s     ' '& 'r   c                	sP    V '       g   R # V P                   V P                  ,          # r4   )ro   r   r_   r`   r   r   ZTokenQueue.peek  s    {{4::&&r   c               r   r   r   r   r   r   r   r     s     & &4 &r   c                	sp    V P                  4       ;p'       g   R # VP                  \        P                  8H  # F)r   rk   r   NAMEr$   r   rV   r   r   ZTokenQueue.peek_name  s)    yy{""xx5::%%r   c               r   r   r   r   r   r   r   r     s      # r   c                	s    V P                  4       pVP                  \        P                  8w  d   \	        R 4      hVP
                  # )r   )r}   rk   r   r   r{   r   r   rV   r   r   ZTokenQueue.pop_name  s2    hhj88uzz!Z((zzr   c               r   )r   r   r(   r   rR   r   r   r   r   r   r     s     $ $# $$ $r   c                	sT    V P                  4       ;p'       g   R # VP                  V8H  # r   )r   r   r$   r   r   r-   r   rz   ZTokenQueue.peek_string  s%    yy{""zzV##r   c               s     V ^8  d   QhRRRR/# )r   r   r(   r   r   r   r   r   r   r     s        r   c                	sr    V P                  4       pVP                  V8w  d   \        R 4      hVP                  # )r   )r}   r   r{   r   r-   r   r   ZTokenQueue.pop_string  s.    hhj::\**zzr   c               r   )r   r   r   r   r   r   r   r   r     s      Y r   c                	s    V '       g   \        R 4      hV P                  V P                  ,          pV ;P                  ^,          un        V# )r}   )r{   ro   r   r   rV   r   r}   ZTokenQueue.pop  s4    U##kk$**%

a

r   )r   r   ro   N)ra   rb   rc   rd   re   r&   r   rq   r   r   r   r   rz   r   r}   rf   r   r   r   rn   rn   u  sF    J#
  -'
&
$
 r   rn   )!Z
__future__r   r"   r   rW   r    r   rj   Zimportlib.machineryr   Zior   Z
contextlibr   Zdataclassesr   Z	itertoolsr   r   ZTYPE_CHECKINGZtypingr   r	   r
   r   rM   r   r   r)   r,   r{   ru   rn   r   r   r   <module>r      s    "  	  
   *  % !  77 E76((G, <
p" p"fQ# Q#h	 	 $  
5 5r   