
    ^hqq                        S r SSKJr  \" S\5        SSKrSSK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JrJrJr  SSKJr  SSKJrJrJrJrJrJrJrJrJrJr  SSKJr  SS	KJrJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'  \RP                  " S
RS                  / SQ5      5      r*\RP                  " S5      r+\RP                  " S5      r,S r-\	R\                  r/\	R\                  S-   r0 " S S5      r1 " S S5      r2S r3S\44S jr5S r6\RP                  " S\Rn                  5      r8\RP                  " S\Rn                  5      r9S r:S r;S r< " S S\=5      r> " S S \>5      r?g)!a6  DEPRECATED: Input handling and transformation machinery.

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

The first class in this module, :class:`InputSplitter`, is designed to tell when
input from a line-oriented frontend is complete and should be executed, and when
the user should be prompted for another line of code instead. The name 'input
splitter' is largely for historical reasons.

A companion, :class:`IPythonInputSplitter`, provides the same functionality but
with full support for the extended IPython syntax (magics, system calls, etc).
The code to actually do these transformations is in :mod:`IPython.core.inputtransformer`.
:class:`IPythonInputSplitter` feeds the raw code to the transformers in order
and stores the results.

For more details, see the class docstrings below.
    )warnzeIPython.core.inputsplitter is deprecated since IPython 7 in favor of `IPython.core.inputtransformer2`N)ListTupleUnionOptional)CodeType)
leading_indentclassic_prompt
ipy_prompt	cellmagicassemble_logical_lineshelp_endescaped_commandsassign_from_magicassign_from_systemassemble_python_lines)	tokenutil)
	ESC_SHELL
ESC_SH_CAPESC_HELP	ESC_HELP2	ESC_MAGIC
ESC_MAGIC2	ESC_QUOTE
ESC_QUOTE2	ESC_PARENESC_SEQUENCES|)z^\s+raise(\s.*)?$z^\s+raise\([^\)]*\).*$z^\s+return(\s.*)?$z^\s+return\([^\)]*\).*$z^\s+pass\s*$z^\s+break\s*$z^\s+continue\s*$z^([ \t\r\f\v]+)z^\s*\#c                     [         R                  " SS[        S9  [        R	                  U 5      nU(       a  UR                  5       $ g)zReturn the number of initial spaces in a string.

Note that tabs are counted as a single space.  For now, we do *not* support
mixing of tabs and spaces in the user's input.

Parameters
----------
s : string

