Format: application/x-python-code
⬇ Download File (16.2 KB)
   1  o
   2  
   3  ��h�K�@s�dZddlZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
   4  mZddlm
   5  Z
   6  dZdZd	Zd
   7  ZdZdZd
   8  ZdZdZeeeeeeeeeg	ZGdd�dejd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zejdd��Zde de de d e fd!d"�Z!d#efd$d%�Z"d#efd&d'�Z#d#efd(d)�Z$d#efd*d+�Z%d#efd,d-�Z&d#efd.d/�Z'd#efd0d1�Z(ee"ee#ee$ee$ee%ee&ee'ee(iZ)ejd2e fd3d4��Z*e�+d5�Z,e�+d6ej-�Z.e/�Z0e/�Z1d7d8�Z2d9d:�Z3d;d<�Z4ejd2e fd=d>��Z5ejdTd@e6fdAdB��Z7dUdCdD�Z8ejdEdF��Z9ejdGdH��Z:ejdIdJ��Z;dKZ<e�+dL�=e<�ej-�Z>dMZ?ejdNdO��Z@e�+dP�=e<�ej-�ZAdQZBejdRdS��ZCdS)Va,DEPRECATED: Input transformer classes to support IPython special syntax.
   9  
  10  This module was deprecated in IPython 7.0, in favour of inputtransformer2.
  11  
  12  This includes the machinery to recognise and transform ``%magic`` commands,
  13  ``!system`` commands, ``help?`` querying, prompt stripping, and so forth.
  14  �N)�
  15  untokenize�
  16  TokenError)�StringIO)�LineInfo)�	tokenutil�!z!!�?�??�%z%%�,�;�/c@s@eZdZdZdd�Zejdd��Zejdd��Ze	dd	��Z
  17  d
  18  S)�InputTransformerz6Abstract base class for line-based input transformers.cCstjdtdd�dS)Nz`InputTransformer` has been deprecated since IPython 7.0 and emit a warnig since IPython 8.31, it will be removed in the future���
  19  stacklevel)�warnings�warn�DeprecationWarning��self�r�Sc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/core/inputtransformer.py�__init__/s
  20  
  21  �zInputTransformer.__init__cC�dS)a1Send a line of input to the transformer, returning the transformed
  22          input or None if the transformer is waiting for more input.
  23  
  24          Must be overridden by subclasses.
  25  
  26          Implementations may raise ``SyntaxError`` if the input is invalid. No
  27          other exceptions may be raised.
  28          Nr�r�linerrr�push8s
  29  zInputTransformer.pushcCr)z�Return, transformed any lines that the transformer has accumulated,
  30          and reset its internal state.
  31  
  32          Must be overridden by subclasses.
  33          Nrrrrr�resetDszInputTransformer.resetcst�����fdd��}|S)z�Can be used by subclasses as a decorator, to return a factory that
  34          will allow instantiation with the decorated object.
  35          cs��fi|��S�Nr)�kwargs��cls�funcrr�transformer_factoryRsz2InputTransformer.wrap.<locals>.transformer_factory)�	functools�wraps)r"r#r$rr!r�wrapMszInputTransformer.wrapN)�__name__�
  36  __module__�__qualname__�__doc__r�abc�abstractmethodrr�classmethodr'rrrrr,s	
  37  
  38  r)�	metaclassc�8eZdZdZ�fdd�Zdd�Zdd�Zdd	�Z�ZS)
  39  �StatelessInputTransformerzDWrapper for a stateless input transformer implemented as a function.cs$t���tjdtdd�||_dS)Nz�`StatelessInputTransformer` has been deprecated since IPython 7.0 and emit a warnig since IPython 8.31, it will be removed in the futurerr)�superrrrrr#�rr#��	__class__rrrZs
  40  �
  41  z"StatelessInputTransformer.__init__cC�d�|j�S)Nz%StatelessInputTransformer(func={0!r}))�formatr#rrrr�__repr__e�z"StatelessInputTransformer.__repr__cCs
  42  |�|�S)zQSend a line of input to the transformer, returning the
  43          transformed input.)r#rrrrrhs
  44  zStatelessInputTransformer.pushcCr)z!No-op - exists for compatibility.NrrrrrrmszStatelessInputTransformer.reset�	r(r)r*r+rr8rr�
  45  __classcell__rrr4rr1Xsr1cr0)
  46  �CoroutineInputTransformerz<Wrapper for an input transformer implemented as a coroutine.cs8t���tjdtdd�|di|��|_t|j�dS)N��`CoroutineInputTransformer` has been deprecated since IPython 7.0 and emit a warnig since IPython 8.31, it will be removed in the futurerrr)r2rrrr�coro�next)rr>r r4rrrss
  47  �z"CoroutineInputTransformer.__init__cCr6)Nz%CoroutineInputTransformer(coro={0!r}))r7r>rrrrr8�r9z"CoroutineInputTransformer.__repr__cCs|j�|�S)z�Send a line of input to the transformer, returning the
  48          transformed input or None if the transformer is waiting for more
  49          input.
  50          �r>�sendrrrrr�szCoroutineInputTransformer.pushcCs|j�d�S)zrReturn, transformed any lines that the transformer has
  51          accumulated, and reset its internal state.
  52          Nr@rrrrr�szCoroutineInputTransformer.resetr:rrr4rr<qs
  53  r<c@s8eZdZdZdd�Zdd�Zdd�Zdd	�Zd
  54  d�ZdS)
  55  �TokenInputTransformerz�Wrapper for a token-based input transformer.
  56      
  57      func should accept a list of tokens (5-tuples, see tokenize docs), and
  58      return an iterable which can be passed to tokenize.untokenize().
  59      cCs(tjdtdd�||_g|_|��dS)Nr=rr)rrrr#�buf�reset_tokenizerr3rrrr�s�zTokenInputTransformer.__init__cCst|j�}t�|j�|_dSr)�iterrCr�generate_tokens_catch_errors�__next__�	tokenizer)r�itrrrrD�s
  60  z%TokenInputTransformer.reset_tokenizercCs�|j�|d�tdd�|jD��r|��Sg}d}z&|jD] }|�|�|d}|tjks5|r7|tjkr7n|tjkr>d}qWnt	yN|�
  61  �YdSw|�|�S)N�
  62  css�|]}|��VqdSr)�isspace)�.0�lrrr�	<genexpr>�s�z-TokenInputTransformer.push.<locals>.<genexpr>FrT)rC�append�allrrH�tokenize�NEWLINE�NL�
  63  ERRORTOKENrrD�output)rr�tokensZ
  64  stop_at_NLZintok�trrrr�s&
  65  
  66  
  67  ��
  68  zTokenInputTransformer.pushcCs&|j��|��t|�|���d�S)NrJ)rC�clearrDrr#�rstrip�rrVrrrrU�s
  69  zTokenInputTransformer.outputcCs0d�|j�}|j��|��|r|�d�SdS)N�rJ)�joinrCrXrDrY)rrMrrrr�s
  70  
  71  �zTokenInputTransformer.resetN)	r(r)r*r+rrDrrUrrrrrrB�srBcs$eZdZ�fdd�Zdd�Z�ZS)�assemble_python_linescst��d�dSr)r2rrr4rrr�szassemble_python_lines.__init__cCs|��Sr)rrZrrrrU�szassemble_python_lines.output)r(r)r*rrUr;rrr4rr]�sr]ccst�d}	|V}|r
  72  |��rqg}|dur4|�d�r*t|�s*|�|dd��dV}n|�|�n|dusd�|�}q)z4Join lines following explicit line continuations (\)r[TN�\�����)rK�endswith�has_commentrOr\)r�partsrrr�assemble_logical_lines�s �
  73  �
  74  	�rc�target�esc�lspace�returncCsR|dkrdnd|vrdnd}d�||g�}|�d�\}}}|�t�}d|||fS)zUPrepares a pinfo(2)/psearch call from a target name and the escape
  75      (i.e. ? or ??)r	Zpinfo2�*ZpsearchZpinfo� �&%sget_ipython().run_line_magic(%r, %r))r\�	partition�lstrip�	ESC_MAGIC)rdrerf�method�arg�t_magic_name�_�
  76  t_magic_arg_srrr�_make_help_call�s�
  77  �rs�	line_infocCs|j���t�}d|j|fS)zTranslate lines escaped with: !z%sget_ipython().system(%r))rrl�	ESC_SHELL�pre�rt�cmdrrr�
  78  _tr_system�srycCs |j��dd�}d|j|fS)z Translate lines escaped with: !!rNz%sget_ipython().getoutput(%r))rrlrvrwrrr�_tr_system2�srzcCs$|jdd�s	dSt|j|j|j�S)z"Translate lines escaped with: ?/??�Nzget_ipython().show_usage())rrs�ifunrerv�rtrrr�_tr_helpsr~cCsVd}|j�t�r|jSd�|j|jg���}|�d�\}}}|�t	�}||j
  79  ||fS)zTranslate lines escaped with: %rjri)r�
  80  startswith�
  81  ESC_MAGIC2r\r|�the_rest�striprkrlrmrv)rt�tplrxrprqrrrrr�	_tr_magic
  82  s
  83  r�cC�d|j|jd�|j���fS)zTranslate lines escaped with: ,�
  84  %s%s("%s")z", "�rvr|r\r��splitr}rrr�	_tr_quote�
  85  �r�cCsd|j|j|jfS)zTranslate lines escaped with: ;r�)rvr|r�r}rrr�
  86  _tr_quote2s
  87  �r�cCr�)zTranslate lines escaped with: /z%s%s(%s)z, r�r}rrr�	_tr_paren%r�r�rcCs4|r|��r|St|�}|jtvr|St|j|�S)zHTransform escaped commands - %magic, !system, ?help + various autocalls.)rKrre�tr)rZlineinfrrr�escaped_commands3s
  88  r�z\s*a
  89  (%{0,2}
  90                                (?!\d)[\w*]+            # Variable name
  91                                (\.(?!\d)[\w*]+)*       # .etc.etc
  92                                )
  93                                (\?\??)$                # ? or ??
  94                                c
  95  Cs�t|�j}t�}zt�|�D]	}|�|d�qW|StyF}z d|jdvr/|�t�n|�t	�WYd}~|SWYd}~|Sd}~ww)z5Helper for has_comment and ends_in_comment_or_string.rzmulti-line stringN)
  96  r�readline�setrrF�addr�args�_MULTILINE_STRING�_MULTILINE_STRUCTURE)rr��toktypesrW�errr�_line_tokensLs 
  97  ��
  98  ���r�cCstjt|�vS)a=Indicate whether an input line has (i.e. ends in, or is) a comment.
  99  
 100      This uses tokenize, so it can distinguish comments from # inside strings.
 101  
 102      Parameters
 103      ----------
 104      src : string
 105          A single line input string.
 106  
 107      Returns
 108      -------
 109      comment : bool
 110          True if source has a comment.
 111      )rQ�COMMENTr�)�srcrrrra[sracCst|�}tj|vpt|vS)aIndicates whether or not an input line ends in a comment or within
 112      a multiline string.
 113  
 114      Parameters
 115      ----------
 116      src : string
 117          A single line input string.
 118  
 119      Returns
 120      -------
 121      comment : bool
 122          True if source ends in a comment or multiline string.
 123      )r�rQr�r�)r�r�rrr�ends_in_comment_or_stringlsr�cCs^t�|�}|dus
 124  t|�r|S|�d�}|�d�}t�|�}|dus$J�|�d�}t|||�S)z$Translate lines with ?/?? at the endNr{�r)�_help_end_re�searchr��group�_initial_space_re�matchrs)r�mrdrer�rfrrr�help_end~s
 125  
 126  
 127  
 128  
 129  r�F�end_on_blank_lineccs��d}t�d�}d}	|V}|s|V}|r|�t�s&|dur%|V}|dusq
 130  |�|�r,q
 131  |}g}dV}|durS|��dks?|sS|�|�dV}|durS|��dks?|r?|�d�\}}}|�t�}|||d�	|�f}q)z�Captures & transforms cell magics.
 132  
 133      After a cell magic is started, this stores up any lines it gets until it is
 134      reset (sent None).
 135      z(get_ipython().run_cell_magic(%r, %r, %r)z%%\w+\?r[TNrirJ)
 136  �re�compilerr�r�r�rOrkrlr\)r�r�Zcellmagic_help_rer�first�bodyZ
 137  magic_namerqrrr�	cellmagic�s:�
 138  �
 139  �
 140  
 141  �
 142  �r�ccs��|dur|}d}	|V}|durq	|jd|dd�\}}|r1|s1|�|�r1|dur0|V}|dus)q	|V}|dur9q	|jd|dd�\}}|V}|sJ|r\|dur[|jd|dd�V}|dusNn|durg|V}|dus`q
 143  )a&Remove matching input prompts from a block of input.
 144  
 145      Parameters
 146      ----------
 147      prompt_re : regular expression
 148          A regular expression matching any input prompt (including continuation)
 149      initial_re : regular expression, optional
 150          A regular expression matching only the initial prompt, but not continuation.
 151          If no initial expression is given, prompt_re will be used everywhere.
 152          Used mainly for plain Python prompts, where the continuation prompt
 153          ``...`` is a valid Python expression in Python 3, so shouldn't be stripped.
 154  
 155      Notes
 156      -----
 157      If `initial_re` and `prompt_re differ`,
 158      only `initial_re` will be tested against the first line.
 159      If any prompt is found on the first two lines,
 160      prompts will be stripped from the rest of the block.
 161      Nr[Tr{)�count)�subnr��sub)�	prompt_re�
 162  initial_re�
 163  turnoff_rer�outZn1Zn2rrr�_strip_prompts�s:�
 164  �����r�cCs*t�d�}t�d�}t�d�}t|||�S)z:Strip the >>>/... prompts of the Python interactive shell.z^(>>>|\.\.\.)( |$)z	^>>>( |$)z^[%!]�r�r�r�)r�r�r�rrr�classic_prompt�s
 165  
 166  
 167  r�cCs t�d�}t�d�}t||d�S)z%Strip IPython's In [1]:/...: prompts.z^(In \[\d+\]: |\s*\.{3,}: ?)z^%%)r�r�)r�r�rrr�
 168  ipy_prompt�s
 169  
 170  r�ccs��t�d�}d}	|V}|durq|�|�}|r6|�d�}|dur5|�|�r.|t|�d�}|V}|dus!n|durA|V}|dus:q	)z�Remove leading indentation.
 171  
 172      If the first line starts with a spaces or tabs, the same whitespace will be
 173      removed from each following line until it is reset.
 174      z^[ \t]+r[TNr)r�r�r�r�r�len)Zspace_rerr��spacerrr�leading_indents(�
 175  
 176  
 177  
 178  ����r�z�(?P<lhs>(\s*)
 179      ([\w\.]+)                # Initial identifier
 180      (\s*,\s*
 181          \*?[\w\.]+)*         # Further identifiers for unpacking
 182      \s*?,?                   # Trailing comma
 183      )
 184      \s*=\s*
 185  z{}!\s*(?P<cmd>.*)z %s = get_ipython().getoutput(%r)cCs&t�|�}|dur|St|�dd�S)z<Transform assignment from system commands (e.g. files = !ls)N�lhsrx)�assign_system_rer��assign_system_templater�)rr�rrr�assign_from_system,s
 186  r�z{}%\s*(?P<cmd>.*)z)%s = get_ipython().run_line_magic(%r, %r)cCsNt�|�}|dur|S|�dd�\}}|�d�\}}}|�t�}t|||fS)z;Transform assignment from magic commands (e.g. a = %who_ls)Nr�rxri)�assign_magic_rer�r�rkrlrm�assign_magic_template)rr�Zm_lhsZm_cmdrprqrrrrr�assign_from_magic7s
 187  
 188  r�)F)NN)Dr+r,r%r�rQrrr�iorZIPython.core.splitinputrZ
 189  IPython.utilsrruZ
 190  ESC_SH_CAPZESC_HELPZ	ESC_HELP2rmr�Z	ESC_QUOTEZ
 191  ESC_QUOTE2Z	ESC_PARENZ
 192  ESC_SEQUENCES�ABCMetarr1r<rBr]r'rc�strrsryrzr~r�r�r�r�r�r�r�r��VERBOSEr��objectr�r�r�rar�r��boolr�r�r�r�r�Z_assign_patr7r�r�r�r�r�r�rrrr�<module>s��,9
 193  	�	
 194  
 195  �	
 196  ';
 197  	
 198  	
 199  �
 200  
 201