
    MhL                         d Z dZddlZddlmZmZmZmZmZm	Z	m
Z
mZ ddlmZmZmZmZmZmZ ddlmZmZmZmZmZmZmZmZ  ej        d          Zg dZd	 eeee ee
                    fd
 eeee ee
                    fd eeee ee                    fd eeee ee                    fd eeee ee                    fd eeee ee                    fd eeee ee                    fd eeee ee
                    fd eeee ee
                    fd eeee ee	                    fd eeee ee
                    fd eeee ee
                    fd eeee ee                    fd eeee ee
                    fd eeee ee
                    fd eeee ee
                    fd eeee ee
                    fd eeeee          fd eeee ee                    fd eeee          fd eee          fd eee ee          e          fd eeee          fd  ee ee          e          fd! ee ee          e          fd" eeee          fd# eeee          fgZ G d$ d%e
          Z e Z! G d& d'e          Z" G d( d)e          Z# G d* d+e          Z$ G d, d-e          Z%dS ).a;  
Defines a variety of Pygments lexers for highlighting IPython code.

This includes:

    IPythonLexer, IPython3Lexer
        Lexers for pure IPython (python + magic/shell commands)

    IPythonPartialTracebackLexer, IPythonTracebackLexer
        Supports 2.x and 3.x via keyword `python3`.  The partial traceback
        lexer reads everything but the Python code appearing in a traceback.
        The full lexer combines the partial lexer with an IPython lexer.

    IPythonConsoleLexer
        A lexer for IPython console sessions, with support for tracebacks.

    IPyLexer
        A friendly lexer which examines the first line of text and from it,
        decides whether to use an IPython lexer or an IPython console lexer.
        This is probably the only lexer that needs to be explicitly added
        to Pygments.

z1.1.1    N)	BashLexer	HtmlLexerJavascriptLexer	RubyLexer	PerlLexerPython2LexerPython3LexerTexLexer)LexerDelegatingLexer
RegexLexerdo_insertionsbygroupsusing)GenericKeywordLiteralNameOperatorOtherTextErrorz.*?
)IPython3LexerIPythonLexerIPythonPartialTracebackLexerIPythonTracebackLexerIPythonConsoleLexerIPyLexerz"(?s)(\s*)(%%capture)([^\n]*\n)(.*)z (?s)(\s*)(%%debug)([^\n]*\n)(.*)z (?is)(\s*)(%%html)([^\n]*\n)(.*)z%(?s)(\s*)(%%javascript)([^\n]*\n)(.*)z(?s)(\s*)(%%js)([^\n]*\n)(.*)z (?s)(\s*)(%%latex)([^\n]*\n)(.*)z(?s)(\s*)(%%perl)([^\n]*\n)(.*)z(?s)(\s*)(%%prun)([^\n]*\n)(.*)z(?s)(\s*)(%%pypy)([^\n]*\n)(.*)z"(?s)(\s*)(%%python2)([^\n]*\n)(.*)z"(?s)(\s*)(%%python3)([^\n]*\n)(.*)z!(?s)(\s*)(%%python)([^\n]*\n)(.*)z(?s)(\s*)(%%ruby)([^\n]*\n)(.*)z!(?s)(\s*)(%%timeit)([^\n]*\n)(.*)z(?s)(\s*)(%%time)([^\n]*\n)(.*)z$(?s)(\s*)(%%writefile)([^\n]*\n)(.*)z(?s)(\s*)(%%file)([^\n]*\n)(.*)z(?s)(\s*)(%%)(\w+)(.*)z(?s)(^\s*)(%%!)([^\n]*\n)(.*)z(%%?)(\w+)(\?\??)$z\b(\?\??)(\s*)$z(%)(sx|sc|system)(.*)(\n)z(%)(\w+)(.*\n)z^(!!)(.+)(\n)z(!)(?!=)(.+)(\n)z!^(\s*)(\?\??)(\s*%{0,2}[\w\.\*]*)z!(\s*%{0,2}[\w\.\*]*)(\?\??)(\s*)$c                   l    e Zd ZdZdZddgZej                                        Ze	ed         z   ed<   dS )r   z&IPython code lexer (based on Python 3)IPythonipythonipython3rootN)
__name__
__module____qualname____doc__namealiasesr	   tokenscopyipython_tokens     W/var/www/html/test/jupyter/venv/lib/python3.11/site-packages/ipython_pygments_lexers.pyr   r      sI        00D*%G %%''F#fVn4F6NNNr.   r   c                      e Zd ZdZdZdd eeej                  fd eej        e	j
        ej        ej        j                  fd ee	j        ej        e          fd ee	j
        ee	j        e	j                  fd eej        ej        j        e          fd	 ee	j        ej        j        e          fd
 ee	j        e          fdefgiZdS )r   zX
    Partial lexer for IPython tracebacks.

    Handles all the non-python output.

    zIPython Partial Tracebackr#   z^(\^C)?(-+\n)z^(  File)(.*)(, line )(\d+\n)z&(?u)(^[^\d\W]\w*)(\s*)(Traceback.*?\n)z(.*)( in )(.*)(\(.*\)\n)z(\s*?)(\d+)(.*?\n)z(-*>?\s?)(\d+)(.*?\n)z(?u)(^[^\d\W]\w*)(:.*?\n)z.*\nN)r$   r%   r&   r'   r(   r   r   r   	Tracebackr   	Namespacer   NumberInteger	Exception
