
    9 fG                     2   d Z ddlZddlZddlZddlZddlmZmZ ddlmZ ddl	m
Z
 ddlmZ dZdZd	Zd
ZdZdZdZdZdZeeeeeeeeeg	Z G d dej                  Z G d de          Z G d de          Z G d de          Z G d de          Zej        d             Zdedededefd Z d!e
fd"Z!d!e
fd#Z"d!e
fd$Z#d!e
fd%Z$d!e
fd&Z%d!e
fd'Z&d!e
fd(Z'ee!ee"ee#ee#ee$ee%ee&ee'iZ(ej        d)efd*            Z) ej*        d+          Z+ ej*        d,ej,                  Z- e.            Z/ e.            Z0d- Z1d. Z2d/ Z3ej        d)efd0            Z4ej        d?d2e5fd3            Z6d@d4Z7ej        d5             Z8ej        d6             Z9ej        d7             Z:d8Z; ej*        d9<                    e;          ej,                  Z=d:Z>ej        d;             Z? ej*        d<<                    e;          ej,                  Z@d=ZAej        d>             ZBdS )Aa,  DEPRECATED: Input transformer classes to support IPython special syntax.

This module was deprecated in IPython 7.0, in favour of inputtransformer2.

This includes the machinery to recognise and transform ``%magic`` commands,
``!system`` commands, ``help?`` querying, prompt stripping, and so forth.
    N)
untokenize
TokenError)StringIO)LineInfo)	tokenutil!z!!???%z%%,;/c                   h    e Zd ZdZej        d             Zej        d             Zed             Z	dS )InputTransformerz6Abstract base class for line-based input transformers.c                     dS )a1  Send a line of input to the transformer, returning the transformed
        input or None if the transformer is waiting for more input.

        Must be overridden by subclasses.

        Implementations may raise ``SyntaxError`` if the input is invalid. No
        other exceptions may be raised.
        N selflines     S/var/www/equiseq/venv/lib/python3.11/site-packages/IPython/core/inputtransformer.pypushzInputTransformer.push.   s	     	    c                     dS )zReturn, transformed any lines that the transformer has accumulated,
        and reset its internal state.

        Must be overridden by subclasses.
        Nr   r   s    r   resetzInputTransformer.reset:   s	     	r   c                 J     t          j                   fd            }|S )zCan be used by subclasses as a decorator, to return a factory that
        will allow instantiation with the decorated object.
        c                       fi | S Nr   )kwargsclsfuncs    r   transformer_factoryz2InputTransformer.wrap.<locals>.transformer_factoryH   s    3t&&v&&&r   )	functoolswraps)r    r!   r"   s   `` r   wrapzInputTransformer.wrapC   sA    
 
			' 	' 	' 	' 	' 
		' #"r   N)
__name__
__module____qualname____doc__abcabstractmethodr   r   classmethodr%   r   r   r   r   r   +   sq        @@	 	 	 	   # # [# # #r   r   )	metaclassc                   *    e Zd ZdZd Zd Zd Zd ZdS )StatelessInputTransformerzDWrapper for a stateless input transformer implemented as a function.c                     || _         d S r   r!   r   r!   s     r   __init__z"StatelessInputTransformer.__init__P   s    			r   c                 6    d                     | j                  S )Nz%StatelessInputTransformer(func={0!r}))formatr!   r   s    r   __repr__z"StatelessInputTransformer.__repr__S       6==diHHHr   c                 ,    |                      |          S )zQSend a line of input to the transformer, returning the
        transformed input.r1   r   s     r   r   zStatelessInputTransformer.pushV   s     yyr   c                     dS )z!No-op - exists for compatibility.Nr   r   s    r   r   zStatelessInputTransformer.reset[   s    r   Nr&   r'   r(   r)   r3   r6   r   r   r   r   r   r/   r/   N   sY        NN  I I I  
    r   r/   c                   *    e Zd ZdZd Zd Zd Zd ZdS )CoroutineInputTransformerz<Wrapper for an input transformer implemented as a coroutine.c                 H     |di || _         t          | j                    d S )Nr   )coronext)r   r>   r   s      r   r3   z"CoroutineInputTransformer.__init__a   s&    DNN6NN	TYr   c                 6    d                     | j                  S )Nz%CoroutineInputTransformer(coro={0!r}))r5   r>   r   s    r   r6   z"CoroutineInputTransformer.__repr__f   r7   r   c                 6    | j                             |          S )zSend a line of input to the transformer, returning the
        transformed input or None if the transformer is waiting for more
        input.
        r>   sendr   s     r   r   zCoroutineInputTransformer.pushi   s    
 y~~d###r   c                 6    | j                             d          S )zrReturn, transformed any lines that the transformer has
        accumulated, and reset its internal state.
        NrB   r   s    r   r   zCoroutineInputTransformer.resetp   s     y~~d###r   Nr:   r   r   r   r<   r<   _   sY        FF  
