
    ^hG                     f   S r SSKrSSKrSSKrSSKrSSKJrJr  SSKJr  SSK	J
r
  SSKJr  SrSrS	rS
rSrSrSrSrSr\\\\\\\\\/	r " S S\R.                  S9r " S S\5      r " S S\5      r " S S\5      r " S S\5      r\R:                  S 5       rS\S\S\S\4S  jr S!\
4S" jr!S!\
4S# jr"S!\
4S$ jr#S!\
4S% jr$S!\
4S& jr%S!\
4S' jr&S!\
4S( jr'\\!\\"\\#\\#\\$\\%\\&\\'0r(\R:                  S)\4S* j5       r)\RT                  " S+5      r+\RT                  " S,\RX                  5      r-\." 5       r/\." 5       r0S- r1S. r2S/ r3\R:                  S)\4S0 j5       r4\R:                  S>S1\54S2 jj5       r6S?S3 jr7\R:                  S4 5       r8\R:                  S5 5       r9\R:                  S6 5       r:S7r;\RT                  " S8Ry                  \;5      \RX                  5      r=S9r>\R:                  S: 5       r?\RT                  " S;Ry                  \;5      \RX                  5      r@S<rA\R:                  S= 5       rBg)@a,  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                   p    \ rS rSrSr\R                  S 5       r\R                  S 5       r\	S 5       r
Srg)InputTransformer+   z6Abstract base class for line-based input transformers.c                     g)a	  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     W/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/inputtransformer.pypushInputTransformer.push.   s     	    c                     g)zReturn, transformed any lines that the transformer has accumulated,
and reset its internal state.

Must be overridden by subclasses.
Nr   r   s    r   resetInputTransformer.reset:   s     	r   c                 J   ^ ^ [         R                  " T5      U U4S j5       nU$ )zwCan be used by subclasses as a decorator, to return a factory that
will allow instantiation with the decorated object.
c                     > T" T40 U D6$ Nr   )kwargsclsfuncs    r   transformer_factory2InputTransformer.wrap.<locals>.transformer_factoryH   s    t&v&&r   )	functoolswraps)r#   r$   r%   s   `` r   wrapInputTransformer.wrapC   s(    
 
		' 
	' #"r   r   N)__name__
__module____qualname____firstlineno____doc__abcabstractmethodr   r   classmethodr)   __static_attributes__r   r   r   r   r   +   sK    @	 	 	  # #r   r   )	metaclassc                   0    \ rS rSrSrS rS rS rS rSr	g)	StatelessInputTransformerN   zDWrapper for a stateless input transformer implemented as a function.c                     Xl         g r!   r$   r   r$   s     r   __init__"StatelessInputTransformer.__init__P   s    	r   c                 8    SR                  U R                  5      $ )Nz%StatelessInputTransformer(func={0!r}))formatr$   r   s    r   __repr__"StatelessInputTransformer.__repr__S       6==diiHHr   c                 $    U R                  U5      $ )zISend a line of input to the transformer, returning the
transformed input.r9   r   s     r   r   StatelessInputTransformer.pushV   s     yyr   c                     g)z!No-op - exists for compatibility.Nr   r   s    r   r   StatelessInputTransformer.reset[   s    r   r9   N
r+   r,   r-   r.   r/   r;   r?   r   r   r3   r   r   r   r6   r6   N   s    NI
r   r6   c                   0    \ rS rSrSrS rS rS rS rSr	g)	CoroutineInputTransformer_   z<Wrapper for an input transformer implemented as a coroutine.c                 H    U" S0 UD6U l         [        U R                   5        g )Nr   )coronext)r   rK   r"   s      r   r;   "CoroutineInputTransformer.__init__a   s    N6N	TYYr   c                 8    SR                  U R                  5      $ )Nz%CoroutineInputTransformer(coro={0!r}))r>   rK   r   s    r   r?   "CoroutineInputTransformer.__repr__f   rA   r   c                 8    U R                   R                  U5      $ )zSend a line of input to the transformer, returning the
transformed input or None if the transformer is waiting for more
input.
rK   sendr   s     r   r   CoroutineInputTransformer.pushi   s    
 yy~~d##r   c                 8    U R                   R                  S5      $ )zbReturn, transformed any lines that the transformer has
