Format: application/x-python-code
⬇ Download File (6.1 KB)
   1  o
   2  
   3  ��h{*�@s"dZddgZdZddlZddlZddlZddlZddlZejZddl	m
   4  Z
   5  mZmZm
   6  Z
   7  ddlmZdd	lmZejdZejd
   8  Ze
   9  Zedidej�ejej�ejej�ejej�ejej�ejej�ejej�eej�eej�d
  10  ej�dej�dej�dej�dej�dej�dej��Zedidej�ejej�ejej�ejej �ejej�ejej!�ejej"�eej#�eej�d
  11  ej$�dej#�dej$�dej!�dej"�dej�dej!��Z%edidej"�ejej&�ejej'�ejej'�ejej"�ejej!�ejej"�eej$�eej'�d
  12  ej'�dej �dej'�dej!�dej"�dej�dej!��Z(ej)dk�r0e%j*dd�Z(edidej"�ejej&�ejej'�ejej'�ejej"�ejej!�ejej"�eej$�eej'�d
  13  ej'�dej �dej'�dej!�dej"�dej�dej!��Z+e
  14  ee%e+e(ge�Z,e-�Z.Gdd�de�Z/dS)a]
  15  Class and program to colorize python source code for ANSI terminals.
  16  
  17  Based on an HTML code highlighter by Jurgen Hermann found at:
  18  http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52298
  19  
  20  Modifications by Fernando Perez (fperez@colorado.edu).
  21  
  22  Information on the original HTML highlighter follows:
  23  
  24  MoinMoin - Python Source Parser
  25  
  26  Title: Colorize Python source using the built-in tokenizer
  27  
  28  Submitter: Jurgen Hermann
  29  Last Updated:2001/04/06
  30  
  31  Version no:1.2
  32  
  33  Description:
  34  
  35  This code is part of MoinMoin (http://moin.sourceforge.net/) and converts
  36  Python source code to HTML markup, rendering comments, keywords,
  37  operators, numeric and string literals in different colors.
  38  
  39  It shows how to use the built-in keyword, token and tokenize modules to
  40  scan Python source code and re-emit it with no changes to its original
  41  formatting (which is the hard part).
  42  �ANSICodeColors�Parser�Linux�N)�
  43  TermColors�InputTermColors�ColorScheme�ColorSchemeTable�)�	Colorable)�StringIO��NoColor�headerZ	in_promptZ	in_numberZ
  44  in_prompt2Z	in_normalZ
  45  out_promptZ
  46  out_number�normalZNeutral�nt)�nameZLightBGcsTeZdZdZdejddf�fdd�	Zdefdd�Zd
  47  dd�Z	d	d
  48  �Z
  49  dd�Z�ZS)rz# Format colored Python source.
  50      NcsRtt|�j|d�|r
  51  |nt|_||_d|_d|_d|_|s$|j	|_
  52  dS||_
  53  dS)zr Create a parser with a specified color table and output channel.
  54  
  55          Call format() to process code.
  56          )�parentN)�superr�__init__r�color_table�out�pos�lines�raw�
  57  default_style�style)�selfrrrr��	__class__��Nc:\Users\shubh\Videos\agent\nova\Lib\site-packages\IPython/utils/PyColorize.pyr�s
  58  zParser.__init__cCs.ddl}|tur|jddd�|�||�dS)Nrz�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)�
  59  stacklevel)�warnings�	Undefined�warn�format2)rrr�schemer"rrr �format�s�z
  60  Parser.formatcCs�d}|dks|jdkst|jt�r|j}t�|_d}n|dur#||_ntd��|jdkr>d}|j�|�|r:||fSd|fS|j|jj}||_|���	�|_
  61  ddg|_d}|j
  62  j}|jj
  63  }		|d	|�d}|sin|	|�q_|	t|j
  64  ��d|_t|j
  65  �}
  66  d}zt|
  67  j�D]}||�q�Wn9tjy�}z,|jd}
  68  |jdd}|j�d
  69  |tj|
  70  |j
  71  |j|d�|jf�d}WYd}~nd}~ww|j�|jd	�|r�|j��}||_||fSd|fS)a4 Parse and send the colored source.
  72  
  73          If out and scheme are not specified, the defaults (given to
  74          constructor) are used.
  75  
  76          out should be a file-type object. Optionally, out can be given as the
  77          string 'str' and the parser will automatically return the output in a
  78          string.r�strr	Nz<`out` or `self.out` should be file-like or the value `"str"`r
  79  FT�
  80  z%s
  81  
  82  *** ERROR: %s%s%s
  83  )r�
  84  isinstancer�
  85  ValueErrorr�writer�colors�
  86  expandtabs�rstriprr�find�append�lenr�generate_tokens�readline�tokenize�
  87  TokenError�args�token�
  88  ERRORTOKENr�getvalue)rrrZ
  89  string_outputZout_old�errorr-rZraw_findZlines_append�textZatoken�ex�msg�line�outputrrr r%�sn
  90  
  91  �
  92  
  93  �
  94  
  95  �
  96  ����	
  97  zParser.format2c
  98  Cst�}|\}}|j}|j}tj}	|j}
  99  |j||}|t|�|_||
 100  kr.||j|
 101  |��|t	j
 102  t	jfvrB||_|�d�|�
 103  �St	j|krNt	jkrTnnt	j}n|t	jkr`t�|�r`t}|�||t�}|	|vrx|�|	d|j|	|f�}|d|||jf�|�d�|�
 104  �S)z)like call but write to a temporary bufferrz%s%s%s)rr-r,�os�lineseprrr2rr8�INDENT�DEDENT�seek�read�LPAR�OP�NAME�keyword�	iskeyword�_KEYWORD�get�_TEXT�replacer)
 105  r�toktype�toktext�	start_posZbuffZsrowZscolr-ZowriterB�oldposZnewpos�colorrrr �_inner_call_s4
 106  
 107  �
 108  zParser._inner_call_cCs|j�|�|||��dS)z) Token handler, with syntax highlighting.N)rr,rU)rrPrQrR�end_posr?rrr �__call__Hs�zParser.__call__)N)
 109  �__name__�
 110  __module__�__qualname__�__doc__�sys�stdoutrr#r'r%rUrW�
 111  __classcell__rrrr r�s
 112  M,)0r[�__all__Z_scheme_defaultrJrAr\r8r5r3ZIPython.utils.coloransirrrrZ	colorabler
 113  �ior�	NT_OFFSETrLrNZColorsr
 114  �NUMBERrH�STRING�COMMENTrIr9ZLightRedZ	LightCyanZYellowZ	LightBlueZNormal�RedZ
 115  LightGreenZGreenZLinuxColorsZCyanZBlueZ
 116  NeutralColorsr�copyZ
 117  LightBGColorsr�objectr#rrrrr �<module>sD
 118  
 119  �������	�
 120  ��
 121  ��������������	�
 122  ��
 123  ��������������	�
 124  ��
 125  ��������������
 126  ��
 127  ���������