
    fQ                     :   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 ddlmZ  ej:                  d      Zg dZd	 Z  e d
      Z! e d      Z" G d de      Z# G d de      Z$ G d de      Z% G d de      Z&y)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.

    N)	BashLexer	HtmlLexerJavascriptLexer	RubyLexer	PerlLexerPythonLexerPython3LexerTexLexer)LexerDelegatingLexer
RegexLexerdo_insertionsbygroupsusing)GenericKeywordLiteralNameOperatorOtherTextError)get_bool_optz.*?
)build_ipy_lexerIPython3LexerIPythonLexerIPythonPartialTracebackLexerIPythonTracebackLexerIPythonConsoleLexerIPyLexerc                  $   | rt         }d}dg}d}nt        }d}ddg}d}dt        t        t        t        t        |            fd	t        t        t        t        t        |            fd
t        t        t        t        t        t                    fdt        t        t        t        t        t                    fdt        t        t        t        t        t                    fdt        t        t        t        t        t                    fdt        t        t        t        t        t                    fdt        t        t        t        t        |            fdt        t        t        t        t        |            fdt        t        t        t        t        |            fdt        t        t        t        t        t                    fdt        t        t        t        t        t                     fdt        t        t        t        t        t                    fdt        t        t        t        t        |            fdt        t        t        t        t        |            fdt        t        t        t        t        |            fdt        t        t        t        t        |            fdt        t        t        t        t              fdt        t        t        t        t        t                    fdt        t        t        t              fdt        t        t              fdt        t        t        t        t              t              fdt        t        t        t              fdt        t        t        t              t              fd t        t        t        t              t              fd!t        t        t        t              fd"t        t        t        t              fg}|j                  j                         }||d#   z   |d#<   ||g ||d$}t        ||f|      S )%a_  Builds IPython lexers depending on the value of `python3`.

    The lexer inherits from an appropriate Python lexer and then adds
    information about IPython specific keywords (i.e. magic commands,
    shell commands, etc.)

    Parameters
    ----------
    python3 : bool
        If `True`, then build an IPython lexer from a Python 3 lexer.

    IPython3ipython3zIPython3 LexerIPythonipython2ipythonzIPython Lexerz"(?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*)(%%python)([^\n]*\n)(.*)z"(?s)(\s*)(%%python2)([^\n]*\n)(.*)z"(?s)(\s*)(%%python3)([^\n]*\n)(.*)z(?s)(\s*)(%%ruby)([^\n]*\n)(.*)z(?s)(\s*)(%%time)([^\n]*\n)(.*)z!(?s)(\s*)(%%timeit)([^\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*)$root)namealiases	filenames__doc__tokens)r	   r   r   r   r   r   r   r   r
   r   r   r   r   r,   copytype)python3PyLexerr(   r)   docipython_tokensr,   attrss           M/var/www/cvtools/html/venv/lib/python3.12/site-packages/IPython/lib/lexers.pyr   r   9   s     ,"y)! 	.xheT[n/]^	,htXtUSZ^.\]	,htXtUS\M].^_	18D(DRWXgRh3ij	)8D(D%P_J`+ab	,htXtUS[_.]^	+XdHdER[L\-]^	+XdHdERYN-[\	+XdHdERYN-[\	-xheT[n/]^	.xuU`Oa0bc	.xuUaOb0cd	+XdHdER[L\-]^	+XdHdERYN-[\	-xheT[n/]^	0(44QVW^Q_2`a	+XdHdERYN-[\	"HT8Wd$KL	)8D(D%PYJZ+[\	(GX!FG	hx67	%x'05i0@$(H 	I	HXw=>	8HeI.>EF	hxy1A4HI	-xh/MN	-xh/MN9N> ^^  "F#fVn4F6NgBv/E wj%((    T)r/   Fc                   $   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y)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)__name__
__module____qualname__r+   r(   r   r   r   	Tracebackr   	Namespacer   NumberInteger	Exception
Whitespacer   EntityTagr   r,    r5   r4   r   r      s     'D 	 xw/@/@AB-g'''')?)?AB
 7dnng&8&8$?A )dnndDKKBD #g(('..*@*@%HJ &dnngnn&<&<eDF *dnnd+- eE#
%Fr5   r   c                        e Zd ZdZdZdgZd Zy)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	ipythontbc                     t        |dd      | _        | j                  r	dg| _        n	ddg| _        | j                  rt        }nt        }t        j                  | |t        fi | y)z
        A subclass of `DelegatingLexer` which delegates to the appropriate to either IPyLexer,
        IPythonPartialTracebackLexer.
        r/   F
ipython3tb
ipython2tbrD   N)r   r/   r)   r   r   r   __init__r   )selfoptionsr    s      r4   rH   zIPythonTracebackLexer.__init__   s`     $GY><<(>DL(+6DL<<$H#H  x!=	JAH	Jr5   N)r7   r8   r9   r+   r(   r)   rH   rB   r5   r4   r   r      s     DmGJr5   r   c                   n    e Zd ZdZdZ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y)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ipythonconsoleztext/x-ipython-consolezIn \[[0-9]+\]: z   \.\.+\.: zOut\[[0-9]+\]: z+^(\^C)?(-+\n)|^(  File)(.*)(, line )(\d+\n)c                    t        |dd      | _        | j                  r	dg| _        n	ddg| _        |j                  d| j                        }|j                  d| j
                        }|j                  d| j                        }|j                         d	z   }|j                         d	z   }|j                         d	z   }g d
}|D ]2  }	| j                  |	t        j                  t               |	                4 t        j                  | fi | | j                  rt        }
t        }nt         }
t        } |
di || _         |di || _        | j'                          y)a  Initialize the IPython console lexer.

        Parameters
        ----------
        python3 : bool
            If `True`, then the console inputs are parsed using a Python 3
            lexer. Otherwise, they are parsed using a Python 2 lexer.
        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.

        r/   Fipython3consoleipython2consolerL   	in1_regex	in2_regex	out_regex
)rP   rQ   rR   in1_regex_rstripin2_regex_rstripout_regex_rstripNrB   )r   r/   r)   getrP   rQ   rR   rstrip__setattr__recompilelocalsr   rH   r   r   r   pylexertblexerreset)rI   rJ   rP   rQ   rR   rT   rU   rV   r3   attrr]   r^   s               r4   rH   zIPythonConsoleLexer.__init__  s7   . $GY><<-.DL-/?@DLKKT^^<	KKT^^<	KKT^^<	 %++-4$++-4$++-4M 	?DT2::fhtn#=>	? 	t'w'<<#G+G"G+G))))

r5   c                 <    d| _         d| _        d| _        g | _        y )Noutputr    )modeindexbuffer
insertions)rI   s    r4   r_   zIPythonConsoleLexer.resetM  s    	
r5   c              #     K   | j                   dk(  rdt        j                  | j                  fg}nZ| j                   dk(  r&| j                  j                  | j                        }n%| j                  j                  | j                        }t        | j                  |      D ]  \  }}}| j                  |z   ||f  | xj                  t        | j                        z  c_	        d| _        g | _        yw)zu
        Generator of unprocessed tokens after doing insertions and before
        changing to a new state.

        rb   r   inputrc   N)rd   r   Outputrf   r]   get_tokens_unprocessedr^   r   rg   re   len)rI   r,   itvs        r4   buffered_tokensz#IPythonConsoleLexer.buffered_tokensS  s      99 '..$++67FYY'!\\88EF\\88EF$T__f= 	'GAq!**q.!Q&&	'
 	

c$++&&
s   C3C5c                    | j                   j                  |      }| j                  j                  |      }|r/|j                         j	                         |j	                         k(  s|rd}nd}|r+| j
                  dk7  rd}d}dt        j                  |f}|||fS | j                  j                  |      }| j                  j                  |      }	|s|	rEd}|r|j                         }
n|	j                         }
||
d }dt        j                  |d|
 f}|||fS | j                  j                  |      }|s|rT| j
                  dk7  rEd}|r|j                         }
n|j                         }
||
d }dt        j                  |d|
 f}|||fS | j                  j                  |      }|s|rT| j
                  dk7  rEd}|r|j                         }
n|j                         }
||
d }dt        j                  |d|
 f}|||fS | j                  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tbrb   rc   r   Nri   )ri   rb   )rQ   matchrU   grouprX   rd   r   PromptrR   rV   endHeadingrP   rT   ipytb_start)rI   line	in2_matchin2_match_rstrip	end_inputrd   code	insertion	out_matchout_match_rstripidx	in1_matchin1_match_rstrips                r4   get_mcizIPythonConsoleLexer.get_mcii  sm   0 NN((.	0066t<)//+224EIId* DDGNND1Iy(( NN((.	0066t<(Dmmo&**,:D GOOT$3Z8Iy(( NN((.	tyyD'8 Dmmommo:DGNND#J7Iy((  0066t< 0TYY$5F D&**,&**,:DGNND#J7Iy(( !!$'DDIy(( 99++ DD	T9$$r5   c              #     K   | j                          t        j                  |      D ]  }|j                         }| j	                  |      \  }}}|| j
                  k7  r | j                         D ]  }|  || _        |r1| j                  j                  t        | j                        |gf       | xj                  |z  c_
         | j                         D ]  }|  y w)N)r_   line_refinditerrt   r   rd   rp   rg   appendrl   rf   )rI   textrs   ry   rd   r}   r~   tokens           r4   rk   z*IPythonConsoleLexer.get_tokens_unprocessed  s     

%%d+ 	 E;;=D$(LL$6!D$	tyy !113  EK  	&&DKK(89+'FGKK4K	  ))+ 	EK	s   C!C#N)r7   r8   r9   r+   r(   r)   	mimetypesrP   rQ   rR   rZ   r[   rx   rH   r_   rp   r   rk   rB   r5   r4   r   r      s^    8 %D G)*I #II"I "**KLK?B,s%jr5   r   c                   &    e Zd ZdZdZdgZd Zd Zy)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ipyc                     t        |dd      | _        | j                  r	dg| _        n	ddg| _        t        j                  | fi | t        di || _        t        di || _        y)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).
        r/   Fipy3ipy2r   NrB   )r   r/   r)   r   rH   r   r   )rI   rJ   s     r4   rH   zIPyLexer.__init__   s`     $GY><<"8DL"E?DLt'w'(373#6#A#A r5   c              #      K   t        j                  d|j                         t         j                        r| j                  }n| j
                  }|j                  |      D ]  }|  y w)Nz.*(In \[[0-9]+\]:))rZ   rs   stripDOTALLr   r   rk   )rI   r   lexr   s       r4   rk   zIPyLexer.get_tokens_unprocessed  sX      88)4::<C**C##C//5 	EK	s   A(A*N)r7   r8   r9   r+   r(   r)   rH   rk   rB   r5   r4   r    r      s     
 DgGB&r5   r    )'r+   rZ   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   pygments.utilr   r[   r   __all__r   r   r   r   r   r   r    rB   r5   r4   <module>r      s   @ 
      ' "**W
.
@)F  -u-.: .b'JO 'JRU% Un*u *r5   