o aZ@sHdZddlZddlZddlZddlZddlmZddlmZm Z ddl m Z m Z m Z mZmZmZmZddlmZmZmZmZmZmZddlmZddlmZmZdd lmZm Z m!Z!m"Z"m#Z#dd l$m%Z%dd l&m'Z'dd l(m)Z)m*Z*dd l+m,Z,m-Z-ddZ.ddZ/ddZ0ddZ1ddZ2ddZ3Gdddej4Z4ej5fddZ6dS)z pygments.cmdline ~~~~~~~~~~~~~~~~ Command line interface. :copyright: Copyright 2006-2021 by the Pygments team, see AUTHORS. :license: BSD, see LICENSE for details. N)dedent) __version__ highlight) ClassNotFound OptionErrordocstring_headline guess_decodeguess_decode_from_terminalterminal_encodingUnclosingTextIOWrapper)get_all_lexersget_lexer_by_name guess_lexerload_lexer_from_fileget_lexer_for_filenamefind_lexer_class_for_filename) TextLexer)LatexEmbeddedLexerLatexFormatter)get_all_formattersget_formatter_by_nameload_formatter_from_fileget_formatter_for_filenamefind_formatter_class)TerminalFormatter)Terminal256Formatter)get_all_filtersfind_filter_class)get_all_stylesget_style_by_namec Csi}|s|S|D]9}|sq|d}|D]*}|}z|dd\}}|}|}Wn ty;d||<Yqw|||<qq|S)N,=T)stripsplit ValueError)o_strsoptso_stro_argso_argo_keyo_valr-2/usr/lib/python3/dist-packages/pygments/cmdline.py_parse_options!s&      r/cCsVg}|s|S|D] }d|vr!|dd\}}||t|gfq||ifq|S)N:r")r$appendr/)f_strsfiltersf_strfnamefoptsr-r-r._parse_filters6sr7c CszJ|dkrt|}td|jtt|jWdS|dkr3t|}td|jtt|jWdS|dkrHt|}td|tt|jWdSttfy_td|t j d Yd Sw) NlexerzHelp on the %s lexer: formatterzHelp on the %s formatter:filterzHelp on the %s filter:rz %s not found!filer") r printnamer__doc__rrAttributeErrorr%sysstderr)whatr>clsr-r-r. _print_helpCs(  rEc Cs|dkrFttdtdg}tD] \}}}}d|d||r,dd|dp-df}||q||D]}td |q;dS|d krttd td g}tD]#}t|} d|jd| |jrudd|jdpvdf}||qZ||D]}td |qdS|d krttdtdt D]} t | }td| dtdt|qdS|dkrttdtdt D]} t | }td| dtdt|qdSdS)Nr8zLexers:z~~~~~~~z, r0z (filenames )z* %s %s %sr9z Formatters:z ~~~~~~~~~~~r:zFilters:z~~~~~~~~z* z %sstylezStyles:) r=r joinr1sortrraliases filenamesrrrr) rCinfofullnamenamesexts_tupirDdocr>r-r-r. _print_listWsd     rUc Csddl}i}d|vr"i}tD]\}}}}|||d||<q||d<d|vrAi}tD]}t|} |j|j| d||j<q+||d<d|vr]i}tD]} t| }d t|i|| <qJ||d <d |vryi}t D]} t | }d t|i|| <qf||d <| |t j dS) Nrr8)rKrL mimetypeslexersr9)rKrLrT formattersr:rTr3rHstyles)jsonr rrrKrLr>rrrrdumprAstdout) requested_itemsrZresultrMrNrOrLrVrDrTr>r-r-r._print_list_as_jsonsD      r_c& sr jr |dSjrtdtdSfdd}jdurt}tD] \}}|r3| |q(| d| d|rH|t j dSj sQtdd ghd d d jD}tfd d|Drp|t j dS|st}j s|D]}t|qydSt|dSjr|ds|t j dSj\}} |dvr|t j dSt|| Stjpg} jpgD]} z | dd\} } Wn tyd| | <Yqw| | | <q| d| d} | d| d}jrtj}|durt}t|jddSjr*t jj !}zt"|| d}Wn t#y t}Ynwt|jddSj$}j%}|durj&}|sC|t j dSj'sKj(rS|t j dSz|| d<t)|fi| }Wnt#y|}zt|t j dWYd}~dSd}~wwt|*|pddSj%dur|t j dSt+j,pg}t-j.}d}j'}|r,|rd|vrz2d}d} d|vr|/dd\}} d| vrd} |r| rt0|| fi| }nt0|fi| }WnEt#y}ztd|t j dWYd}~dSd}~wwz t1|fi| }Wnt2t#fy+}ztd|t j dWYd}~dSd}~wwd}j(rj3r?tdt j ddSj(}zt4|d }|!}Wdn 1sXwYWnt5yz}ztd|t j dWYd}~dSd}~ww| st6|\}} |sz t7||fi| }Wnt#y}z5j8rz t"|fi| }Wn t#ytd,i| }Ynwtd|t j dWYd}~dSWYd}~nbd}~wt2y}ztd|t j dWYd}~dSd}~wwnAj3s&t jj !}| st9|t j\}} |s%z t"|fi| }Wnt#y$td,i| }Ynwn |s2td t j ddS|D]-\}}z |j:|fi|Wq4t#ya}ztd|t j dWYd}~dSd}~wwj;}j&}|r|rd|vrz2d}d} d|vr|/dd\}} d| vrd} |r| rt<|| fi| }nt<|fi| }WnEt#y}ztd|t j dWYd}~dSd}~wwz t)|fi| }Wnt2t#fy}ztd|t j dWYd}~dSd}~ww|r>|sz t=|fi| }Wnt2t#fy}ztd|t j dWYd}~dSd}~wwzt4|d!} Wn<t5y=}ztd"|t j dWYd}~dSd}~ww|sZd#t>j?d$dvrSt@d,i| }ntAd,i| }t jBj } |sn|rh| |_CntDt jB|_C|st jEd%vr|jFd&vrtG| |jCd'} d|_CzddlH}!Wn tIyYn w|!jJjK| ddd(dd)} | d*d}"tL|"dkrtM|tNr|"d}#|"d}$tO|#|$|}j3sztP|||| W|r| QdS|r| QwwzLz6 t jj R}%|%sn| st9|%t jd}%tP|%||| tS| d+r | TqWW|r| QdSdStUy/YW|r-| QdSdSw|r8| Qww)-NruWPygments version %s, (c) 2006-2021 by Georg Brandl, Matthäus Chajdas and contributors.cs tfddtD S)Nc3s |] \}}|kr|VqdSNr-).0kvoptr-r. sz5main_inner..is_only_option..)anyvarsitemsrd)argnsrdr.is_only_options z"main_inner..is_only_optionLrZrG-V>r8rHr:r9cSsg|]}|dqS)s)rstripraargr-r-r. szmain_inner..c3s|]}|vVqdSr`r-rq) allowed_typesr-r.rfszmain_inner..H)r8r9r:r!r"T inencodingencoding outencoding)rvrHr;z.pyr0zError:z5Error: -s option not usable when input file specifiedrbzError: cannot read infile:z7Error: when using -s a lexer has to be selected with -lwbzError: cannot open outfile:256TERM)win32cygwin)Terminal Terminal256)rwF)convertr# autoresetwrap escapeinsideflushr-)Vhelp print_helpVr=rrlsetrhriadddiscardrArBrZmainrgrUr_rurEr/OPr$r%getNrrrKCstdinbufferreadrrSafl INPUTFILErget_style_defsr7Fboolxrsplitrr rroopen Exceptionrrgr add_filterorrosenvironrrr\rwr platformr>r colorama.initialise ImportError initialise wrap_streamlen isinstancerrrclosereadlinehasattrrKeyboardInterrupt)&parserrjrkarg_setrbrclargsrrrCr> parsed_optsp_optvaluervrxr8inpS_opta_optf_optfmtererrF_optsallow_custom_lexer_formatter lexernamefilenamecodeinfninfpr5r6outfnoutfilecoloramarleftrightliner-)rtrjr. main_innersD                                                  rc@seZdZdddZdS) HelpFormatterrmNcCsF|durz tjd}Wn tyYnwtj|||||dS)Nrm)shutilget_terminal_sizecolumnsrargparser__init__)selfprogindent_incrementmax_help_positionwidthr-r-r.rs  zHelpFormatter.__init__)rmrN)__name__ __module__ __qualname__rr-r-r-r.rsrc Csd}tj|dtd}|d}|}|jdddd|jd d d d |jd dddd|jdddd|jddddd|jddddd|jdddd|jddd d!|d"}|jd#d d$d |jd%d d&d |jd'd d(d |jd)d*dd d+|d,}|}|jd-d.d/d|jd0d1d2d3d4|jd5d6d7d|jd8d d9d |jd:d;dd?|jd@d dAd |jdBdCd dDd |jdEdFdGd||dHdI}zt||WSty]|j rt t j dJt dKt j dJt dLt j dJt dMt j dJt dNt j dJt dKt j dJt t j dJdOdIl } | jt } | dP} t| dQkr?| dR| dSdTdOdHdI7} t t j dJt dUt j dJt | t j dJt dVt j dJYdHSw)Wz( Main command line entry point. z?Highlight an input file and write the result to an output file.F) descriptionadd_helpformatter_classzMain operationz-lLEXERz~Specify the lexer to use. (Query names with -L.) If not given and -g is not present, the lexer is guessed from the filename.)metavarrz-g store_truez`Guess the lexer from the file contents, or pass through as plain text if nothing can be guessed.)actionrz-FzFILTER[:options]r1znAdd a filter to the token stream. (Query names with -L.) Filter options are given after a colon if necessary.)rrrz-f FORMATTERzSpecify 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-Pz OPTION=valuezGive 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-o OUTPUTFILEz8Where to write the output. Defaults to standard output.r?z5Where to read the input. Defaults to standard input.)nargsrzOperation 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-xaAllow 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.)rdefaultrz*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*WHATzList 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.)rrrz-NFILENAMEzGuess 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-Hstorerm)NAMETYPEzrPrint detailed help for the object of type , where is one of "lexer", "formatter" or "filter".)rrrrrnzPrint the package version.z-hz--helpzPrint this help.z-aARGzKFormatter-specific additional argument for the -S (print style sheet) mode.r"Nr;zA*****************************************************************z3An unhandled exception occurred while highlighting.z9Please report the whole traceback to the issue tracker atz..rz (f%s) z*** Error while highlighting:z>*** If this is a bug you want to report, please rerun with -v.)rArgumentParserradd_argument_groupadd_mutually_exclusive_group add_argument parse_argsrrrcr=rArB tracebackformat_exceptionexc_infor#rr$) argsdescr operationlexerselflagsspecial_modes_group special_modesrjrrMmsgr-r-r.rs       & r)7r?rrArrtextwraprpygmentsrr pygments.utilrrrrr r r pygments.lexersr r rrrrpygments.lexers.specialrpygments.formatters.latexrrpygments.formattersrrrrrpygments.formatters.terminalrpygments.formatters.terminal256rpygments.filtersrrpygments.stylesrrr/r7rErUr_rrargvrr-r-r-r.s4  $     3,O