3

V'ícê[ã@sLdZddlZddlZddlZddlZddlmZddlmZm	Z	ddl
mZmZm
Z
mZmZmZmZddlmZmZmZmZmZmZddlmZddlmZmZdd	lmZm Z m!Z!m"Z"m#Z#dd
l$m%Z%ddl&m'Z'm(Z(ddl)m*Z*m+Z+dd
l,m-Z-m.Z.dd„Z/dd„Z0dd„Z1dd„Z2dd„Z3dd„Z4Gdd„dej5ƒZ5ej6fdd„Z7dS)z¼
    pygments.cmdline
    ~~~~~~~~~~~~~~~~

    Command line interface.

    :copyright: Copyright 2006-2022 by the Pygments team, see AUTHORS.
    :license: BSD, see LICENSE for details.
éN)Údedent)Ú__version__Ú	highlight)Ú
ClassNotFoundÚOptionErrorÚdocstring_headlineÚguess_decodeÚguess_decode_from_terminalÚterminal_encodingÚUnclosingTextIOWrapper)Úget_all_lexersÚget_lexer_by_nameÚguess_lexerÚload_lexer_from_fileÚget_lexer_for_filenameÚfind_lexer_class_for_filename)Ú	TextLexer)ÚLatexEmbeddedLexerÚLatexFormatter)Úget_all_formattersÚget_formatter_by_nameÚload_formatter_from_fileÚget_formatter_for_filenameÚfind_formatter_class)ÚTerminalFormatter)ÚTerminal256FormatterÚTerminalTrueColorFormatter)Úget_all_filtersÚfind_filter_class)Úget_all_stylesÚget_style_by_namec
Cs’i}|s|Sx€|D]x}|jƒs q|jdƒ}x^|D]V}|jƒ}y$|jddƒ\}}|jƒ}|jƒ}Wntk
r|d||<Yq0X|||<q0WqW|S)Nú,ú=éT)ÚstripÚsplitÚ
ValueError)Zo_strsÚoptsZo_strZo_argsZo_argZo_keyZo_val©r(ú4/tmp/pip-build-gk9425m9/Pygments/pygments/cmdline.pyÚ_parse_options!s"


r*cCsZg}|s|SxH|D]@}d|krD|jddƒ\}}|j|t|gƒfƒq|j|ifƒqW|S)Nú:r#)r%Úappendr*)Zf_strsÚfiltersZf_strÚfnameÚfoptsr(r(r)Ú_parse_filters6s
r0cCsºyŠ|dkr0t|ƒ}td|jƒtt|jƒƒnX|dkr^t|ƒ}td|jƒtt|jƒƒn*|dkrˆt|ƒ}td|ƒtt|jƒƒdSttfk
r´td|t	j
d	d
SXdS)NÚlexerzHelp on the %s lexer:Ú	formatterzHelp on the %s formatter:ÚfilterzHelp on the %s filter:rz
%s not found!)Úfiler#)r
ÚprintÚnamerÚ__doc__rrÚAttributeErrorr&ÚsysÚstderr)Úwhatr6Úclsr(r(r)Ú_print_helpCs"r=cCsê|dkr”tƒtdƒtdƒg}xJtƒD]@\}}}}dj|ƒd||rZddj|ƒdp\df}|j|ƒq*W|jƒx|D]}td	|ƒq|WnR|d
kr0tƒtdƒtdƒg}xPtƒD]F}t|ƒ}	dj|jƒd|	|jröddj|jƒdpødf}|j|ƒqÀW|jƒxÒ|D]}td	|ƒqWn¶|d
krŒtƒtdƒtdƒx”t	ƒD].}
t
|
ƒ}td|
dƒtdt|ƒƒqXWnZ|dkrætƒtdƒtdƒx8tƒD].}
t|
ƒ}td|
dƒtdt|ƒƒq´WdS)Nr1zLexers:z~~~~~~~z, r+z(filenames ú)Úz* %s
    %s %sr2zFormatters:z~~~~~~~~~~~r3zFilters:z~~~~~~~~z* z    %sÚstylezStyles:)