I I I$ $ $$ $ $ $ $r   r<   c                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )TokenInputTransformerzWrapper for a token-based input transformer.
    
    func should accept a list of tokens (5-tuples, see tokenize docs), and
    return an iterable which can be passed to tokenize.untokenize().
    c                 J    || _         g | _        |                                  d S r   )r!   bufreset_tokenizerr2   s     r   r3   zTokenInputTransformer.__init__|   s(    	r   c                 j    t          | j                  }t          j        |j                  | _        d S r   )iterrH   r   generate_tokens_catch_errors__next__	tokenizer)r   its     r   rI   z%TokenInputTransformer.reset_tokenizer   s'    $(^^"?LLr   c                    | j                             |dz              t          d | j         D                       r|                                 S g }d}	 | j        D ]U}|                    |           |d         }|t
          j        k    s|r|t
          j        k    r n|t
          j        k    rd}Vn%# t          $ r | 
                                 Y d S w xY w|                     |          S )N
c              3   >   K   | ]}|                                 V  d S r   )isspace).0ls     r   	<genexpr>z-TokenInputTransformer.push.<locals>.<genexpr>   s*      --qqyy{{------r   Fr   T)rH   appendallr   rN   tokenizeNEWLINENL
ERRORTOKENr   rI   output)r   r   tokens
stop_at_NLintokts         r   r   zTokenInputTransformer.push   s   t$$$--DH----- 	 ::<<
	 & &e$$$!H(((Z(A<L<LE(---!%J 	 	 	  """44	
 {{6"""s   AB3 3CCc                     | j                                          |                                  t          |                     |                                        d          S )NrQ   )rH   clearrI   r   r!   rstripr   r^   s     r   r]   zTokenInputTransformer.output   sN    $))F++,,33D999r   c                     d                     | j                  }| j                                         |                                  |r|                    d          S d S )N rQ   )joinrH   rc   rI   rd   )r   rU   s     r   r   zTokenInputTransformer.reset   s[    GGDH 	"88D>>!	" 	"r   N)	r&   r'   r(   r)   r3   rI   r   r]   r   r   r   r   rF   rF   v   sl         
  
M M M# # #.: : :
" " " " "r   rF   c                   $     e Zd Z fdZd Z xZS )assemble_python_linesc                 X    t          t          |                               d            d S r   )superrj   r3   )r   	__class__s    r   r3   zassemble_python_lines.__init__   s(    #T**33D99999r   c                 *    |                                  S r   )r   re   s     r   r]   zassemble_python_lines.output   s    zz||r   )r&   r'   r(   r3   r]   __classcell__)rm   s   @r   rj   rj      sG        : : : : :      r   rj   c               #   2  K   d} 	 | V } | r|                                  rg }| ^|                     d          r1t          |           s"|                    | dd                    dV } n|                    |            n| ^d                    |          } )z4Join lines following explicit line continuations (\)rg   TN\)rS   endswithhas_commentrW   rh   )r   partss     r   assemble_logical_linesrv      s       D

 	t||~~ 	}}T"" K,=,= T#2#Y'''"