accumulated, and reset its internal state.
NrQ   r   s    r   r   CoroutineInputTransformer.resetp   s     yy~~d##r   )rK   NrF   r   r   r   rH   rH   _   s    F
I$$r   rH   c                   6    \ rS rSrSrS rS rS rS rS r	Sr
g	)
TokenInputTransformerv   zWrapper 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                 >    Xl         / U l        U R                  5         g r!   )r$   bufreset_tokenizerr:   s     r   r;   TokenInputTransformer.__init__|   s    	r   c                 x    [        U R                  5      n[        R                  " UR                  5      U l        g r!   )iterrZ   r   generate_tokens_catch_errors__next__	tokenizer)r   its     r   r[   %TokenInputTransformer.reset_tokenizer   s%    $((^"??Lr   c                    U R                   R                  US-   5        [        S U R                    5       5      (       a  U R                  5       $ / nSn U R                   Hb  nUR                  U5        US   nU[
        R                  :X  d  U(       a  U[
        R                  :X  a    OU[
        R                  :X  d  M`  SnMd      U R                  U5      $ ! [         a    U R                  5          g f = f)N
c              3   @   #    U  H  oR                  5       v   M     g 7fr!   )isspace).0ls     r   	<genexpr>-TokenInputTransformer.push.<locals>.<genexpr>   s     -Hqyy{{Hs   Fr   T)rZ   appendallr   ra   tokenizeNEWLINENL
ERRORTOKENr   r[   output)r   r   tokens
stop_at_NLintokts         r   r   TokenInputTransformer.push   s    t$-DHH---::<
	e$!H(((ZA<L(---!%J ( {{6""  	  "	s   AC +C C C65C6c                     U R                   R                  5         U R                  5         [        U R	                  U5      5      R                  S5      $ )Nre   )rZ   clearr[   r   r$   rstripr   rs   s     r   rr   TokenInputTransformer.output   s;    $))F+,33D99r   c                     SR                  U R                  5      nU R                  R                  5         U R                  5         U(       a  UR	                  S5      $ g )N re   )joinrZ   ry   r[   rz   )r   ri   s     r   r   TokenInputTransformer.reset   sD    GGDHH88D>! r   )rZ   r$   ra   N)r+   r,   r-   r.   r/   r;   r[   r   rr   r   r3   r   r   r   rW   rW   v   s!    

M#.:
"r   rW   c                   .   ^  \ rS rSrU 4S jrS rSrU =r$ )assemble_python_lines   c                 ,   > [         [        U ]  S 5        g r!   )superr   r;   )r   	__class__s    r   r;   assemble_python_lines.__init__   s    #T3D9r   c                 "    U R                  5       $ r!   )r   r{   s     r   rr   assemble_python_lines.output   s    zz|r   r   )r+   r,   r-   r.   r;   rr   r3   __classcell__)r   s   @r   r   r      s    : r   r   c               #   0  #    Sn  U v n U (       a  U R                  5       (       a  M#  / nU bV  U R                  S5      (       a)  [        U 5      (       d  UR                  U SS 5        Sv n OUR                  U 5        OU b  MV  SR	                  U5      n M  7f)z4Join lines following explicit line continuations (\)r~   N\)rg   endswithhas_commentrl   r   )r   partss     r   assemble_logical_linesr      s      D

t||~~}}T""K,=,=T#2Y'"
T"  wwu~ s   A?BBtargetesclspacereturnc                     US:X  a  SO	SU ;   a  SOSnSR                  X0/5      nUR                  S5      u  pVnUR                  [        5      nU< SU< SU< S	3$ )
zQPrepares 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(, ))r   	partitionlstrip	ESC_MAGIC)r   r   r   methodargt_magic_name_t_magic_arg_ss           r   _make_help_callr      sg     +h"%-Y  ((F#
$C%(]]3%7"L]&&y1L r   	line_infoc                     U R                   R                  5       R                  [        5      nU R                  < SU< S3$ )zTranslate lines escaped with: !zget_ipython().system(r   )r   r   	ESC_SHELLprer   cmds     r   
_tr_systemr      s.    
..


!
(
(
3C+4==#>>r   c                 d    U R                   R                  5       SS nU R                  < SU< S3$ )z Translate lines escaped with: !!   Nzget_ipython().getoutput(r   )r   r   r   r   s     r   _tr_system2r      s*    
..


!!"
%C.7mmSAAr   c                     U R                   SS (       d  g[        U R                  U R                  U R                  5      $ )z"Translate lines escaped with: ?/??   Nzget_ipython().show_usage())r   r   ifunr   r   r   s    r   _tr_helpr      s0     >>!"+9>>9==)--HHr   c                 B   SnU R                   R                  [        5      (       a  U R                   $ SR                  U R                  U R
                  /5      R                  5       nUR                  S5      u  p4nUR                  [        5      nXR                  X54-  $ )zTranslate lines escaped with: %z&%sget_ipython().run_line_magic(%r, %r)r   )r   
startswith
ESC_MAGIC2r   r   the_reststripr   r   r   r   )r   tplr   r   r   r   s         r   	_tr_magicr      s    
2C~~  ,,~~
((INNI$6$67
8
>
>
@C%(]]3%7"L]&&y1L--===r   c                     U R                   < U R                  < SSR                  U R                  R	                  5       5      < S3$ )zTranslate lines escaped with: ,("z", "")r   r   r   r   splitr   s    r   	_tr_quoter      s6    $==)..Y%7%7%=%=%?@C Cr   c                 X    U R                   < U R                  < SU R                  < S3$ )zTranslate lines escaped with: ;r   r   )r   r   r   r   s    r   
_tr_quote2r      s"    $==)..$--/ /r   c                     U R                   < U R                  < SSR                  U R                  R	                  5       5      < S3$ )zTranslate lines escaped with: /(r   r   r   r   s    r   	_tr_parenr     s6    "	9#5#5#;#;#=>@ @r   r   c                     U (       a  U R                  5       (       a  U $ [        U 5      nUR                  [        ;  a  U $ [        UR                     " U5      $ )zHTransform escaped commands - %magic, !system, ?help + various autocalls.)rg   r   r   tr)r   lineinfs     r   escaped_commandsr     sC     4<<>>tnG{{"gkk?7##r   z\s*a  (%{0,2}
                              (?!\d)[\w*]+            # Variable name
                              (\.(?!\d)[\w*]+)*       # .etc.etc
                              )
                              (\?\??)$                # ? or ??
                              c                 ^   [        U 5      R                  n[        5       n [        R                  " U5       H  nUR                  US   5        M     U$ ! [         aN  nSUR                  S   ;   a  UR                  [        5         SnAU$ UR                  [        5         SnAU$ SnAff = f)z5Helper for has_comment and ends_in_comment_or_string.r   zmulti-line stringN)
r   readlinesetr   r_   addr   args_MULTILINE_STRING_MULTILINE_STRUCTURE)r   r   toktypesrv   es        r   _line_tokensr   +  s    ~&&HuH/77AALL1 B O  /!&&)+LL*++ O LL-..O/s   1A 
B,(B'B''B,c                 :    [         R                  [        U 5      ;   $ )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.
)rn   COMMENTr   )srcs    r   r   r   :  s     S 112r   c                 ^    [        U 5      n[        R                  U;   =(       d	    [        U;   $ )zIndicates 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   rn   r   r   )r   r   s     r   ends_in_comment_or_stringr   K  s*     C H(L.?8.KLr   c                    [         R                  U 5      nUb  [        U 5      (       a  U $ UR                  S5      nUR                  S5      n[        R                  U 5      nUc   eUR                  S5      n[        X#U5      $ )z$Translate lines with ?/?? at the endr      r   )_help_end_researchr   group_initial_space_rematchr   )r   mr   r   r   r   s         r   help_endr   ]  sy     	D!Ay-d33WWQZF
''!*C##D)E[[^F6//r   end_on_blank_linec              #   ,  #    Sn[         R                  " S5      nSn Uv nU(       d  Uv nU(       d  M  UR                  [        5      (       d  Ub	  Uv nUb  M	  MA  UR	                  U5      (       a  MY  Un/ nSv nUbR  UR                  5       S:w  d  U (       d7  UR                  U5        Sv nUb  UR                  5       S:w  a  M.  U (       d  M7  UR                  S5      u  pgnUR                  [        5      nXUSR                  U5      4-  nM  7f)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+\?r~   Nr   re   )
recompiler   r   r   r   rl   r   r   r   )r   r   cellmagic_help_rer   firstbody
magic_namer   s           r   	cellmagicr   l  s     5C

:.D

JD $ z**""
 """4((
"&**,""4=NKKJD "&**,""4=N=N
  %s3
u&&z2
%D)9::7 s   2D$DA,D
DADc              #   f  #    Uc  U nSn Uv nUc  M
  UR                  SUSS9u  pEU(       a+  U(       d$  UR                  U5      (       a  Ub	  Uv nUb  M	  MO  Uv nUc  MX  U R                  SUSS9u  pFUv nU(       d  U(       a  Ub  U R                  SUSS9v nUb  M  OUb	  Uv nUb  M	  M  7f)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.
r~   r   )count)subnr   sub)	prompt_re
initial_re
turnoff_rer   outn1n2s          r   _strip_promptsr     s     ( 
D

 <//"d!/4b%% &"&JD &	< ..T.3	 "'mmBAm>> "
 ""
 "C s   AB1A	B1"B1/B1c                      [         R                  " S5      n [         R                  " S5      n[         R                  " S5      n[        XU5      $ )z:Strip the >>>/... prompts of the Python interactive shell.z^(>>>|\.\.\.)( |$)z	^>>>( |$)z^[%!]r   r   r   )r   r   r   s      r   classic_promptr     s<     

01IL)JH%J)<<r   c                  l    [         R                  " S5      n [         R                  " S5      n[        XS9$ )z%Strip IPython's In [1]:/...: prompts.z^(In \[\d+\]: |\s*\.{3,}: ?)z^%%)r   r   )r   r   s     r   
ipy_promptr     s,     

:;IF#J);;r   c               #     #    [         R                  " S5      n Sn Uv nUc  M
  U R                  U5      nU(       aB  UR                  S5      nUb-  UR	                  U5      (       a  U[        U5      S nUv nUb  M-  OUb	  Uv nUb  M	  Mq  7f)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]+r~   Nr   )r   r   r   r   r   len)space_rer   r   spaces       r   leading_indentr    s      zz*%HD

<NN4 GGAJE"??5))E
,D"
 " ""
 " s   A:B>BB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                 h    [         R                  U 5      nUc  U $ [        UR                  SS5      -  $ )z<Transform assignment from system commands (e.g. files = !ls)lhsr   )assign_system_rer   assign_system_templater   )r   r   s     r   assign_from_systemr    s4     	t$Ay!AGGE5$999r   z{}%\s*(?P<cmd>.*)z)%s = get_ipython().run_line_magic(%r, %r)c                     [         R                  U 5      nUc  U $ UR                  SS5      u  p#UR                  S5      u  pEnUR	                  [
        5      n[        X$U4-  $ )z;Transform assignment from magic commands (e.g. a = %who_ls)r  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    sc     	d#Ay775%(LE%*__S%9"L]&&y1L E#GGGr   )F)NN)Cr/   r0   r'   r   rn   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   r6   rH   rW   r   r)   r   strr   r   r   r   r   r   r   r   r   r   r   r   VERBOSEr   objectr   r   r   r   r   r   boolr   r   r   r   r  _assign_patr>   r  r  r  r  r	  r  r   r   r   <module>r     s     	  +  , # 	
		
	
	JIzJ	4
!# !#F 0 "$ 0 $.0", 0"d1    *C c 3 3 $?( ?B8 BI I	> 	>C C/( /@ @
 JKHHIIJI  $3 $  $ JJv& zz " !jj* H x 3"M$ 03 0  0 $; $;  $;N9$v =  = <  < $  $8  ::299+F

S ; :  : **188ErzzRC 	H  	Hr   