Returns
-------
n : int
z`num_ini_spaces` is Pending Deprecation since IPython 8.17.It is considered fro removal in in future version. Please open an issue if you believe it should be kept.   )
stacklevelcategoryr   )warningsr   PendingDeprecationWarningini_spaces_rematchend)s
ini_spacess     T/home/james-whalen/.local/lib/python3.13/site-packages/IPython/core/inputsplitter.pynum_ini_spacesr+   Q   sC     MM	A * $$Q'J~~       c                   "    \ rS rSr\=rrS rSrg)IncompleteStringr   c                 4    Xl         X l        X0l        X@l        g Nr(   startr'   line)selfr(   r4   r'   r5   s        r*   __init__IncompleteString.__init__t   s    
	r,   r'   r5   r(   r4   N)	__name__
__module____qualname____firstlineno__INCOMPLETE_STRINGtype
exact_typer7   __static_attributes__ r,   r*   r/   r/   r   s    ))D:r,   r/   c                   "    \ rS rSr\=rrS rSrg)InMultilineStatementz   c                 :    SU l         U=U l        U l        X l        g N r3   )r6   posr5   s      r*   r7   InMultilineStatement.__init__|   s     ##
TX	r,   r9   N)	r:   r;   r<   r=   IN_MULTILINE_STATEMENTr?   r@   r7   rA   rB   r,   r*   rD   rD   z   s    ..D:r,   rD   c              #   h  #    [         R                  " U 5      R                  n[        R                  " [        R
                  SSSS5      n [        R                  " U5       H  nUv   M	     g	! [        R                   a  nU R                  SS9n[        U5      [        US   5      4nSUR                  S   ;   aD  UR                  =u  pgnXFS-
     US	 SR                  XFS	 5      -   n [        XXTS   5      v    S	nAg	S
UR                  S   ;   a  [        XTS   5      v    S	nAg	e S	nAff = f7f)zIterate over tokens from a possibly-incomplete string of code.

This adds two special token types: INCOMPLETE_STRING and
IN_MULTILINE_STATEMENT. These can only occur as the last token yielded, and
represent the two main ways for code to be incomplete.
rH   )r-   r   T)keependszmulti-line stringr   r-   Nzmulti-line statement)ioStringIOreadlinetokenize	TokenInfoNEWLINEr   generate_tokens_catch_errors
TokenError
splitlineslenargsr'   joinr/   rD   )	r(   rQ   tokenelinesr'   lcr4   s	            r*   partial_tokensr`      s	     {{1~&&Hx//VVRHE;;HEEK F d+%j#eBi.(!&&)+ 99$DA5c
12r!33A"1S)<<#qvvay0&s"I66sC   A	D2!A. -D2.D/A:D*<D2#D*$D2)D**D//D2returnc                    ^ [        [        U 5      5      nUS   R                  [        R                  :X  a  UR                  5         U(       d  gUS   R                  [        R                  [        R                  [        R                  [        R                  1;   aa  UR                  5         US   R                  [        R                  [        R                  [        R                  [        R                  1;   a  Ma  US   R                  [        :X  aW  US   R                  [        R                  1;   a5  UR                  S5        US   R                  [        R                  1;   a  M5  US   R                  [        :X  a  gS/mU4S jn[        U5      nU H  nUR                  [        R                  [        R                  1;   a  U" UR                  S   5        MH  UR                  [        R                  :X  d  Mh   U" [!        U5      R"                  S   5        M     TR                  5       nUS   R                  [        :X  aG  US   R&                  [        R(                  [        R*                  [        R,                  1;   a  US-   $ U$ US   R&                  [        R.                  :X  a  US-   $ U(       a  Sn[1        U5       H*  u  ptUR                  [        R                  :X  d  M%  US-   nM,     XS nU V	s/ s H.  oR                  [        R2                  :X  d  M"  U	R4                  PM0     n
n	U
(       a$  U
S   S;   a  [7        T5       H  nX:  d  M
  Us  $    U$ ! [$         a       GMQ  f = fs  sn	f )	z:Find the number of spaces for the next line of indentationrN   r   c                 <   > U TS   :w  a  TR                  U 5        g g NrN   )append)nprev_indentss    r*   _add_indent%find_next_indent.<locals>._add_indent   s#    R  " !r,   r-      N>   passbreakraisera   continue)listr`   r?   rR   	ENDMARKERpopDEDENTrT   COMMENT
ERRORTOKENrK   NLr>   iterINDENTr'   nextr4   StopIterationr@   LPARLSQBLBRACECOLON	enumerateNAMEstringreversed)codetokensri   tokitertoklast_indentlast_line_startsilast_line_tokenstnamesindentrh   s               @r*   find_next_indentr      s   .&'Fbz(,,,


*//	  	

 *//	  bz00Rjoo(++.JJrN Rjoo(++. bz++ 3L# 6lG8899
#hh(++%DM//23  ""$K bz00":  X]]HMM8??$SS?"bz.Q 'FAxx8+++#$q5  ( ""34#3O#3avv7N#3OU1X!QQ"<0'!M 1 ? ! 0 Ps   M(!M;)M;(
M87M8c                 p    U (       d  gU R                  5       S   nUS:H  =(       d    UR                  5       $ )zDetermine if the input source ends in a blank.

A blank is either a newline or a line consisting of whitespace.

Parameters
----------
src : string
    A single or multiline string.
FrN   rH   )rW   isspace)srclls     r*   
last_blankr      s/     u
..
2
B"H%%r,   z\n\s*\n\s*$z.+\n\s*\n\s+$c                     U (       d  gSR                  S/U R                  5       SS -   5      n[        [        R	                  U5      5      =(       d    [        [
        R	                  U5      5      $ )zDetermine if the input source ends in two blanks.

