
    ^hM0                        S r SSKrSSKrSSKrSSKrSSKrSSKJr  SSKJ	r	  SSK
J
r
  SSKJr  SSKJrJr  SS	KJr  S
SKJr  SSKJr  SSKJr  \	" 5       rS
rSr\R6                  " SSR9                  S \ 5       5      -  5      r\R6                  " S5      rS rS r S r!S r"S S\#S\\#   4S jjr$S r%S r&S r'S r(S r)S r*g)!z\Implementations for various useful completers.

These are all loaded by default by IPython.
    N)import_module)all_suffixes)time)zipimporter   )expand_usercompress_user)TryNext   )	arg_split)get_ipython)List   z?(?P<name>[^\W\d]\w*?)(?P<package>[/\\]__init__)?(?P<suffix>%s)$|c              #   N   #    U  H  n[         R                  " U5      v   M     g 7fN)reescape).0ss     S/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/completerlib.py	<genexpr>r   :   s      Ay!1ys   #%z.*(\.ipy|\.ipynb|\.py[w]?)$c                   ^^	 U S:X  a  Sn [         R                  R                  m[         R                  R                  U 5      (       an  / n[         R                  " U SS9 HR  u  p#nU[        U 5      S-   S m	T	(       a#  UR                  UU	4S jU 5       5        / USS& MA  UR                  U5        MT     O- [        [        U 5      R                  R                  5       5      n/ nU HA  n[        R                  U5      nU(       d  M!  UR                  UR                  S5      5        MC     [        [        U5      5      $ !   / n Nc= f)	zT
Return the list containing the names of the modules available in the given
folder.
 .T)followlinksr   Nc              3   6   >#    U  H  nT" TU5      v   M     g 7fr    )r   fpjoinsubdirs     r   r   module_list.<locals>.<genexpr>W   s     ?w!U61--ws   name)ospathjoinisdirwalklenextendlistr   _fileskeys	import_rematchappendgroupset)