Whitespacer   EntityTagr   r*   r-   r.   r/   r   r      s$         'D 	 xxw/@AAB 1%N%N*	  :);TBB ,t{DHEE &+W^-CUKK ))?GG
 *88DND+I+IJe]/
1FFFr.   r   c                   $    e Zd ZdZdZddgZd ZdS )r   aA  
    IPython traceback lexer.

    For doctests, the tracebacks can be snipped as much as desired with the
    exception to the lines that designate a traceback. For non-syntax error
    tracebacks, this is the line of hyphens. For syntax error tracebacks,
    this is the line which lists the File and line number.

    zIPython Traceback	ipythontb
ipython3tbc                 B    t          j        | t          t          fi | dS )z
        A subclass of `DelegatingLexer` which delegates to the appropriate to either IPyLexer,
        IPythonPartialTracebackLexer.
        N)r   __init__r   r   selfoptionss     r/   r=   zIPythonTracebackLexer.__init__  s8     	 -!=	
 	
AH	
 	
 	
 	
 	
r.   N)r$   r%   r&   r'   r(   r)   r=   r-   r.   r/   r   r      s>           DL)G

 

 

 

 

r.   r   c                   n    e Zd ZdZdZddgZdgZdZdZdZ	 e
j        d	          Zd
 Zd Zd Zd Zd ZdS )r   a  
    An IPython console lexer for IPython code-blocks and doctests, such as:

    .. code-block:: rst

        .. code-block:: ipythonconsole

            In [1]: a = 'foo'

            In [2]: a
            Out[2]: 'foo'

            In [3]: print(a)
            foo


    Support is also provided for IPython exceptions:

    .. code-block:: rst

        .. code-block:: ipythonconsole

            In [1]: raise Exception
            Traceback (most recent call last):
            ...
            Exception

    zIPython console sessionipythonconsoleipython3consoleztext/x-ipython-consolezIn \[[0-9]+\]: z   \.\.+\.: zOut\[[0-9]+\]: z+^(\^C)?(-+\n)|^(  File)(.*)(, line )(\d+\n)c                 H   |                     d| j                  }|                     d| j                  }|                     d| j                  }|                                dz   }|                                dz   }|                                dz   }g d}|D ]<}	|                     |	t          j        t                      |	                              =t          j
        | fi | t          di || _        t          di || _        |                                  dS )ak  Initialize the IPython console lexer.

        Parameters
        ----------
        in1_regex : RegexObject
            The compiled regular expression used to detect the start
            of inputs. Although the IPython configuration setting may have a
            trailing whitespace, do not include it in the regex. If `None`,
            then the default input prompt is assumed.
        in2_regex : RegexObject
            The compiled regular expression used to detect the continuation
            of inputs. Although the IPython configuration setting may have a
            trailing whitespace, do not include it in the regex. If `None`,
            then the default input prompt is assumed.
        out_regex : RegexObject
            The compiled regular expression used to detect outputs. If `None`,
            then the default output prompt is assumed.

        	in1_regex	in2_regex	out_regex
)rE   rF   rG   in1_regex_rstripin2_regex_rstripout_regex_rstripNr-   )getrE   rF   rG   rstrip__setattr__recompilelocalsr   r=   r   pylexerr   tblexerreset)
r?   r@   rE   rF   rG   rI   rJ   rK   attrsattrs
             r/   r=   zIPythonConsoleLexer.__init__E  s*   ( KKT^<<	KKT^<<	KKT^<<	 %++--4$++--4$++--4
 
 
  	? 	?DT2:fhhtn#=#=>>>>t''w'''$//w//,77w77

r.   c                 >    d| _         d| _        d| _        g | _        d S )Noutputr    )modeindexbuffer
insertions)r?   s    r/   rT   zIPythonConsoleLexer.reset|  s"    	
r.   c              #     K   | j         dk    rdt          j        | j        fg}nJ| j         dk    r | j                            | j                  }n| j                            | j                  }t          | j        |          D ]\  }}}| j	        |z   ||fV  | xj	        t          | j                  z  c_	        d| _        g | _        dS )zu
        Generator of unprocessed tokens after doing insertions and before
        changing to a new state.

        rX   r   inputrY   N)rZ   r   Outputr\   rR   get_tokens_unprocessedrS   r   r]   r[   len)r?   r*   itvs        r/   buffered_tokensz#IPythonConsoleLexer.buffered_tokens  s       9  '.$+67FFY'!!\88EEFF\88EEF$T_f== 	' 	'GAq!*q.!Q&&&&& 	

