Format: application/x-python-code
⬇ Download File (9.2 KB)
   1  o
   2  
   3  ��ha1�@sVdZddlZddlZddlZddlZddlZddlmZddlm	Z	ddl
   4  m
   5  Z
   6  ddlmZddl
   7  mZmZdd	lmZd
   8  dlmZddlmZdd
   9  lmZe	�Zd
  10  ZdZe�dd�dd�eD���Ze�d�Zdedeefdd�Z dd�Z!dede"fdd�Z#dd�Z$d/d edeefd!d"�Z%d#d$�Z&d%d&�Z'd'd(�Z(d)d*�Z)d+d,�Z*d-d.�Z+dS)0z\Implementations for various useful completers.
  11  
  12  These are all loaded by default by IPython.
  13  �N)�
  14  import_module)�all_suffixes)�time)�zipimporter�)�expand_user�
  15  compress_user)�TryNext�)�	arg_split)�get_ipython)�List�z?(?P<name>[^\W\d]\w*?)(?P<package>[/\\]__init__)?(?P<suffix>%s)$�|cc��|]}t�|�VqdS�N)�re�escape��.0�s�r�Oc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/completerlib.py�	<genexpr>:��rz.*(\.ipy|\.ipynb|\.py[w]?)$�path�returncs�|dkrd}tjj�tj�|�rEg}tj|dd�D]*\}}}|t|�dd���r>|���fdd�|D��g|dd�<q|�|�qnztt|�j	�
  16  ��}Wnty[g}Ynwg}|D]}t�
  17  |�}|rq|�|�d	��q`tt|��S)
  18  z`
  19      Return the list containing the names of the modules available in the given
  20      folder.
  21      ��.T)�followlinksrNc3s�|]}��|�VqdSrr�r�f��pjoin�subdirrrrXrzmodule_list.<locals>.<genexpr>�name)�osr�join�isdir�walk�len�extend�listr�_files�keys�	Exception�	import_re�match�append�group�set)r�files�root�dirs�nondirs�modulesr!�mrr"r�module_listDs0�	�
  22  �r;cCs.t�}|durttj�St|jdd�ri}n|j�di�}ttj�}t�}d}tjD]]}z||}WnOt	y�t
  23  |�}z|�d�Wn	tyMYnw|dvrV|||<t�|t
  24  krn|snd}td�td	�tj��t�|tkrtd
  25  �gYSYnw|�|�q*|r�||jd<tt|��}|S)z�
  26      Returns a list containing the names of all the modules available in the
  27      folders of the pythonpath.
  28  
  29      ip.db['rootmodules_cache'] maps sys.path entries to list of modules.
  30      NZ_mockF�rootmodules_cache�__init__)rrTz/
  31  Caching the list of root modules, please wait!z@(This will only be done once - type '%rehashx' to reset cache!)
  32  z%This is taking too long, we give up.
  33  )rr,�sys�builtin_module_names�getattr�db�getrr�KeyErrorr;�remove�
  34  ValueError�TIMEOUT_STORAGE�print�stdout�flush�TIMEOUT_GIVEUPr+r4)�ipr<Zrootmodules�
  35  start_time�storerr9rrr�get_root_moduleslsH
  36  
  37  
  38  �
  39  ��
  40  rN�attrcCsT|rzt||�}Wn
  41  tyYdSwt�|�S|dd�dko(|dd�dkS)NFr
  42  �__�����)r@�ModuleNotFoundError�inspect�ismodule)�modulerO�only_modules�modrrr�
  43  is_importable�s�
  44  "rXcCs@zt||�}WntyYdStyYdSwt�|�S)NTF)r@�AttributeError�	TypeErrorrSrT)rUrO�objrrr�is_possible_submodule�s�
  45  r\FrWcs�|�d�}zt|��WngYSdt�dd�pdv}g}t�d�r(�r(|r7|���fdd�t��D��t�dg�}�rL|��fdd	�|D��n|�|�|rg�j}tj�	|�}|d
  46  urg|�t
  47  |��dd�|D�}|�d�t|�S)
  48  zN
  49      Try to import given module and return list of potential completions.
  50      rr=�__file__rcsg|]
  51  }t�|��r|�qSr)rX�rrO�r:rVrr�
  52  <listcomp>�s
  53  
  54  �ztry_import.<locals>.<listcomp>�__all__c3s�|]
  55  }t�|�r|VqdSr)r\r^)r:rrr�s�ztry_import.<locals>.<genexpr>NcSsh|]	}t|t�r|�qSr)�
  56  isinstance�str�r�crrr�	<setcomp>�sztry_import.<locals>.<setcomp>)
  57  �rstriprr@�hasattrr+�dirr]r&r�dirnamer;�discardr,)rWrVZ	m_is_init�completionsZm_all�file_�	file_pathZcompletions_setrr_r�
  58  try_import�s*
  59  
  60  
  61  rocs4t�t�r	�����fdd�}t�jd||d�dS)a� Easily create a trivial completer for a command.
  62  
  63      Takes either a list of completions, or all completions in string (that will
  64      be split on whitespace).
  65  
  66      Example::
  67  
  68          [d:\ipython]|1> import ipy_completers
  69          [d:\ipython]|2> ipy_completers.quick_completer('foo', ['bar','baz'])
  70          [d:\ipython]|3> foo b<TAB>
  71          bar baz
  72          [d:\ipython]|3> foo ba
  73      cs�Srr��self�event�rlrr�do_complete�sz$quick_completer.<locals>.do_completeZcomplete_command)Zstr_keyN)rbrc�splitrZset_hook)�cmdrlrtrrsr�quick_completer�s
  74  rwcs�|�d�}t|�}|dkr|ddkrdgS|dkrL|ddvrL|dkr't�S|d�d��t��d	kr7t�Std��d
  75  d��d�}�fd
  76  d�|D�S|dkr^|ddkr`|d�t��Sd
  77  Sd
  78  S)z�
  79      Returns a list containing the completion possibilities for an import line.
  80  
  81      The line looks like this :
  82      'import xml.d'
  83      'from xml.dom import'
  84      � �r�fromzimport >z%aimportrz�importrrr
  85  N�����Tcs$g|]}d��dd�|g��qS)rNr|)r')r�el�rWrrr`�$z%module_completion.<locals>.<listcomp>)rur*rNror')�line�wordsZnwordsZcompletion_listrr~r�module_completion�s 
  86  	�r�cCs
  87  t|j�S)z@Give completions after user has typed 'import ...' or 'from ...')r�r�rprrr�module_completers
  88  	r�cs�t|jdd�}t|�dkr|j�d�s|d�d�}nd}tj}tjj�t	|�\}��t
  89  dd	�|D��rB�fd
  90  d�||d�D�}n.�fd
  91  d�||d�D�}dd�||d�||d�||d�||d�D�}||}��fdd�|D�S)zKComplete files that end in .py or .ipy or .ipynb for the %run command.
  92      F)�strictrrxr|z'"rcsrr)�magic_run_rer1rdrrrr7rz&magic_run_completer.<locals>.<genexpr>cs(g|]}|�dd��|�rdnd�qS)�\�/r��replacer �r(rrr`8s �z'magic_run_completer.<locals>.<listcomp>�*cs$g|]}�|�r|�dd�d�qS�r�r�r�r r�rrr`;rcSsg|]}|�dd��qSr�r�r rrrr`<s�z*.pyz*.ipyz*.ipynbz*.pywc�g|]}t|����qSr�r�r�p��tilde_expand�	tilde_valrrr`C�)rr�r*�endswith�strip�globr&rr(r�any)rqrr�comps�relpathZlglob�matchesr7Zpysr)r(r�r�r�magic_run_completer!s*
  93  
  94  �
  95  �
  96  ��r�cstt�}�j}�j�d�sd�jvr |j�dd�}|r|��SgS�jdkrRtttt|j	d�d���}d|d	��fd
  97  d�t
  98  |j	d�D�}t|�dkrP|SgS�j�d�rbd
  99  d�|j	dD�St|�\}��|�
 100  dd�}g}dd�t�|d�D�D]
 101  }d|vr�t�|�|�q}|s�tj�|�r�t|���gS|j�di�}	�fdd�|	D�}
 102  |
 103  r�|
 104  St���fdd�|D�S)z:Completer function for cd, which only returns directories.z-bz -b Z	bookmarksN�-Z_dhrz-%0zd [%s]csg|]
 105  \}}�||f�qSrr)r�ir)�fmtrrr`X�z cd_completer.<locals>.<listcomp>�--cSsg|]
 106  }dtj�|��qS)r�)r&r�basename)r�drrrr`^r�r�r�cSs(g|]}tj�|�r|�dd�d�qSr�)r&rr(r�r rrrr`es
 107  �r�rxcsg|]
 108  }|��j�r|�qSr)�
 109  startswith�symbolr)rrrrr`tr�cr�rr�r�r�rrr`zr�)rr�r�r�rArBr.rcr*Zuser_ns�	enumerater�rr�r�r	r2r&rr(r)rqrrrKr�ZbkmsZwidth_dhZents�foundr�ZbksZ	bkmatchesr)rrr�r�r�r�cd_completerFs@
 110  r�cCsd��S)zA completer for %reset magicz-f -s in out array dhist)rurprrr�reset_completer|sr�)F),�__doc__r�rSr&rr>�	importlibr�importlib.machineryrr�	zipimportrZ	completerrr�errorr	Zutils._process_commonrZIPythonr�typingr
 111  Z	_suffixesrFrJ�compiler'r0r�rcr;rN�boolrXr\rorwr�r�r�r�r�rrrr�<module>sB�
 112  (/%%%6