r%   filesrootdirsnondirsmodulesr   mr    r!   s
           @@r   module_listr9   C   s    rz GGLLE	ww}}T #%774T#BD#d)A+,'F?w??QW% $C	T*116689E
 GOOA1NN1776?+  G	Es   8,E Ec                  >   [        5       n U c  [        [        R                  5      $ [	        U R
                  SS5      (       a  0 nOU R
                  R                  S0 5      n[        [        R                  5      n[        5       nSn[        R                   H  n X   nUR%                  U5        M     U(       a  XR
                  S'   [        ['        U5      5      nU$ ! [         a    [        U5      n UR                  S5        O! [         a     Of = fUS;  a  XaU'   [        5       U-
  [        :  a=  U(       d6  Sn[        S5        [        S5        [        R                  R!                  5         [        5       U-
  ["        :  a  [        S	5        / s s  $  Nf = f)
z
Returns a list containing the names of all the modules available in the
folders of the pythonpath.

ip.db['rootmodules_cache'] maps sys.path entries to list of modules.
_mockFrootmodules_cache__init__)r   r   Tz/
Caching the list of root modules, please wait!z@(This will only be done once - type '%rehashx' to reset cache!)
z%This is taking too long, we give up.
)r   r+   sysbuiltin_module_namesgetattrdbgetr   r%   KeyErrorr9   remove
ValueErrorTIMEOUT_STORAGEprintstdoutflushTIMEOUT_GIVEUPr*   r2   )ipr<   rootmodules
start_timestorer%   r7   s          r   get_root_modulesrO   k   sl    
B	z C,,--ruugu%%EEII&92>s//0KJE	'-G$ 	7#) * %6!"s;'(K+  	!$'Gz* 9$*1$'v
"_4UHI ( )

  "v
"^3>?	 4	s7   CF5DF
DFDBFFc                     U(       a  [         R                  " [        X5      5      $ US S S:H  =(       a    USS  S:H  (       + $ )Nr   __)inspectismoduler@   )moduleattronly_moduless      r   is_importablerX      s?     5668t#9RS	T(9::    c                 |     [        X5      n[        R                  " U5      $ ! [         a     g[         a     gf = f)NTF)r@   AttributeError	TypeErrorrS   rT   )rU   rV   objs      r   is_possible_submoduler^      sC    f# C     s   # 
;	;;modreturnc           
        ^	 U R                  S5      n  [        U 5      m	S[        T	SS5      =(       d    S;   n/ n[        T	S5      (       a  U(       a  U(       a>  UR	                  [        T	5       Vs/ s H  n[        T	XA5      (       d  M  UPM     sn5        [        T	S/ 5      nU(       a  UR	                  U	4S jU 5       5        OUR	                  U5        U(       aC  T	R                  nUR	                  [        [        R                  R                  U5      5      5        U Vs1 s H  n[        U[        5      (       d  M  UiM     nnUR                  S5        [        U5      $ !   / s $ = fs  snf s  snf )zF
Try to import given module and return list of potential completions.
r   r=   __file__r   __all__c              3   N   >#    U  H  n[        TU5      (       d  M  Uv   M     g 7fr   )r^   )r   rV   r8   s     r   r   try_import.<locals>.<genexpr>   s     TED5J1d5S44Es   %	%)rstripr   r@   hasattrr*   dirrX   rb   r9   r$   r%   dirname
isinstancestrdiscardr+   )
r_   rW   	m_is_initcompletionsrV   m_allfile_ccompletions_setr8   s
            @r   
try_importrs      s6    **S/C# wq*b9?R@IKAz""LYc!f Cfd*1dA "f C 	D Ay"%ETETT5!

;rwwu'=>?"-D+QAs1Cq+ODJ'  +	C Es#   E' 1E0
E0&E5E5'E-c                    ^ [        T[        5      (       a  TR                  5       mU4S jn[        5       R	                  SX S9  g)a\  Easily create a trivial completer for a command.

Takes either a list of completions, or all completions in string (that will
be split on whitespace).

Example::

    [d:\ipython]|1> import ipy_completers
    [d:\ipython]|2> ipy_completers.quick_completer('foo', ['bar','baz'])
    [d:\ipython]|3> foo b<TAB>
    bar baz
    [d:\ipython]|3> foo ba
c                    > T$ r   r   )selfeventrn   s     r   do_complete$quick_completer.<locals>.do_complete   s	    rY   complete_command)str_keyN)rj   rk   splitr   set_hook)cmdrn   rx   s    ` r   quick_completerr      s=     +s##!'') M-kIrY   c                    U R                  S5      n[        U5      nUS:X  a  US   S:X  a  S/$ US:  a  US   S;   a  US:X  a
  [        5       $ US   R                  S5      n[        U5      S	:  a
  [        5       $ [        SR	                  US
S 5      S5      nU Vs/ s H  nSR	                  US
S U/-   5      PM     sn$ US:  a  US   S:X  a  US   n[        U5      $ g
g
s  snf )z
Returns a list containing the completion possibilities for an import line.

The line looks like this :
'import xml.d'
'from xml.dom import'
    r   fromzimport >   r   import%aimportr   r   r   NT)r|   r)   rO   rs   r&   )linewordsnwordsr_   completion_listels         r   module_completionr      s     JJsOEZF {uQx6){ zuQx#AAQ;#%%AhnnS!s8a<#%%$SXXc#2h%7>4CDObSbRD)ODD {uQx6)Ah# *{ Es   "C#c                 ,    [        UR                  5      $ )z@Give completions after user has typed 'import ...' or 'from ...')r   r   rv   rw   s     r   module_completerr     s     UZZ((rY   c                 P   [        UR                  SS9n[        U5      S:  a5  UR                  R                  S5      (       d  US   R	                  S5      nOSn[
        R
                  n[        R                  R                  n[        U5      u  p6n[        S U 5       5      (       a>  U" US	-   5       Vs/ s H'  nUR                  S
S5      U" U5      (       a  SOS-   PM)     n	nOU" US	-   5       Vs/ s H&  o" U5      (       d  M  UR                  S
S5      S-   PM(     n
nU" US-   5      U" US-   5      -   U" US-   5      -   U" US-   5      -    Vs/ s H  nUR                  S
S5      PM     nnX-   n	U	 Vs/ s H  n[        XU5      PM     sn$ s  snf s  snf s  snf s  snf )zKComplete files that end in .py or .ipy or .ipynb for the %run command.
    F)strictr   r   r   z'"r   c              3   L   #    U  H  n[         R                  U5      v   M     g 7fr   )magic_run_rer/   )r   rq   s     r   r   &magic_run_completer.<locals>.<genexpr>/  s     
0%Q<a  %s   "$*\/z*.pyz*.ipyz*.ipynbz*.pyw)r   r   r)   endswithstripglobr$   r%   r'   r   anyreplacer	   )rv   rw   compsrelpathlglobr'   tilde_expand	tilde_valr   matchesr5   pysps                r   magic_run_completerr     s    ejj/EE
Q!4!4S!9!9)//%( IIEGGMME'27';$G9 
0%
000%*73;%79%7 IId3'%((3C%7 	 9 493ER3Eaq)		$s#c)3ERwv~.ww1GGgi'()+071B+CDEDA 		$s#D 	 E * @GGw!M!95wGG9 SE Hs   7.F5F	FF;F#c           
         [        5       nUR                  nUR                  R                  S5      (       d  SUR                  ;   a5  U R                  R                  SS5      nU(       a  UR                  5       $ / $ UR                  S:X  a  [        [        [        [        UR                  S   5      S-   5      5      5      nSU-   S	-   n[        UR                  S   5       VVs/ s H  u  pxXgU4-  PM     n	nn[        U	5      S:  a  U	$ / $ UR                  R                  S
5      (       a@  UR                  S    V
s/ s H%  n
S
[        R                  R                  U
5      -   PM'     sn
$ [        U5      u  p;nUR!                  SS5      n/ n["        R"                  " US-   5       Vs/ s H>  n[        R                  R%                  U5      (       d  M)  UR!                  SS5      S-   PM@     sn H   n
SU
;   a  [&        eUR)                  U
5        M"     U(       d  [        R                  R%                  U5      (       a  [+        X;U5      /$ U R                  R                  S0 5      nU Vs/ s H&  oR                  UR                  5      (       d  M$  UPM(     nnU(       a  U$ [&        eU Vs/ s H  n[+        UX5      PM     sn$ s  snnf s  sn
f s  snf s  snf s  snf )z:Completer function for cd, which only returns directories.z-bz -b 	bookmarksN-_dhr   z-%0zd [%s]z--r   r   r   r   )r   symbolr   r   rA   rB   r-   rk   r)   user_ns	enumerate
startswithr$   r%   basenamer   r   r   r'   r
   r0   r	   )rv   rw   rK   r   bkmswidth_dhfmtir   entsdr   r   foundr   bks	bkmatchesr   s                     r   cd_completerr   >  s_   	BllG zz4  Fejj$8ww{{;-99;I||ss3s2::e#459:;<h((1"**U2C(DE(D!u(DEt9q=K	||t$$46JJu4EF4Eqrww''**4EFF (37';$G9ood3'GE1573;1G #1GAq! (aiiS!C'1G #!8 MQ# 77==!!!'CDD ggkk+b) #B1||ELL'AQ	B?DEu!M!\5uEEE F G# C Fs*   %K	>,K*(KK.#KK0Kc                 "    SR                  5       $ )zA completer for %reset magicz-f -s in out array dhist)r|   r   s     r   reset_completerr   t  s    %++--rY   )F)+__doc__r   rS   r$   r   r>   	importlibr   importlib.machineryr   r   	zipimportr   	completerr   r	   errorr
   utils._process_commonr   IPythonr   typingr   	_suffixesrF   rJ   compiler&   r.   r   r9   rO   rX   r^   rk   rs   r   r   r   r   r   r   r   rY   r   <module>r      s   "   	 	 
 # ,  ! 2  -   
 N	   JJ * yy Ay AAB C	 zz89%P,^;	!!C !S	 !FJ.J	)"HJ4Fl.rY   