Your IP : 216.73.216.213


Current Path : /opt/alt/python34/lib64/python3.4/Tools/scripts/__pycache__/
Upload File :
Current File : //opt/alt/python34/lib64/python3.4/Tools/scripts/__pycache__/highlight.cpython-34.pyo

�
e f�#�@s1dZdZddlZddlZddlZddlZddlZddlZdd�Z	dd�Z
dd	�Zd
d�Zid`d6dad6dbd6dcd6ddd6ded6dfd6dgd6Z
e
dd�Zdddd�Zid d!6d"d#6d$d%6d&d'6d(d)6d*d+6d,d-6d.d/6Zd0Zd1eed2d3�Zid4d6d5d6d6d6d7d6d8d6d7d6d9d6d:d6Zd;Zd<d=�Zd1eed>d?�Zed@kr-ddlZddlZddlZddlZddlZejdAddBejdCej 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[�ne$j)Z)e*e)��Z+e+j,�Z-WdQXee-�Z.e$j/r=ee.�Z0nie$j'sOe$j&rdee.d\e)�Z0nBe$j%r|ee.�Z0n*e$j1r�ee.d\e)�Z0nee.�Z0e$j&rej2j3ej2j4e)��dd]Z5e*e5d^��Z+e+j6e0�WdQXej*d_ej2j7e5��q-ej8j6e0�ndS)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/python34/lib64/python3.4/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]�}||}}	|\}}\}
}\}}
}d}|tjkr�d}n�|tj	kr�|dd�dkr�d}n�|tj
krd	}|tjks|dkr�d
}q�nu|tjkr�|dkr@d}q�|	dkrUd}q�t
j|�rmd}q�t|�r�|	dkr�d}q�n|r`t|||
|f�\}}d|fV|||
f}}||fVq`q`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)�def�classzimportzfrom)r r!)�
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

	
!	%				r6cCsGg}x1|D])\}}|jd|p+d|f�q
Wdj|�S)z-Straight text display of text classificationsz
%15s:  %r
Zplainr	)r#r
)�classified_text�resultr2r5rrr�
raw_highlightDs!r9��r�rr�r�rr�rrcCsUg}x?|D]7\}}|j|d�\}}||||g7}q
Wdj|�S)zBAdd syntax highlighting to source code using ANSI escape sequencesr	)r	r	)�getr
)r7Zcolorsr8r2r5�opener�closerrrr�ansi_highlightXs
rCz<pre class="python">
z</pre>
cCs�|g}xZ|D]R\}}|r6|jd|�n|jtj|��|r|jd�qqW|j|�dj|�S)z+Convert classified text to an HTML fragmentz<span class="%s">z</span>r	)r#�html_module�escaper
)r7rArBr8r2r5rrr�html_highlightcs	
rFz{color: crimson;}z.commentz{color: forestgreen;}z.stringz({color: forestgreen; font-style:italic;}z
.docstringz{color: darkorange;}z.keywordz{color: purple;}z.builtinz&{color: darkorange; font-weight:bold;}z.definitionz{color: blue;}z.defnamez{color: brown;}z	.operatora<!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
�itemsrFrDrE�format)r7rLrM�htmlZcss_strr8rrr�build_html_page�s"rRz{\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}
cs:idd6dd6dd6�tjd�fdd	�|�S)
z;Replace backslash and braces with their escaped equivalentsz\{�{z\}�}z\textbackslash{}�\z[\\{}]cs�|j�S)N)�group)Zmo)�xlatrr�<lambda>�szalltt_escape.<locals>.<lambda>)�re�sub)rr)rWr�alltt_escape�sr[c	Cs�djdd�|j�D��}g}xW|D]O\}}|rU|jd|�n|jt|��|r/|jd�q/q/Wttd|d|dd	j|��S)
z;Create a complete LaTeX document with colorized source coderHcss|]}d|VqdS)z\newcommand{\py%s}[1]{%s}Nr)rI�crrr�	<genexpr>�sz"latex_highlight.<locals>.<genexpr>z\py%s{rTrL�macrosrNr	)r
rOr#r[�default_latex_document�dict)r7rLZcommandsZdocumentr^r8r2r5rrr�latex_highlight�s"ra�__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 optionsrLz.html�wzfile://)r:r;)r<r;)r<r;)r=r;)r>r;)r=r;)r?r;)r=r;)9�__doc__�
__author__rr$rQrDrrYr(rrr6r9Zdefault_ansirCrFZdefault_cssZdefault_htmlrRZdefault_latex_commandsr_r[ra�__name__�argparseZos.path�os�sys�textwrapZ
webbrowser�ArgumentParserZRawDescriptionHelpFormatter�dedent�parser�add_argument�
parse_args�argsZsectionZbrowserZcomplete�errorrc�open�f�readr0r7�rawZencodedZlatex�path�splitext�basenameZhtmlfile�write�abspath�stdoutrrrr�<module>s�)	

	

							&