Your IP : 216.73.216.213


Current Path : /opt/alt/python35/lib64/python3.5/Tools/scripts/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/Tools/scripts/__pycache__/highlight.cpython-35.opt-1.pyc



��Yf�#�@sdZdZddlZddlZddlZddlZddlZddlZdd�Z	dd�Z
dd	�Zd
d�Zdd`ddaddbddcdddddeddfddgiZ
e
dd�Zdddd�Zd d!d"d#d$d%d&d'd(d)d*d+d,d-d.d/iZd0Zd1eed2d3�Zdd4dd5dd6dd7dd8dd7dd9dd:iZd;Zd<d=�Zd1eed>d?�Zed@krddlZddlZddlZddlZddlZejdAddBejdCej dD��Z!e!j"dEdFdGdHdI�e!j"dJdKdLdMdHdN�e!j"dOdPdLdMdHdQ�e!j"dRdSdLdMdHdT�e!j"dUdVdLdMdHdW�e!j"dXdYdLdMdHdZ�e!j#�Z$e$j%r�e$j&s�e$j'r�e!j(d[�e$j)Z)e*e)��Z+e+j,�Z-WdQRXee-�Z.e$j/r#ee.�Z0nie$j's5e$j&rJee.d\e)�Z0nBe$j%rbee.�Z0n*e$j1r�ee.d\e)�Z0nee.�Z0e$j&rej2j3ej2j4e)��dd]Z5e*e5d^��Z+e+j6e0�WdQRXej*d_ej2j7e5��nej8j6e0�dS)hz-Add syntax highlighting to Python source codezRaymond Hettinger�NcCs
tt|�S)z)Return True if s is the name of a builtin)�hasattr�builtins)�s�r�</opt/alt/python35/lib64/python3.5/Tools/scripts/highlight.py�
is_builtinsrcCs�||\}}\}}||krA||d||�|fS||d|d�g|||d�||dd|�g}dj|�|fS)z8Join content from a range of lines between start and end�N�)�join)�lines�start�end�srow�scol�erow�ecolZrowsrrr�
combine_ranges
Frccs|jd�}|jd�tjtt|�d�}d}}tj}d}x�tj|�D]u}||}}	|\}}\}
}\}}
}d}|tjkr�d}n�|tj	kr�|dd�dkr�d}n�|tj
krd	}|tjks|dkr�d
}no|tjkr�|dkr=d}nK|	dkrRd}n6t
j|�rjd}nt|�r�|	dkr�d}|r`t|||
|f�\}}d|fV|||
f}}||fVq`Wt||||
f�\}}d|fVdS)z�Generate and classify chunks of Python for syntax highlighting.
       Yields tuples in the form: (category, categorized_text).
    Tr	rr�commentNz{}[](),.:;@�operator�string�	docstring�def�class�import�from�
definition�defname�keyword�.�builtin)rr)rrrr)rr)�
splitlines�append�	functools�partial�next�iter�tokenize�COMMENT�generate_tokens�OP�STRING�INDENT�NAMEr�	iskeywordrr)�sourcer�readline�kindZtok_str�tok_typeZwritten�tokZ
prev_tok_typeZprev_tok_strrrrrZlogical_lineno�textZline_upto_tokenrrr�analyze_pythonsD

	
!	%					r4cCsGg}x1|D])\}}|jd|p+d|f�q
Wdj|�S)z-Straight text display of text classificationsz
%15s:  %r
Zplainr	)r!r
)�classified_text�resultr0r3rrr�
raw_highlightDs!r7r��r�rr�r�rr�rcCsUg}x?|D]7\}}|j|d�\}}||||g7}q
Wdj|�S)zBAdd syntax highlighting to source code using ANSI escape sequencesr	)r	r	)�getr
)r5Zcolorsr6r0r3�opener�closerrrr�ansi_highlightXs
rAz<pre class="python">
z</pre>
cCsz|g}xT|D]L\}}|r3|jd|�|jtj|��|r|jd�qW|j|�dj|�S)z+Convert classified text to an HTML fragmentz<span class="%s">z</span>r	)r!�html_module�escaper
)r5r?r@r6r0r3rrr�html_highlightcs	
rDz.commentz{color: crimson;}z.stringz{color: forestgreen;}z
.docstringz({color: forestgreen; font-style:italic;}z.keywordz{color: darkorange;}z.builtinz{color: purple;}z.definitionz&{color: darkorange; font-weight:bold;}z.defnamez{color: blue;}z	.operatorz{color: brown;}a<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
          "http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-type" content="text/html;charset=UTF-8">
<title> {title} </title>
<style type="text/css">
{css}
</style>
</head>
<body>
{body}
</body>
</html>
�pythoncCsYdjdd�|j�D��}t|�}tj|�}|jd|d|d|�S)z6Create a complete HTML page with colorized source code�
cSsg|]}d|�qS)z%s %sr)�.0�itemrrr�
<listcomp>�s	z#build_html_page.<locals>.<listcomp>�title�css�body)r
�itemsrDrBrC�format)r5rJrK�htmlZcss_strr6rrr�build_html_page�s"rPz{\color{red}#1}z{\color{ForestGreen}#1}z{\emph{\color{ForestGreen}#1}}z{\color{orange}#1}z{\color{purple}#1}z{\color{blue}#1}z{\color{brown}#1}a
\documentclass{article}
\usepackage{alltt}
\usepackage{upquote}
\usepackage{color}
\usepackage[usenames,dvipsnames]{xcolor}
\usepackage[cm]{fullpage}
%(macros)s
\begin{document}
\center{\LARGE{%(title)s}}
\begin{alltt}
%(body)s
\end{alltt}
\end{document}
cs7ddddddi�tjd�fdd	�|�S)
z;Replace backslash and braces with their escaped equivalents�{z\{�}z\}�\z\textbackslash{}z[\\{}]cs�|j�S)N)�group)Zmo)�xlatrr�<lambda>�szalltt_escape.<locals>.<lambda>)�re�sub)rr)rUr�alltt_escape�srYc	Cs�djdd�|j�D��}g}xQ|D]I\}}|rR|jd|�|jt|��|r/|jd�q/Wttd|d|dd	j|��S)
z;Create a complete LaTeX document with colorized source coderFcss|]}d|VqdS)z\newcommand{\py%s}[1]{%s}Nr)rG�crrr�	<genexpr>�sz"latex_highlight.<locals>.<genexpr>z\py%s{rRrJ�macrosrLr	)r
rMr!rY�default_latex_document�dict)r5rJZcommandsZdocumentr\r6r0r3rrr�latex_highlight�s"r_�__main__ZdescriptionZformatter_classZepilogaa
                examples:

                  # Show syntax highlighted code in the terminal window
                  $ ./highlight.py myfile.py

                  # Colorize myfile.py and display in a browser
                  $ ./highlight.py -b myfile.py

                  # Create an HTML section to embed in an existing webpage
                  ./highlight.py -s myfile.py

                  # Create a complete HTML file
                  $ ./highlight.py -c myfile.py > myfile.html

                  # Create a PDF using LaTeX
                  $ ./highlight.py -l myfile.py | pdflatex

            �
sourcefile�metavarZ
SOURCEFILE�helpz!file containing Python sourcecodez-bz	--browser�action�
store_truez launch a browser to show resultsz-cz
--completezbuild a complete html webpagez-lz--latexzbuild a LaTeX documentz-rz--rawzraw parse of categorized textz-sz	--sectionz3show an HTML section rather than a complete webpagezVThe -s/--section option is incompatible with the -b/--browser or -c/--complete optionsrJz.html�wzfile://)r8r9)r:r9)r:r9)r;r9)r<r9)r;r9)r=r9)r;r9)9�__doc__�
__author__rr"rOrBrrWr&rrr4r7Zdefault_ansirArDZdefault_cssZdefault_htmlrPZdefault_latex_commandsr]rYr_�__name__�argparseZos.path�os�sys�textwrapZ
webbrowser�ArgumentParserZRawDescriptionHelpFormatter�dedent�parser�add_argument�
parse_args�argsZsectionZbrowserZcomplete�errorra�open�f�readr.r5�rawZencodedZlatex�path�splitext�basenameZhtmlfile�write�abspath�stdoutrrrr�<module>s�)



		
					&