T"""  wwu~~r   targetesclspacereturnc                     |dk    rdnd| v rdnd}d                     || g          }|                    d          \  }}}|                    t                    }|d|d|d	S )
zUPrepares a pinfo(2)/psearch call from a target name and the escape
    (i.e. ? or ??)r
   pinfo2*psearchpinfo zget_ipython().run_line_magic(, ))rh   	partitionlstrip	ESC_MAGIC)rw   rx   ry   methodargt_magic_name_t_magic_arg_ss           r   _make_help_callr      s     ++hh"%--YY  ((FF#
$
$C%(]]3%7%7"L!]&&y11L r   	line_infoc                 ~    | j                                                             t                    }| j        d|dS )zTranslate lines escaped with: !zget_ipython().system(r   )r   r   	ESC_SHELLprer   cmds     r   
_tr_systemr      s8    
.


!
!
(
(
3
3C+4===###>>r   c                 ^    | j                                         dd         }| j        d|dS )z Translate lines escaped with: !!   Nzget_ipython().getoutput(r   )r   r   r   r   s     r   _tr_system2r      s3    
.


!
!!""
%C.7mmmSSSAAr   c                 d    | j         dd         sdS t          | j        | j        | j                  S )z"Translate lines escaped with: ?/??   Nzget_ipython().show_usage())r   r   ifunrx   r   r   s    r   _tr_helpr      s5     >!"" ,++9>9=)-HHHr   c                 8   d}| j                             t                    r| j         S d                    | j        | j        g                                          }|                    d          \  }}}|                    t                    }|| j
        ||fz  S )zTranslate lines escaped with: %z&%sget_ipython().run_line_magic(%r, %r)r   )r   
startswith
ESC_MAGIC2rh   r   the_reststripr   r   r   r   )r   tplr   r   r   r   s         r   	_tr_magicr      s    
2C~  ,, ~
((INI$67
8
8
>
>
@
@C%(]]3%7%7"L!]&&y11L)-}===r   c                 ~    | j         | j        dd                    | j                                                  dS )zTranslate lines escaped with: ,("z", "")r   r   rh   r   splitr   s    r   	_tr_quoter      sA    $==)...Y%7%=%=%?%?@@@@C Cr   c                 4    | j         | j        d| j        dS )zTranslate lines escaped with: ;r   r   )r   r   r   r   s    r   
_tr_quote2r      s'    $==)...$---/ /r   c                 ~    | j         | j        dd                    | j                                                  dS )zTranslate lines escaped with: /(r   r   r   r   s    r   	_tr_parenr     sA    "	9#5#;#;#=#=>>>>@ @r   r   c                     | r|                                  r| S t          |           }|j        t          vr| S t          |j                 |          S )zHTransform escaped commands - %magic, !system, ?help + various autocalls.)rS   r   rx   tr)r   lineinfs     r   escaped_commandsr     sQ      4<<>> tnnG{"gk?7###r   z\s*a  (%{0,2}
                              (?!\d)[\w*]+            # Variable name
                              (\.(?!\d)[\w*]+)*       # .etc.etc
                              )
                              (\?\??)$                # ? or ??
                              c                 h   t          |           j        }t                      }	 t          j        |          D ]}|                    |d                    n[# t          $ rN}d|j        d         v r|                    t                     n|                    t                     Y d}~nd}~ww xY w|S )z5Helper for has_comment and ends_in_comment_or_string.r   zmulti-line stringN)
r   readlinesetr   rL   addr   args_MULTILINE_STRING_MULTILINE_STRUCTURE)r   r   toktypesra   es        r   _line_tokensr   +  s    ~~&HuuH/7AA 	 	ALL1	 / / /!&)++LL*++++LL-.../ Os   2A 
B/!AB**B/c                 8    t           j        t          |           v S )a=  Indicate whether an input line has (i.e. ends in, or is) a comment.

    This uses tokenize, so it can distinguish comments from # inside strings.

    Parameters
    ----------
    src : string
        A single line input string.

    Returns
    -------
    comment : bool
        True if source has a comment.
    )rY   COMMENTr   )srcs    r   rt   rt   :  s     S 1 112r   c                 N    t          |           }t          j        |v pt          |v S )a  Indicates whether or not an input line ends in a comment or within
    a multiline string.

    Parameters
    ----------
    src : string
        A single line input string.

    Returns
    -------
    comment : bool
        True if source ends in a comment or multiline string.
    )r   rY   r   r   )r   r   s     r   ends_in_comment_or_stringr   K  s*     C  H(L.?8.KLr   c                 8   t                               |           }|t          |           r| S |                    d          }|                    d          }t                              |           }|J |                    d          }t          |||          S )z$Translate lines with ?/?? at the endNr      r   )_help_end_researchr   group_initial_space_rematchr   )r   mrw   rx   r   ry   s         r   help_endr   ]  s     	D!!Ay-d33yWWQZZF
''!**C##D))E[[^^F63///r   Fend_on_blank_linec              #     K   d}t          j        d          }d}	 |V }|s|V }||                    t                    s	||V }|0|                    |          rF|}g }dV }|O|                                dk    s| s5|                    |           dV }||                                dk    3| 5|                    d          \  }}}|                    t                    }|||d	                    |          fz  })zCaptures & transforms cell magics.

    After a cell magic is started, this stores up any lines it gets until it is
    reset (sent None).
    z(get_ipython().run_cell_magic(%r, %r, %r)z%%\w+\?rg   TNr   rQ   )
recompiler   r   r   r   rW   r   r   rh   )r   r   cellmagic_help_rer   firstbody
magic_namer   s           r   	cellmagicr   l  sQ      5C
:..D;

 	 JJD  	  z** 	""

 """4(( 	

"&**,,""4"4=N"4KKJJD "&**,,""4"4=N"4
  %s33
Au&&z22
j%D)9)9::7;r   c              #   @  K   || }d}	 |V }||                     d|d          \  }}|r |s|                    |          r	||V }|E|V }|L|                      d|d          \  }}|V }|s|r||                     d|d          V }|n||V }|)a&  Remove matching input prompts from a block of input.

    Parameters
    ----------
    prompt_re : regular expression
        A regular expression matching any input prompt (including continuation)
    initial_re : regular expression, optional
        A regular expression matching only the initial prompt, but not continuation.
        If no initial expression is given, prompt_re will be used everywhere.
        Used mainly for plain Python prompts, where the continuation prompt
        ``...`` is a valid Python expression in Python 3, so shouldn't be stripped.

    Notes
    -----
    If `initial_re` and `prompt_re differ`,
    only `initial_re` will be tested against the first line.
    If any prompt is found on the first two lines,
    prompts will be stripped from the rest of the block.
    Nrg   Tr   )count)subnr   sub)	prompt_re
