o
    û›h{*  ã                   @   s"  d Z ddgZdZddlZddlZddlZddlZddlZejZddl	m
Z
mZmZmZ ddlmZ dd	lmZ ejd Zejd
 Ze
Zedi dej“ejej“ejej“ejej“ejej“ejej“ejej“eej“eej“dej“dej“dej“dej“dej“dej“dej“ƒZedi dej“ejej“ejej“ejej “ejej“ejej!“ejej"“eej#“eej“dej$“dej#“dej$“dej!“dej"“dej“dej!“ƒZ%edi dej"“ejej&“ejej'“ejej'“ejej"“ejej!“ejej"“eej$“eej'“dej'“dej “dej'“dej!“dej"“dej“dej!“ƒZ(ej)dk�r0e%j*dd�Z(edi dej"“ejej&“ejej'“ejej'“ejej"“ejej!“ejej"“eej$“eej'“dej'“dej “dej'“dej!“dej"“dej“dej!“ƒZ+eee%e+e(geƒZ,e-ƒ Z.G dd„ deƒZ/dS )a]  
Class and program to colorize python source code for ANSI terminals.

Based on an HTML code highlighter by Jurgen Hermann found at:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298

Modifications by Fernando Perez (fperez@colorado.edu).

Information on the original HTML highlighter follows:

MoinMoin - Python Source Parser

Title: Colorize Python source using the built-in tokenizer

Submitter: Jurgen Hermann
Last Updated:2001/04/06

Version no:1.2

Description:

This code is part of MoinMoin (http://moin.sourceforge.net/) and converts
Python source code to HTML markup, rendering comments, keywords,
operators, numeric and string literals in different colors.

It shows how to use the built-in keyword, token and tokenize modules to
scan Python source code and re-emit it with no changes to its original
formatting (which is the hard part).
ÚANSICodeColorsÚParserÚLinuxé    N)Ú
TermColorsÚInputTermColorsÚColorSchemeÚColorSchemeTableé   )Ú	Colorable)ÚStringIOé   ÚNoColorÚheaderZ	in_promptZ	in_numberZ
in_prompt2Z	in_normalZ
out_promptZ
out_numberÚnormalZNeutralÚnt)ÚnameZLightBGc                       sT   e Zd ZdZdejddf‡ fdd„	Zdefdd„Zddd„Z	d	d
„ Z
dd„ Z‡  ZS )r   z# Format colored Python source.
    Nc                    sR   t t| ƒj|d� |r|nt| _|| _d| _d| _d| _|s$| j	| _
dS || _
dS )zr Create a parser with a specified color table and output channel.

        Call format() to process code.
        )ÚparentN)Úsuperr   Ú__init__r   Úcolor_tableÚoutÚposÚlinesÚrawÚdefault_styleÚstyle)Úselfr   r   r   r   ©Ú	__class__© úNc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/PyColorize.pyr   ´   s   
zParser.__init__c                 C   s.   dd l }|tur|jddd� |  ||¡d S )Nr   z˜The `scheme` argument of IPython.utils.PyColorize:Parser.format is deprecated since IPython 6.0.It will have no effect. Set the parser `style` directly.r   )Ú
stacklevel)ÚwarningsÚ	UndefinedÚwarnÚformat2)r   r   r   Úschemer"   r   r   r    ÚformatÇ   s   þzParser.formatc                 C   sÄ  d}|dks| j dkst| j tƒr| j }tƒ | _ d}n|dur#|| _ ntdƒ‚| jdkr>d}| j  |¡ |r:||fS d|fS | j| j j}|| _| ¡  	¡ | _
ddg| _d}| j
j}| jj}		 |d	|ƒd }|sin|	|ƒ q_|	t| j
ƒƒ d| _t| j
ƒ}
d}zt|
jƒD ]}| |Ž  q…W n9 tjyÆ } z,|jd }|jd d }| j  d
|tj || j
| j| d… |jf ¡ d}W Y d}~nd}~ww | j  |jd	 ¡ |rÞ| j  ¡ }|| _ ||fS d|fS )a4   Parse and send the colored source.

        If out and scheme are not specified, the defaults (given to
        constructor) are used.

        out should be a file-type object. Optionally, out can be given as the
        string 'str' and the parser will automatically return the output in a
        string.r   Ústrr	   Nz<`out` or `self.out` should be file-like or the value `"str"`r   FTÚ
z%s

*** ERROR: %s%s%s
)r   Ú
isinstancer   Ú
ValueErrorr   Úwriter   ÚcolorsÚ
expandtabsÚrstripr   r   ÚfindÚappendÚlenr   Úgenerate_tokensÚreadlineÚtokenizeÚ
TokenErrorÚargsÚtokenÚ
ERRORTOKENr   Úgetvalue)r   r   r   Zstring_outputZout_oldÚerrorr-   r   Zraw_findZlines_appendÚtextZatokenÚexÚmsgÚlineÚoutputr   r   r    r%   Ï   sn   

ÿ

ü

ÿ
þÿ€ø	
zParser.format2c                 C   s  t ƒ }|\}}| j}|j}tj}	| j}
| j| | }|t|ƒ | _||
kr.|| j|
|… ƒ |t	j
t	jfv rB|| _| d¡ | ¡ S t	j|  krNt	jkrTn nt	j}n|t	jkr`t |¡r`t}| ||t ¡}|	|v rx| |	d|j|	|f ¡}|d|||jf ƒ | d¡ | ¡ S )z)like call but write to a temporary bufferr   z%s%s%s)r   r-   r,   ÚosÚlinesepr   r   r2   r   r8   ÚINDENTÚDEDENTÚseekÚreadÚLPARÚOPÚNAMEÚkeywordÚ	iskeywordÚ_KEYWORDÚgetÚ_TEXTÚreplacer   )r   ÚtoktypeÚtoktextÚ	start_posZbuffZsrowZscolr-   ZowriterB   ÚoldposZnewposÚcolorr   r   r    Ú_inner_call_  s4   

ÿ
zParser._inner_call_c                 C   s   | j  |  |||¡¡ dS )z) Token handler, with syntax highlighting.N)r   r,   rU   )r   rP   rQ   rR   Úend_posr?   r   r   r    Ú__call__H  s   ÿzParser.__call__)N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚsysÚstdoutr   r#   r'   r%   rU   rW   Ú__classcell__r   r   r   r    r   °   s    
M,)0r[   Ú__all__Z_scheme_defaultrJ   rA   r\   r8   r5   r3   ZIPython.utils.coloransir   r   r   r   Z	colorabler
   Úior   Ú	NT_OFFSETrL   rN   ZColorsr   ÚNUMBERrH   ÚSTRINGÚCOMMENTrI   r9   ZLightRedZ	LightCyanZYellowZ	LightBlueZNormalÚRedZ
LightGreenZGreenZLinuxColorsZCyanZBlueZNeutralColorsr   ÚcopyZLightBGColorsr   Úobjectr#   r   r   r   r   r    Ú<module>   sD  

ÿþýüûúù	÷
öôóòñïîìÿÿþýüûúù	÷
öôóòñïîìÿÿþýüûúù	÷
öôóòñïîìÿÿþýüûúù
öõóòñðîíëÿÿ