r5rÚjoinr,ÚsortrrÚaliasesÚ	filenamesrrrr )r;ÚinfoÚfullnameÚnamesÚextsÚ_ÚtupÚir<Údocr6r(r(r)Ú_print_listWsR




rMcCsddl}i}d|krHi}x&tƒD]\}}}}|||dœ||<q W||d<d|krŠi}x,tƒD]"}t|ƒ}	|j|j|	dœ||j<q\W||d<d|krÆi}x&tƒD]}
t|
ƒ}d	t|ƒi||
<qžW||d
<d|kri}x&t	ƒD]}
t
|
ƒ}d	t|ƒi||
<qÜW||d<|j|tj
ƒdS)
Nrr1)rCrDÚ	mimetypesZlexersr2)rCrDrLÚ
formattersr3rLr-r@Zstyles)ÚjsonrrrrCrDr6rrrr Údumpr9Ústdout)Zrequested_itemsrPÚresultrErFrGrDrNr<rLr6r(r(r)Ú_print_list_as_jsonŠs<
rTc&‰s
ˆjr|jƒd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r>y\d}d}	d|krÞ|j/ddƒ\}}	d|	krÞd}	|rú|	rút<||	f|
Ž}nt<|f|
Ž}Wn2t#k
r:}ztd|tjddSd}~XnXnHyt)|f|
Ž}Wn6t2t#fk
r„}ztd|tjddSd}~XnX|r|sÚyt=|f|
Ž}Wn6t2t#fk
rØ}ztd|tjddSd}~XnXyt4|d"ƒ} Wn2t5k
r}ztd#|tjddSd}~XnXnX|snt>j?jd$dƒd3krDt@f|
Ž}n*d't>j?jd(dƒkrdtAf|
Ž}n
tBf|
Ž}tjCj } |s–|rŠ|
|_DntEtjCƒ|_D|	rtjFd4k	r|jGd5k	rtH| |jDd-} d|_DyddlI}!WntJk
rìYnX|!jKjL| ddd.dd/} |
jd0dƒ}"tM|"ƒdk	rFtN|tOƒ	rF|"d}#|"d}$tP|#|$|ƒ}ˆj3	svztQ|||| ƒWd|	rp| jRƒXdSztyXxRtjj jSƒ}%|%	sP|
	s¦t9|%tjƒd}%tQ|%||| ƒtT| d1ƒ	r|| jUƒ	q|WdStVk
	rædSXWd|	rú| jRƒXdS)6NruWPygments version %s, (c) 2006-2022 by Georg Brandl, Matthäus Chajdas and contributors.cs t‡fdd„tˆƒjƒDƒƒS)Nc3s|]\}}|ˆkr|VqdS)Nr()Ú.0ÚkÚv)Úoptr(r)ú	<genexpr>Ász5main_inner.<locals>.is_only_option.<locals>.<genexpr>)ÚanyÚvarsÚitems)rX)Úargns)rXr)Úis_only_optionÀsz"main_inner.<locals>.is_only_optionÚLrPér?z-Vr1r2r3r@cSsg|]}|jdƒ‘qS)Ús)Úrstrip)rUÚargr(r(r)ú
<listcomp>Õszmain_inner.<locals>.<listcomp>c3s|]}|ˆkVqdS)Nr()rUrc)Ú
allowed_typesr(r)rYÖszmain_inner.<locals>.<genexpr>ÚHr"r#TÚ
inencodingÚencodingÚoutencoding)rg)r4z.pyr+zError:z5Error: -s option not usable when input file specifiedÚrbzError: cannot read infile:z7Error: when using -s a lexer has to be selected with -lÚwbzError: cannot open outfile:Z	COLORTERMÚ	truecolorÚ24bitZ256ÚTERMÚwin32ÚcygwinÚTerminalÚTerminal256)rhF)Úconvertr$Ú	autoresetÚwrapÚescapeinsideÚflush)r1r2r3)rlrm)rorp)rqrr)WÚhelpÚ
print_helpÚVr5rr_Úsetr[r\ÚaddÚdiscardr9r:rPÚmainrZrMrTrfr=r*ÚOÚPr%r&ÚgetÚNrrrCÚCÚstdinÚbufferÚreadrrÚSÚaÚfÚlÚ	INPUTFILErZget_style_defsr0ÚFÚboolÚxÚrsplitrr
rraÚopenÚ	ExceptionrrÚgr	Z
add_filterÚorrÚosÚenvironrrrrRrhr
Úplatformr6rZcolorama.initialiseÚImportErrorÚ
initialiseÚwrap_streamÚlenÚ
isinstancerrrÚcloseÚreadlineÚhasattrrwÚKeyboardInterrupt)&Úparserr]r^Zarg_setrVrWÚlargsrcr;r6Zparsed_optsZp_optÚvaluergrir1ÚinpZS_optZa_optZf_optZfmterÚerrZF_optsZallow_custom_lexer_formatterZ	lexernameÚfilenameÚcodeZinfnÚinfpr.r/ZoutfnÚoutfileÚcoloramarvÚleftÚrightÚliner()rer]r)Ú
main_inner¶sà




