initial_re
turnoff_rer   outn1n2s          r   _strip_promptsr     s     ( 
D"$

 <//"d!/44R 	b 	%%  &"&JJD &		< ..T.33R		 		$ 		$ "'mmBAm>>>> "
 ""

 "C"$r   c                      t          j        d          } t          j        d          }t          j        d          }t          | ||          S )z:Strip the >>>/... prompts of the Python interactive shell.z^(>>>|\.\.\.)( |$)z	^>>>( |$)z^[%!]r   r   r   )r   r   r   s      r   classic_promptr     sD     
011IL))JH%%J)Z<<<r   c                  t    t          j        d          } t          j        d          }t          | |          S )z%Strip IPython's In [1]:/...: prompts.z^(In \[\d+\]: |\s*\.{3,}: ?)z^%%)r   r   )r   r   s     r   
ipy_promptr     s6     
:;;IF##J)
;;;;r   c               #     K   t          j        d          } d}	 |V }||                     |          }|rJ|                    d          }|2|                    |          r|t          |          d         }|V }|2n||V }|q)zRemove leading indentation.

    If the first line starts with a spaces or tabs, the same whitespace will be
    removed from each following line until it is reset.
    z^[ \t]+rg   TNr   )r   r   r   r   r   len)space_rer   r   spaces       r   leading_indentr     s       z*%%HD$

<NN4   		$GGAJJE"??5)) -E

,D"

 " ""

 "$r   z(?P<lhs>(\s*)
    ([\w\.]+)                # Initial identifier
    (\s*,\s*
        \*?[\w\.]+)*         # Further identifiers for unpacking
    \s*?,?                   # Trailing comma
    )
    \s*=\s*
z{}!\s*(?P<cmd>.*)z %s = get_ipython().getoutput(%r)c                 z    t                               |           }|| S t          |                    dd          z  S )z<Transform assignment from system commands (e.g. files = !ls)Nlhsr   )assign_system_rer   assign_system_templater   )r   r   s     r   assign_from_systemr     s:     	t$$Ay!AGGE5$9$999r   z{}%\s*(?P<cmd>.*)z)%s = get_ipython().run_line_magic(%r, %r)c                     t                               |           }|| S |                    dd          \  }}|                    d          \  }}}|                    t
                    }t          |||fz  S )z;Transform assignment from magic commands (e.g. a = %who_ls)Nr   r   r   )assign_magic_rer   r   r   r   r   assign_magic_template)r   r   m_lhsm_cmdr   r   r   s          r   assign_from_magicr     su     	d##Ay775%((LE5%*__S%9%9"L!]&&y11L E<#GGGr   )F)NN)Cr)   r*   r#   r   rY   r   r   ior   IPython.core.splitinputr   IPython.utilsr   r   
ESC_SH_CAPESC_HELP	ESC_HELP2r   r   	ESC_QUOTE
ESC_QUOTE2	ESC_PARENESC_SEQUENCESABCMetar   r/   r<   rF   rj   r%   rv   strr   r   r   r   r   r   r   r   r   r   r   r   VERBOSEr   objectr   r   r   rt   r   r   boolr   r   r   r   r   _assign_patr5   r   r   r   r   r   r   r   r   r   <module>r     s#    


     				  + + + + + + + +       , , , , , , # # # # # # 	
		
	
	JIzJ	4
!# !# !# !# !# !# !# !# !#F     0   "$ $ $ $ $ 0 $ $ $.0" 0" 0" 0" 0", 0" 0" 0"d    1       *C c 3 3    $?( ? ? ? ?B8 B B B BI I I I I	> 	> 	> 	> 	>C C C C C/( / / / /@ @ @ @ @
 JKHHIIJI  $3 $ $ $  $ BJv&& rz " !j* * FHH vxx   3 3 3"M M M$ 03 0 0 0  0 $; $; $; $; $;  $;N9$ 9$ 9$ 9$v = =  = < <  < $ $  $8  2:299+FF
SS ; : :  : "*188EErzRRC 	H 	H  	H 	H 	Hr   