c$+&&&

r.   c                    | j                             |          }| j                            |          }|r<|                                                                |                                k    s|rd}nd}|r#| j        dk    rd}d}dt          j        |f}|||fS | j                            |          }| j	                            |          }	|s|	rSd}|r|
                                }
n|	
                                }
||
d         }dt          j        |d|
         f}|||fS | j                            |          }|s|r^| j        dk    rSd}|r|
                                }
n|
                                }
||
d         }dt          j        |d|
         f}|||fS | j                            |          }|s|r^| j        dk    rSd}|r|
                                }
n|
                                }
||
d         }dt          j        |d|
         f}|||fS | j                            |          rd}|}d}|||fS | j        d	v rd}nd}|}d}|||fS )
a  
        Parses the line and returns a 3-tuple: (mode, code, insertion).

        `mode` is the next mode (or state) of the lexer, and is always equal
        to 'input', 'output', or 'tb'.

        `code` is a portion of the line that should be added to the buffer
        corresponding to the next mode and eventually lexed by another lexer.
        For example, `code` could be Python code if `mode` were 'input'.

        `insertion` is a 3-tuple (index, token, text) representing an
        unprocessed "token" that will be inserted into the stream of tokens
        that are created from the buffer once we change modes. This is usually
        the input or output prompt.

        In general, the next mode depends on current mode and on the contents
        of `line`.

        TFtbrX   rY   r   Nr_   )r_   rX   )rF   matchrJ   grouprM   rZ   r   PromptrG   rK   endHeadingrE   rI   ipytb_start)r?   line	in2_matchin2_match_rstrip	end_inputrZ   code	insertion	out_matchout_match_rstripidx	in1_matchin1_match_rstrips                r/   get_mcizIPythonConsoleLexer.get_mci  s   0 N((..	066t<<	#//++2244EE FIII 	)d** DDGND1Iy(( N((..	066t<< 
	)( 
	)D -mmoo&**,,:D GOT$3$Z8Iy(( N((..	 	) 	)tyD'8'8 D &mmoommoo:DGND#J7Iy((  066t<< 	) 0 	)TY$5F5F D -&**,,&**,,:DGND#J7Iy(( !!$'' 	)DDIy(( 9+++ DDD	T9$$r.   c              #     K   |                                   t                              |          D ]}|                                }|                     |          \  }}}|| j        k    r"|                                 D ]}|V  || _        |r/| j                            t          | j
                  |gf           | xj
        |z  c_
        |                                 D ]}|V  d S )N)rT   line_refinditerrj   rz   rZ   rf   r]   appendrb   r\   )r?   textri   ro   rZ   rs   rt   tokens           r/   ra   z*IPythonConsoleLexer.get_tokens_unprocessed  s     