A blank is either a newline or a line consisting of whitespace.

Parameters
----------
src : string
    A single or multiline string.
F
z###
rc   N)rZ   rW   boollast_two_blanks_rer&   last_two_blanks_re2)r   new_srcs     r*   last_two_blanksr      s`     u ii	CNN$4RS$99:G#))'23 5$**7347r,   c                 2    [         R                  " SSU 5      $ )zRemove all comments from input source.

Note: comments are NOT recognized inside of strings!

Parameters
----------
src : string
    A single or multiline input string.

Returns
-------
String with all Python comments removed.
z#.*rH   )resub)r   s    r*   remove_commentsr     s     66%S!!r,   c                  F    [        [        R                  SS5      n U c  Sn U $ )z_Return the default standard input encoding.

If sys.stdin has no encoding, 'ascii' is returned.encodingNascii)getattrsysstdin)r   s    r*   get_input_encodingr     s&     syy*d3HOr,   c                      \ rS rSr% SrSr\\S   \\\	4   4   \
S'   SrSr\\
S'   Sr\\   \
S'   \\   \
S	'   \R$                  \
S
'   Sr\\   \
S'   Sr\\
S'   SS jrS rS rS rS\S\4S jrS rS\	4S jr\" \5      rSS jrS r Sr!g)InputSplitteri.  a  An object that can accumulate lines of Python source before execution.

This object is designed to be fed python source line-by-line, using
:meth:`push`. It will return on each push whether the currently pushed
code could be executed already. In addition, it provides a method called
:meth:`push_accepts_more` that can be used to query whether more input
can be pushed into a single interactive block.

This is a simple example of how an interactive terminal-based client can use
this tool::

    isp = InputSplitter()
    while isp.push_accepts_more():
        indent = ' '*isp.indent_spaces
        prompt = '>>> ' + indent
        line = indent + raw_input(prompt)
        isp.push(line)
    print 'Input source was:\n', isp.source_reset(),
NN_indent_spaces_cacherH   sourceNr   _buffer_compile_is_completeF_is_invalidra   c                 d    / U l         [        R                  " 5       U l        [	        5       U l        g)z$Create a new InputSplitter instance.N)r   codeopCommandCompilerr   r   r   r6   s    r*   r7   InputSplitter.__init__a  s#    ..0*,r,   c                 Z    / U R                   SS& SU l        SU l        SU l        SU l        gz,Reset the input buffer and associated state.NrH   F)r   r   r   r   r   r   s    r*   resetInputSplitter.resetg  s-    Q	! r,   c                 >    U R                   nU R                  5         U$ )z:Return the input source and perform a full reset.
        )r   r   r6   outs     r*   source_resetInputSplitter.source_reseto  s     kk


r,   c                    U R                  5          U R                  U5        U R                  (       a   U R                  5         gU R                  5       (       a"  SU R	                  5       4U R                  5         $  U R                  5         g! [
         a     U R                  5         gf = f! U R                  5         f = f)a  Return whether a block of code is ready to execute, or should be continued

This is a non-stateful API, and will reset the state of this InputSplitter.

Parameters
----------
source : string
    Python input code, which can be multiline.

Returns
-------
status : str
    One of 'complete', 'incomplete', or 'invalid' if source is not a
    prefix of valid code.
indent_spaces : int or None
    The number of spaces by which to indent the next line of code. If
    status is not 'incomplete', this is None.
)invalidN
incomplete)completeN)r   pushr   push_accepts_moreget_indent_spacesSyntaxError)r6   r   s     r*   check_completeInputSplitter.check_completev  s    & 	

	IIf & JJL ''))#T%;%;%== JJL (JJL  	# # JJL	# JJLs.   B B/ &B/ 
B,B/ +B,,B/ /Cr]   c                 H   [        U[        5      (       d   eU R                  U5        U R                  nSu  U l        U l        SU l        UR                  S5      (       a  g [        R                  " 5          [        R                  " S[        5        U R                  USS9U l        SSS5        U R                  SLU l        U R
                  $ ! , (       d  f       N-= f! [        [        [        [         ["        [        4 a    SU l        SU l         U R
                  $ f = f)	a  Push one or more lines of input.

This stores the given lines and returns a status code indicating
whether the code forms a complete Python block or not.

Any exceptions generated in compilation are swallowed, but if an
exception was produced, the method returns True.

Parameters
----------
lines : string
    One or more lines of Python input.

Returns
-------
is_complete : boolean
    True if the current input source (the result of the current input
    plus prior inputs) forms a complete Python execution block.  Note that
    this value is also stored as a private attribute (``_is_complete``), so it
    can be queried at any time.
r   Fz\
errorexec)symbolNT)
isinstancestr_storer   r   r   r   endswithr#   catch_warningssimplefilterSyntaxWarningr   r   OverflowError
ValueError	TypeErrorMemoryError)r6   r]   r   s      r*   r   InputSplitter.push  s    , %%%%%E
 (2$	4$  ??6""	6((*%%g}= MM&M@	 + !%		 5D   # +* ]J	], 	$ $D#D    	$s*   #C! 81C)C! 
CC! !2D! D!c                    U R                   (       d  gU R                  R                  5       S   nU(       a  UR                  5       (       a  gU R	                  5       S:X  a  [        U R                  R                  5       5      S::  a  g [        R                  " SR                  U R                  5      5      n[        UR                  5      S:X  a  [        UR                  S   S5      (       d  ggg! [         a     gf = f)a7  Return whether a block of interactive input can accept more input.

This method is meant to be used by line-oriented frontends, who need to
guess whether a block is complete or not based solely on prior and
current input lines.  The InputSplitter considers it has a complete
interactive block and will not accept more input when either:

* A SyntaxError is raised

* The code is complete and consists of a single line or a single
  non-compound statement

* The code is complete and has a blank line at the end

If the current input produces a syntax error, this method immediately
returns False but does *not* raise the syntax error exception, as
typically clients will want to send invalid syntax to an execution
backend which might convert the invalid syntax into valid Python via
one of the dynamic IPython mechanisms.
TrN   Fr   r-   rH   body)r   r   rW   r   r   rX   astparserZ   r   r   hasattr	Exception)r6   	last_linecode_asts      r*   r   InputSplitter.push_accepts_more  s    0    KK**,R0	i//11
 !!#q(4;;))+,1	!99RWWT\\%:;
 x}}%*(/a0@&(I(I    s   
/C3 3
D ?D c                     U R                   u  pXR                  :X  a  Uc   eU$ [        U R                  S S 5      nU R                  U4U l         U$ re   )r   r   r   )r6   	sourceforrg   s      r*   r   InputSplitter.get_indent_spaces	  sU    00	#= =H T[["-.%)[[!$4!r,   c                     Uc  U R                   nUR                  S5      (       a  UR                  U5        OUR                  US-   5        [        XU R	                  U5      5        g)zrStore one or more lines of input.

If input lines are not newline-terminated, a newline is automatically
appended.Nr   )r   r   rf   setattr_set_source)r6   r]   bufferstores       r*   r   InputSplitter._store  sR     >\\F>>$MM% MM%*%T--f56r,   c                 $    SR                  U5      $ rG   )rZ   )r6   r   s     r*   r   InputSplitter._set_source(  s    xxr,   )r   r   r   r   r   r   r   r   )ra   N)Nr   )"r:   r;   r<   r=   __doc__r   r   r   r   int__annotations__r   r   r   r   r   r   r   r   r   r   r   r7   r   r   r   r   r   r   propertyindent_spacesr   r   rA   rB   r,   r*   r   r   .  s    2 GQ%j 15c? BCP H FC  $D(8
#
 #Y$$$#'L(4.'K-!"H6! 6! 6!p5n	3 	 ./M7 r,   r   c                      ^  \ rS rSr% SrSrSrSr\\	   \
S'     SU 4S jjr\S 5       r\S 5       rU 4S	 jrS
 rS rS rU 4S jrS rS\	S\4U 4S jjrS rSrU =r$ )IPythonInputSplitteri,  zBAn input splitter that recognizes all of IPython's special syntax.rH   F_buffer_rawc                 v  > [         [        U ]  5         / U l        SU l        Ub  X l        O*[        5       [        5       [        5       [        US9/U l        [        5       U l
        Ub  X0l        O+[        5       [        5       [        5       [        5       /U l        [!        5       U l        Ub  X@l        g / U l        g )NT)end_on_blank_line)superr   r7   r   	_validatephysical_line_transformsr	   r
   r   r   r   logical_line_transformsr   r   r   r   r   python_line_transforms)r6   line_input_checkerr   r   r   	__class__s        r*   r7   IPythonInputSplitter.__init__?  s    "D24#/,D) .<-=-;-=-7\-6I[-\	-.D) '=&>#".+B( -5J,<,>,=,?,>,@	,-D( &;%<"!-*@' +-D'r,   c                     U R                   U R                  /-   U R                  -   U R                  /-   U R                  -   $ )z!Quick access to all transformers.)r   r   r   r   r   r   s    r*   
transformsIPythonInputSplitter.transformsa  sS     ,,(()*,0,H,HI''(),0,G,GH 	Hr,   c                     U R                   SS nU R                  (       d  XR                  /U R                  -   -  nXR                  /-   U R
                  -   $ )zLTransformers, excluding logical line transformers if we're in a
Python line.N)r   within_python_liner   r   r   r   )r6   r   s     r*   transforms_in_use&IPythonInputSplitter.transforms_in_useh  sV     ))!,&&--.1M1MMMA..//$2M2MMMr,   c                    > [         [        U ]  5         / U R                  SS& SU l        SU l        SU l        U R                   H  n UR                  5         M     g! [         a     M&  f = fr   )	r   r   r   r   
source_rawtransformer_accumulatingr  r   r   )r6   r   r   s     r*   r   IPythonInputSplitter.resetq  sj    "D/1 (-%"'A	 !   s   A
A+*A+c                     S n/ nU R                    H  nU" X25      nM     [        U5      nU(       a!  U R                  SR                  U5      5        g g )Nc              3      #    U H4  nUR                  5        H  nU R                  U5      nUc  M  Uv   M     M6     U R                  5       nUb  Uv   gg7f)zyield transformed lines

always strings, never None

transform: the current transform
outs: an iterable of previously transformed inputs.
     Each may be multiline, which will be passed
     one line at a time to transform.
N)rW   r   r   )	transformoutsr   r5   tmps        r*   _flush7IPythonInputSplitter.flush_transformers.<locals>._flush  sW      NN,D#...C!		 -  //#C	 s
   +A%Ar   )r  rp   r   rZ   )r6   r  r   r   s       r*   flush_transformers'IPythonInputSplitter.flush_transformers  sN    	, ''A.C ( 3iKK		#' r,   c                 >    U R                   nU R                  5         U$ )z8Return raw input only and perform a full reset.
        )r  r   r   s     r*   	raw_resetIPythonInputSplitter.raw_reset  s     oo


r,   c                      U R                  5         U R                  U R                  5         $ ! U R                  5         f = fr2   )r  r   r   r   s    r*   r   !IPythonInputSplitter.source_reset  s-    	##%;;JJLDJJLs	   . A c                 L   > U R                   (       a  g[        [        U ]  5       $ NT)r  r   r   r   )r6   r   s    r*   r   &IPythonInputSplitter.push_accepts_more  s     ((-tFHHr,   c                     U R                  5          U R                  U5        U R                  5         U R                  U R                  5         $ ! U R                  5         f = f)z/Process and translate a cell of input.
        )r   r   r  r   )r6   cells     r*   transform_cell#IPythonInputSplitter.transform_cell  sC     	

	IIdO##%;;JJLDJJLs   ,A A!r]   ra   c                 Z  > [        U[        5      (       d   eUR                  5       nU(       d  S/nU R                  XR                  S5        / nU H*  nU R                  U5      nUc  M  UR                  U5        M,     U(       a$  SR                  U5      n[        [        U ]+  U5      $ g)a  Push one or more lines of IPython input.

This stores the given lines and returns a status code indicating
whether the code forms a complete Python block or not, after processing
all input lines for special IPython syntax.

Any exceptions generated in compilation are swallowed, but if an
exception was produced, the method returns True.

Parameters
----------
lines : string
    One or more lines of Python input.

Returns
-------
is_complete : boolean
    True if the current input source (the result of the current input
    plus prior inputs) forms a complete Python execution block.  Note that
    this value is also stored as a private attribute (_is_complete), so it
    can be queried at any time.
rH   r  r   F)r   r   rW   r   r   _transform_linerf   rZ   r   r   r   )r6   r]   
lines_listtransformed_lines_listr5   transformedtransformed_linesr   s          r*   r   IPythonInputSplitter.push  s    . %%%%% %%'
J
 	E++\:!#D..t4K&&--k: 
 " $		*@ A-t9:KLL r,   c                   ^  U 4S jnT R                    H!  nUR                  U5      nUb  M  U" U5      s  $    T R                  (       dW  T R                  R                  U5      nUc  U" S5      $ T R                   H!  nUR                  U5      nUb  M  U" U5      s  $    T R
                  R                  U5      nUc  ST l        U" S5      $ ST l        T R                   H!  nUR                  U5      nUb  M  U" U5      s  $    ST l        U$ )zPush a line of input code through the various transformers.

Returns any output from the transformers, or None if a transformer
is accumulating lines.

Sets self.transformer_accumulating as a side effect.
c                    > STl         g r  )r  )dbgr6   s    r*   _accumulating;IPythonInputSplitter._transform_line.<locals>._accumulating  s    ,0D)r,   zacc logical lineTzacc python lineF)r   r   r  r   r   r   r   r  )r6   r5   r'  transformers   `   r*   r  $IPythonInputSplitter._transform_line  s   	
  88K##D)D|$[11 9
 &&..33D9D|$%788#;;"''-<(55  <
 ))..t4<&*D# !233&+D#66K##D)D|$[11 7 ).%r,   )
r   r   r   r   r   r   r   r  r  r  )TNNN)r:   r;   r<   r=   r   r  r  r  r   r   r   r7   r   r   r  r   r  r  r   r   r  r   r   r  rA   __classcell__)r   s   @r*   r   r   ,  s    L J  % 
 cIMIM -D H H N N (>I	/ / /b* *r,   r   )@r   r#   r   DeprecationWarningr   r   rO   r   r   rR   typingr   r   r   r   typesr   IPython.core.inputtransformerr	   r
   r   r   r   r   r   r   r   r   IPython.utilsr   r   r   r   r   r   r   r   r   r   r   compilerZ   	dedent_rer%   comment_line_rer+   N_TOKENSr>   rK   r/   rD   r`   r   r   r   	MULTILINEr   r   r   r   r   objectr   r   rB   r,   r*   <module>r7     sN  $  l
   	 	 
   / / 
- 
- 
- $Y Y Y JJsxx !  	 

-. **Y'8 %% !**Q.   2Gc GT& ZZ= jj!12<<@ 7."$	{ F { |n= nr,   