3

T'íc÷ã
@sÂUdZddlmZddlmZddlmZmZddlm	Z	ddl
mZddl
m
Z
ddlmZdd	lmZdd
lmZmZddlmZddlmZmZmZmZmZmZmZmZdd
l m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'ddl(m)Z)m*Z*ddl+m,Z,m-Z-e,j.e/ƒZ0iZ1ee2ef1eeddeeddeeddeeddeedddeeddeedddœZ3ee2ef3e4dƒde4dƒde4dƒdiZ5dZ6dZ7e	j8eƒj9d&kr°e6e77Z6Gd#d$„d$ƒZ:d%S)'z%Highlight code blocks using Pygments.é)Úpartial)Ú
import_module)ÚAnyÚDict)Úversion)Ú__version__)Ú	highlight)Ú
ErrorToken)Ú	Formatter)Ú
HtmlFormatterÚLatexFormatter)ÚLexer)ÚCLexerÚPython3LexerÚPythonConsoleLexerÚPythonLexerÚRstLexerÚ	TextLexerÚget_lexer_by_nameÚguess_lexer)ÚStyle)Úget_style_by_name)Ú
ClassNotFound)Ú__)Ú	NoneStyleÚSphinxStyle)ÚloggingÚ	texescapeF)ÚstripnlT)Úpython3r)ÚnoneÚpythonrÚpyconÚpycon3ÚrestÚcú\z	\PYGZbs{}Ú{z	\PYGZob{}Ú}z	\PYGZcb{}z(
\renewcommand\PYGZsq{\textquotesingle}
a
\makeatletter
% fix for Pygments <= 2.7.4
\let\spx@original@fcolorbox\fcolorbox
\def\spx@fixpyg@fcolorbox{\fboxsep-\fboxrule\spx@original@fcolorbox}
\def\PYG#1#2{\PYG@reset\PYG@toks#1+\relax+%
             {\let\fcolorbox\spx@fixpyg@fcolorbox\PYG@do{#2}}}
\makeatother
éééc	@sŽeZdZeZeZdeeeddœdd„Zee	dœdd	„Z
eed
œdd„Z
deeeeeedœdd„Zdeeeeeeedœdd„Zedœdd„ZdS)ÚPygmentsBridgeÚhtmlÚsphinxN)ÚdestÚ	stylenameÚlatex_engineÚreturncCsH||_||_|j|ƒ}d|i|_|dkr2|j|_n|j|_d|jd<dS)NÚstyler-ZPYGZ
commandprefix)r/r1Ú	get_styleÚformatter_argsÚhtml_formatterÚ	formatterÚlatex_formatter)Úselfr/r0r1r3©r:ú5/tmp/pip-build-gk9425m9/sphinx/sphinx/highlighting.pyÚ__init__Es


zPygmentsBridge.__init__)r0r2cCsR|dks|dkrtS|dkr tSd|krF|jddƒ\}}tt|ƒ|ƒSt|ƒSdS)Nr.r Ú.é)rrÚrsplitÚgetattrrr)r9r0Úmoduler:r:r;r4RszPygmentsBridge.get_style)Úkwargsr2cKs|j|jƒ|jf|ŽS)N)Úupdater5r7)r9rBr:r:r;Ú
get_formatter]szPygmentsBridge.get_formatterF)ÚsourceÚlangÚoptsÚforceÚlocationr2cCsÚ|si}|dkr&|jdƒr d}qBd}n|dkrB|jdƒr>d}nd}|tkrRt|S|tkrjt|f|Ž}n^y&|d	kr‚t|f|Ž}nt|f|Ž}Wn6tk
rÆtjtd
ƒ||dtdf|Ž}YnX|sÖ|j	d
ƒ|S)NÚpyr!z>>>r"Úpy3rÚdefaultr#Úguessz#Pygments lexer name %r is not known)rIr Zraiseonerror)rJr!)rKrrL)
Ú
startswithÚlexersÚ
lexer_classesrrrÚloggerÚwarningrZ
add_filter)r9rErFrGrHrIÚlexerr:r:r;Ú	get_lexeras2


zPygmentsBridge.get_lexer)rErFrGrHrIrBr2c

Ks¶t|tƒs|jƒ}|j|||||ƒ}|jf|Ž}yt|||ƒ}	WnTtk
r”|dkrZntjt	dƒ|dd|d|j|d|||ƒ}t|||ƒ}	YnX|j
dkr¤|	Stj|	|j
ƒSdS)NrLz:Could not lex literal_block as "%s". Highlighting skipped.ZmiscZhighlighting_failure)ÚtypeÚsubtyperIr r-)Ú
isinstanceÚstrÚdecoderTrDrr	rQrRrr/rZhlescaper1)
r9rErFrGrHrIrBrSr7Zhlsourcer:r:r;Úhighlight_blockˆs$


zPygmentsBridge.highlight_block)r2cCs,|jƒ}|jdkr|jdƒS|jƒtSdS)Nr-z
.highlight)rDr/Zget_style_defsÚ_LATEX_ADD_STYLES)r9r7r:r:r;Úget_stylesheet¦s

zPygmentsBridge.get_stylesheet)r-r.N)NFN)NFN)Ú__name__Ú
__module__Ú__qualname__rr6rr8rXr<rr4rr
rDrÚboolr
rTrZr\r:r:r:r;r,?s&r,N)r)r*r+);Ú__doc__Ú	functoolsrÚ	importlibrÚtypingrrÚ	packagingrZpygmentsrZpygmentsversionrZpygments.filtersr	Zpygments.formatterr
Zpygments.formattersrrZpygments.lexerr
Zpygments.lexersrrrrrrrrZpygments.stylerZpygments.stylesrZ
pygments.utilrZ
sphinx.localerZsphinx.pygments_stylesrrZsphinx.utilrrÚ	getLoggerr]rQrOrXrPÚordZescape_hl_charsr[Z_LATEX_ADD_STYLES_FIXPYGÚparseÚreleaser,r:r:r:r;Ú<module>sD(