
    }e{*                     	   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   Zej$                  d
z   Ze
Z edi dej,                  ej.                  ej,                  ej0                  ej,                  ej2                  ej,                  ej4                  ej,                  ej6                  ej,                  ej8                  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j0                  ej>                  ej2                  ej@                  ej4                  ej:                  ej6                  ejB                  ej8                  ejD                  eejF                  eej>                  dejH                  dejF                  dejH                  dejB                  dejD                  dej:                  dejB                        Z% edi dejD                  ej.                  ejL                  ej0                  ejN                  ej2                  ejN                  ej4                  ejD                  ej6                  ejB                  ej8                  ejD                  eejH                  eejN                  dejN                  dej@                  dejN                  dejB                  dejD                  dej:                  dejB                        Z(ejR                  dk(  re%jU                  d      Z( edi dejD                  ej.                  ejL                  ej0                  ejN                  ej2                  ejN                  ej4                  ejD                  ej6                  ejB                  ej8                  ejD                  eejH                  eejN                  dejN                  dej@                  dejN                  dejB                  dejD                  dej:                  dejB                        Z+ eee%e+e(ge      Z, e-       Z. G d de      Z/y)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header	in_prompt	in_number
in_prompt2	in_normal
out_prompt
out_numbernormalNeutralnt)nameLightBGc                   `     e Zd ZdZdej
                  ddf fd	ZdefdZddZ	d Z
d Z xZS )	r   z# Format colored Python source.
    Nc                     t         t        |   |       |r|nt        | _        || _        d| _        d| _        d| _        |s| j                  | _
        y|| _
        y)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__s        :/usr/lib/python3/dist-packages/IPython/utils/PyColorize.pyr   zParser.__init__   sV     	fd$F$3*5;>
++DJDJ    c                 j    dd l }|t        ur|j                  dd       | j                  ||      d   S )Nr   zThe `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-   s        r)   formatzParser.format   s?    "MM U%&  ( ||C%a((r*   c           	         d}|dk(  s)| j                   dk(  st        | j                   t              r| j                   }t               | _         d}n||| _         nt        d      | j                  dk(  r'd}| j                   j                  |       |r||fS d|fS | j                  | j                     j                  }|| _        |j                         j                         | _
        ddg| _        d}| j                  j                  }| j                  j                  }		  |d	|      dz   }|sn	 |	|        |	t        | j                               d| _        t        | j                        }
d}	 t!        |
j"                        D ]  } | |  	 	 | j                   j                  |j.                  d	z          |r%| j                   j1                         }| _         ||fS d|fS # t$        j&                  $ r}|j(                  d   }|j(                  d   d   }| j                   j                  |t*        j,                     d
|| j                  | j                  |   d |j.                  d	       d}Y d}~d}~ww xY w)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

*** ERROR: )r!   
isinstancer   
ValueErrorr&   writer    colors
expandtabsrstripr$   r#   findappendlenr"   generate_tokensreadlinetokenize
TokenErrorargstoken
ERRORTOKENr   getvalue)r'   r$   r!   string_outputout_olderrorr9   r"   raw_findlines_appendtextatokenexmsglineoutputs                   r)   r0   zParser.format2   sC    %<488u,dhh)
 hhGzDHM_DH[\\ ::"EHHNN3Ez!; !!$**-44 >>#**, V
88==zz((4%)C	 
 	S]# !	)$--8 f 	v}}T)*XX&&(FDHE?"e} "" 	''!*C771:a=DHHNN"5#3#34$**T*:*;!<"MM+ 
 E	s   1G$ $I>7A=I99I>c                 \   t               }|\  }}| j                  }|j                  }t        j                  }	| j
                  }
| j                  |   |z   }|t        |      z   | _        ||
kD  r || j                  |
|        |t        j                  t        j                  fv r(|| _        |j                  d       |j                         S t        j                  |cxk  rt        j                  k  rn nt        j                  }n.|t        j                   k(  rt#        j$                  |      rt&        }|j)                  ||t*                 }|	|v r"|j-                  |	|j.                  |	|      } ||||j.                         |j                  d       |j                         S )z)like call but write to a temporary bufferr   )r   r9   r8   oslinesepr"   r#   r>   r$   rD   INDENTDEDENTseekreadLPAROPNAMEkeyword	iskeyword_KEYWORDget_TEXTreplacer   )r'   toktypetoktext	start_posbuffsrowscolr9   owriterT   oldposnewposcolors                r)   _inner_call_zParser._inner_call_  sX   z
d ** D!D(CL( F?488F6*+ u||U\\22DHIIaL99; ::,EHH,hhG

"w'8'8'AG

7F5M2 goog'-}}WU0D EG 	578		!yy{r*   c                 \    | j                   j                  | j                  |||             y)z) Token handler, with syntax highlighting.N)r!   r8   rl   )r'   rb   rc   rd   end_posrP   s         r)   __call__zParser.__call__H  s$    gw	:	<r*   )N)__name__
__module____qualname____doc__sysstdoutr   r.   r2   r0   rl   ro   __classcell__)r(   s   @r)   r   r      s:     $(szz$d & #9 )JZ)X<r*   )0rs   __all___scheme_defaultr\   rS   rt   rD   rA   r?   IPython.utils.coloransir   r   r   r	   	colorabler   ior   	NT_OFFSETr^   r`   Colorsr   NUMBERrZ   STRINGCOMMENTr[   rE   LightRed	LightCyanYellow	LightBlueNormalRed
LightGreenGreenLinuxColorsCyanBlueNeutralColorsr   copyLightBGColorsr   objectr.   r    r*   r)   <module>r      s  < X
&  	 
  ** ] ]    ??Q??Q
 
  v~~	LLv~~ 
HHv~~ 
LLv~~	
 v~~ 
JJv~~ 
v~~ v~~ 
v~~ .. .. .. .." v~~#$ v~~%( v~~)	0  v	LLv'' 
HHv}} 
LLv''	
 v 
JJv}} 
vzz v(( 
v}} ,, 11 ,, --" vzz#$ v%( v}})0  vzz	LLv{{ 
HHv{{ 
LLv{{	
 vzz 
JJv}} 
vzz v|| 
v{{ ++ 00 ++ --" vzz#$ v%( v}})	> 77d?$$)$4M vzz	LLv{{ 
HHv{{ 
LLv{{	
 vzz 
JJv}} 
vzz v|| 
v{{ ++ 00 ++  --!$ vzz%& v'* v}}+	4 "7;}m"T"13 H	[<Y [<r*   