%%d++ 	  	 E;;==D$(LL$6$6!D$	ty  !1133    EKKKK 	 H&&DK(8(89+'FGGGKK4KKK))++ 	 	EKKKK	 	r.   N)r$   r%   r&   r'   r(   r)   	mimetypesrE   rF   rG   rO   rP   rn   r=   rT   rf   rz   ra   r-   r.   r/   r   r     s         : %D!23G)*I #II"I "*KLLK5 5 5n    ,s% s% s%j    r.   r   c                   *    e Zd ZdZdZddgZd Zd ZdS )r   ao  
    Primary lexer for all IPython-like code.

    This is a simple helper lexer.  If the first line of the text begins with
    "In \[[0-9]+\]:", then the entire text is parsed with an IPython console
    lexer. If not, then the entire text is parsed with an IPython lexer.

    The goal is to reduce the number of lexers that are registered
    with Pygments.

    zIPy sessionipyipy3c                 n    t          j        | fi | t          di || _        t          di || _        dS )z
        Create a new IPyLexer instance which dispatch to either an
        IPythonCOnsoleLexer (if In prompts are present) or and IPythonLexer (if
        In prompts are not present).
        Nr-   )r   r=   r   r   r>   s     r/   r=   zIPyLexer.__init__1  sN     	t''w'''(33733#6#A#A#A#A   r.   c              #      K   t          j        d|                                t           j                  r| j        }n| j        }|                    |          D ]}|V  d S )Nz.*(In \[[0-9]+\]:))rO   ri   stripDOTALLr   r   ra   )r?   r   lexr   s       r/   ra   zIPyLexer.get_tokens_unprocessed>  sm       8)4::<<CC 	$*CC#C//55 	 	EKKKK	 	r.   N)r$   r%   r&   r'   r(   r)   r=   ra   r-   r.   r/   r   r   !  sO        
 
 DfoGB B B    r.   r   )&r'   __version__rO   pygments.lexersr   r   r   r   r   r   r	   r
   pygments.lexerr   r   r   r   r   r   pygments.tokenr   r   r   r   r   r   r   r   rP   r|   __all__r,   r   r   r   r   r   r   r-   r.   r/   <module>r      s   >  
				 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	               	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 "*W

   	.xuu\':':;;
 	,xuu\':':;;
 	,xuuY'7'788
 	1xuu_'='=>>
 	)xuu_'='=>>
 	,xuuX77
 	+xuuY'7'788
 	+xuu\':':;;
 	+xuu\':':;;
 	.xuu\':':;;
 	.xuu\':':;;
 	-xuu\':':;;
 	+xuuY'7'788
 	-xuu\':':;;
 	+xuu\':':;;
 	0xuu\':':;;
 	+xuu\':':;; x$ G GH(xuuY'7'788 HHXwAAB(D112!88HguuY?O?OQU#V#VW7D99:xx%%	*:*:DAAB((8UU9-=-=tDDE)88D(D+I+IJ)88D(D+I+IJcRj5 5 5 5 5L 5 5 5 ; ; ; ; ;: ; ; ;|
 
 
 
 
O 
 
 
BL L L L L% L L L^% % % % %u % % % % %r.   