r­c@seZdZddd„ZdS)Ú
HelpFormatterr`éNcCsH|dkr0ytjƒjd}Wntk
r.YnXtjj|||||ƒdS)Nr`)ÚshutilÚget_terminal_sizeÚcolumnsr‘Úargparser®Ú__init__)ÚselfÚprogÚindent_incrementÚmax_help_positionÚwidthr(r(r)r´szHelpFormatter.__init__)r`r¯N)Ú__name__Ú
__module__Ú__qualname__r´r(r(r(r)r®sr®cCsÚd}tj|dtd}|jdƒ}|jƒ}|jdddd|jd	d
dd|jd
dddd|jdddd|jddddd|jddddd|jdddd|jddd d!|jd"ƒ}|jd#d
d$d|jd%d
d&d|jd'd
d(d|jd)d*dd
d+|jd,ƒ}|jƒ}|jd-d.d/d|jd0d1d2d3d4|jd5d6d7d|jd8d
d9d|jd:d;d<dVd?d@|jdAd
dBd|jdCdDd
dEd|jdFdGdHd|j|dIdJ…ƒ}y
t||ƒStk
rÄdKSt	k
rÔ|j
rDttj
dLtd1dMtj
dLtdNtj
dLtdOtj
dLtdPtj
dLtd1dMtj
dLttj
dL‚dKdJl}	|	jtjƒŽ}
|
dWjƒ}t|
ƒdQkrš|dR|
dXjdSƒdKjƒdIdJ…7}ttj
dLtdTtj
dLt|tj
dLtdUtj
dLdISXdJS)Yz(
    Main command line entry point.
    z?Highlight an input file and write the result to an output file.F)ÚdescriptionÚadd_helpÚformatter_classzMain operationz-lZLEXERz~Specify the lexer to use.  (Query names with -L.)  If not given and -g is not present, the lexer is guessed from the filename.)Úmetavarrxz-gÚ
store_truez`Guess the lexer from the file contents, or pass through as plain text if nothing can be guessed.)Úactionrxz-FzFILTER[:options]r,znAdd a filter to the token stream.  (Query names with -L.) Filter options are given after a colon if necessary.)rÀrÂrxz-fZ	FORMATTERzÜSpecify the formatter to use.  (Query names with -L.) If not given, the formatter is guessed from the output filename, and defaults to the terminal formatter if the output is to the terminal or an unknown file extension.z-OzOPTION=value[,OPTION=value,...]zyGive options to the lexer and formatter as a comma-separated list of key-value pairs. Example: `-O bg=light,python=cool`.z-PzOPTION=valuez·Give a single option to the lexer and formatter - with this you can pass options whose value contains commas and equal signs. Example: `-P "heading=Pygments, the Python highlighter"`.z-oZ
OUTPUTFILEz8Where to write the output.  Defaults to standard output.r‹ú?z5Where to read the input.  Defaults to standard input.)ÚnargsrxzOperation flagsz-vzbPrint a detailed traceback on unhandled exceptions, which is useful for debugging and bug reports.z-sa!Process lines one at a time until EOF, rather than waiting to process the entire file.  This only works for stdin, only for lexers with no line-spanning constructs, and is intended for streaming input such as you get from `tail -f`. Example usage: `tail -f sql.log | pygmentize -s -l sql`.z-xa«Allow custom lexers and formatters to be loaded from a .py file relative to the current working directory. For example, `-l ./customlexer.py -x`. By default, this option expects a file with a class named CustomLexer or CustomFormatter; you can also specify your own class name with a colon (`-l ./lexer.py:MyLexer`). Users should be very careful not to use this option with untrusted files, because it will import and run them.z--jsonz=Output as JSON. This can be only used in conjunction with -L.)rxÚdefaultrÂz*Special modes - do not do any highlightingz-SzSTYLE -f formatterzqPrint style definitions for STYLE for a formatter given with -f. The argument given by -a is formatter dependent.z-LÚ*ZWHATz›List lexers, formatters, styles or filters -- give additional arguments for the thing(s) you want to list (e.g. "styles"), or omit them to list everything.)rÄrÀrxz-NZFILENAMEzªGuess and print out a lexer name based solely on the given filename. Does not take input or highlight anything. If no specific lexer can be determined, "text" is printed.z-CzXLike -N, but print out a lexer name based solely on a given content from standard input.z-HÚstorer`ÚNAMEÚTYPEzrPrint detailed help for the object <name> of type <type>, where <type> is one of "lexer", "formatter" or "filter".)rÂrÄrÀrxz-VzPrint the package version.z-hz--helpzPrint this help.z-aZARGzKFormatter-specific additional argument for the -S (print style sheet) mode.r#Nr)r4éAz3An unhandled exception occurred while highlighting.z9Please report the whole traceback to the issue tracker atz.<https://github.com/pygments/pygments/issues>.éz	
   (f%s)Ú
z*** Error while highlighting:z>*** If this is a bug you want to report, please rerun with -v.)rÈrÉéÿÿÿÿéþÿÿÿ)r³ÚArgumentParserr®Úadd_argument_groupÚadd_mutually_exclusive_groupÚadd_argumentÚ
parse_argsr­ÚBrokenPipeErrorr‘rWr5r9r:Ú	tracebackÚformat_exceptionÚexc_infor$ršr%)ÚargsÚdescr Z	operationZlexerselÚflagsZspecial_modes_groupZ
special_modesr]rÕrEÚmsgr(r(r)r~sÄ





&
r~)8r7r”r9r°r³ÚtextwraprZpygmentsrrZ
pygments.utilrrrrr	r
rZpygments.lexersrr
rrrrZpygments.lexers.specialrZpygments.formatters.latexrrZpygments.formattersrrrrrZpygments.formatters.terminalrZpygments.formatters.terminal256rrZpygments.filtersrrZpygments.stylesrr r*r0r=rMrTr­r®Úargvr~r(r(r(r)Ú<module>	s2$ 
3,Q