Your IP : 216.73.217.129


Current Path : /opt/alt/python37/lib64/python3.7/Tools/scripts/__pycache__/
Upload File :
Current File : //opt/alt/python37/lib64/python3.7/Tools/scripts/__pycache__/highlight.cpython-37.opt-1.pyc

B

� f�#�	@s�dZdZddlZddlZddlZddlZddlZddlZdd�Z	dd�Z
dd	�Zd
d�Zdd
d
dddddd�Z
e
fdd�ZdNdd�Zddddddddd �Zd!Zd"eefd#d$�Zd%d&d'd(d)d(d*d+d�Zd,Zd-d.�Zd"eefd/d0�Zed1k�r�ddlZddlZddlZddlZddlZejdeje� d2�d3�Z!e!j"d4d5d6d7�e!j"d8d9d:d;d<�e!j"d=d>d:d?d<�e!j"d@dAd:dBd<�e!j"dCdDd:dEd<�e!j"dFdGd:dHd<�e!�#�Z$e$j%�r�e$j&�s�e$j'�r�e!�(dI�e$j)Z)e*e)��Z+e+�,�Z-WdQRXee-�Z.e$j/�r�ee.�Z0nNe$j'�s
e$j&�ree.e)dJ�Z0n0e$j%�r*ee.�Z0ne$j1�r@ee.e)dJ�Z0nee.�Z0e$j&�r�ej2�3ej2�4e)��ddKZ5e*e5dL��Z+e+�6e0�WdQRXe�*dMej2�7e5��nej8�6e0�dS)Oz-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/python37/lib64/python3.7/Tools/scripts/highlight.py�
is_builtinsrcCs|||\}}\}}||kr2||d||�|fS||d|d�g|||d�||dd|�g}d�|�|fS)z8Join content from a range of lines between start and end�N�)�join)�lines�start�end�srow�scol�erow�ecolZrowsrrr�
combine_ranges
<rccsx|�d�}|�d�t�tt|�d�}d}}tj}d}�xt�|�D�]
}||}}	|\}}\}
}\}}
}d}|tjkr�d}n�|tj	kr�|dd�dkr�d}nx|tj
kr�d	}|tjks�|d
kr�d}nR|tjk�r|dkr�d
}n8|	dkr�d}n*t
�|��rd}nt|��r|	dk�rd}|rFt|||
|f�\}}d|fV|||
f}}||fVqFWt||||
f�\}}d|fVdS)z�Generate and classify chunks of Python for syntax highlighting.
       Yields tuples in the form: (category, categorized_text).
    Tr	)rr�commentNrz{}[](),.:;@�operator�stringr�	docstring)�def�class�import�from�
definition)rr�defname�keyword�.�builtin)�
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





r4cCs6g}x&|D]\}}|�d|pd|f�q
Wd�|�S)z-Straight text display of text classificationsz
%15s:  %r
Zplainr	)r!r
)�classified_text�resultr0r3rrr�
raw_highlightDsr7)zz)zz)zz)zz)zz)rrrrrrrrcCs>g}x.|D]&\}}|�|d�\}}||||g7}q
Wd�|�S)zBAdd syntax highlighting to source code using ANSI escape sequences)r	r	r	)�getr
)r5Zcolorsr6r0r3�opener�closerrrr�ansi_highlightXs
r;�<pre class="python">
�</pre>
cCs\|g}x@|D]8\}}|r&|�d|�|�t�|��|r|�d�qW|�|�d�|�S)z+Convert classified text to an HTML fragmentz<span class="%s">z</span>r	)r!�html_module�escaper
)r5r9r:r6r0r3rrr�html_highlightcs
r@z{color: crimson;}z{color: forestgreen;}z({color: forestgreen; font-style:italic;}z{color: darkorange;}z{color: purple;}z&{color: darkorange; font-weight:bold;}z{color: blue;}z{color: brown;})z.commentz.stringz
.docstringz.keywordz.builtinz.definitionz.defnamez	.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>
�pythoncCs:d�dd�|��D��}t|�}t�|�}|j|||d�S)z6Create a complete HTML page with colorized source code�
cSsg|]}d|�qS)z%s %sr)�.0�itemrrr�
<listcomp>�sz#build_html_page.<locals>.<listcomp>)�title�css�body)r
�itemsr@r>r?�format)r5rFrG�htmlZcss_strr6rrr�build_html_page�s
rLz{\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"dddd��t�d�fdd�|�S)z;Replace backslash and braces with their escaped equivalentsz\{z\}z\textbackslash{})�{�}�\z[\\{}]cs�|��S)N)�group)Zmo)�xlatrr�<lambda>��zalltt_escape.<locals>.<lambda>)�re�sub)rr)rQr�alltt_escape�srVcCstd�dd�|��D��}g}x>|D]6\}}|r<|�d|�|�t|��|r"|�d�q"Wtt||d�|�d�S)z;Create a complete LaTeX document with colorized source coderBcss|]}d|VqdS)z\newcommand{\py%s}[1]{%s}Nr)rC�crrr�	<genexpr>�sz"latex_highlight.<locals>.<genexpr>z\py%s{rNr	)rF�macrosrH)r
rIr!rV�default_latex_document�dict)r5rFZcommandsZdocumentrYr6r0r3rrr�latex_highlight�sr\�__main__aa
                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

            )ZdescriptionZformatter_classZepilog�
sourcefileZ
SOURCEFILEz!file containing Python sourcecode)�metavar�helpz-bz	--browser�
store_truez launch a browser to show results)�actionr`z-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 options)rFz.html�wzfile://)r<r=)9�__doc__�
__author__rr"rKr>rrTr&rrr4r7Zdefault_ansir;r@Zdefault_cssZdefault_htmlrLZdefault_latex_commandsrZrVr\�__name__�argparseZos.path�os�sys�textwrapZ
webbrowser�ArgumentParserZRawDescriptionHelpFormatter�dedent�parser�add_argument�
parse_args�argsZsectionZbrowserZcomplete�errorr^�open�f�readr.r5�rawZencodedZlatex�path�splitext�basenameZhtmlfile�write�abspath�stdoutrrrr�<module>s�)