B
    `"T                 @   s@  d Z ddlZddlZddlZddlZddlmZ ddlmZm	Z	 ddl
mZmZmZmZmZmZmZ ddlmZmZmZmZmZmZ ddlmZ ddlmZmZ dd	lmZm Z m!Z!m"Z"m#Z# dd
l$m%Z% ddl&m'Z' ddl(m)Z)m*Z* ddl+m,Z,m-Z- dd Z.dd Z/dd Z0dd Z1dd Z2G dd dej3Z3ej4fddZ5dS )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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)get_all_filtersfind_filter_class)get_all_stylesget_style_by_namec          
   C   s   i }| s|S x| D ]x}|  s q|d}x^|D ]V}|  }y$|dd\}}|  }|  }W n tk
r|   d||< Y q0X |||< q0W qW |S )N,=   T)stripsplit
ValueError)Zo_strsoptsZo_strZo_argsZo_argZo_keyZo_val r'   X/home/kop/projects/devel/pgwui/test_venv/lib/python3.7/site-packages/pygments/cmdline.py_parse_options!   s"    


r)   c             C   sZ   g }| s|S xH| D ]@}d|krD| dd\}}||t|gf q||i f qW |S )N:r"   )r$   appendr)   )Zf_strsfiltersZf_strfnamefoptsr'   r'   r(   _parse_filters6   s    
r/   c          	   C   s   y| dkr0t |}td|j  tt|j nX| dkr^t|}td|j  tt|j n*| dkrt|}td|  tt|j dS  ttfk
r   td|  t	j
d	 d
S X d S )NlexerzHelp on the %s lexer:	formatterzHelp on the %s formatter:filterzHelp on the %s filter:r   z%s not found!)filer"   )r   printnamer   __doc__r   r   AttributeErrorr%   sysstderr)whatr5   clsr'   r'   r(   _print_helpC   s"    r<   c             C   s  | dkrt   t d t d g }xJt D ]@\}}}}d|d ||rZdd| d p\df}|| q*W |  x|D ]}t d	|  q|W nR| d
kr0t   t d t d g }xPt D ]F}t|}	d|jd |	|jrdd|j d pdf}|| qW |  x|D ]}t d	|  qW n| dkrt   t d t d xt	 D ].}
t
|
}t d|
 d  t dt|  qXW nZ| dkrt   t d t d x8t D ].}
t|
}t d|
 d  t dt|  qW d S )Nr0   zLexers:z~~~~~~~z, r*   z(filenames ) z* %s
    %s %sr1   zFormatters:z~~~~~~~~~~~r2   zFilters:z~~~~~~~~z* z    %sstylezStyles:)r4   r   joinr+   sortr   r   aliases	filenamesr   r   r   r   )r:   infofullnamenamesexts_tupir;   docr5   r'   r'   r(   _print_listW   sR    




rL   c       #         s	  j r|   dS jr(tdt  dS fdd}jd k	r|dsV| tj dS tddg d	d
ddh dd jD }t	 fdd|D r| tj dS |s }x|D ]}t
| qW dS jr|ds| tj dS j\}}|dkr
| tj dS t||S tjp g }xRjp0g D ]B}y|dd\}}	W n tk
rh   d||< Y n
X |	||< q2W |d|d}
|d|d}jrtj}|d krt}t|jd  dS jr tjj }yt||
d}W n tk
r   t}Y nX t|jd  dS j}j}|d k	rֈj}|sR| tj dS j sbj!rr| tj dS y||d< t"|f|}W n2 tk
r } zt|tjd dS d }~X Y nX t|#|pd dS jd k	r| tj dS t$j%pg }t&j'}d }j }|r
|rd|kry\d }d }d|kr^|(dd\}}d|kr^d }|rz|rzt)||f|}nt)|f|}W n4 tk
r } ztd|tjd dS d }~X Y nX nJyt*|f|}W n8 t+tfk
r } ztd|tjd dS d }~X Y nX d }j!rbj,r0tdtjd dS j!}y"t-|d}| }W d Q R X W n4 t.k
r } ztd |tjd dS d }~X Y nX |
st/|\}}
|syt0||f|}W n tk
r, } zTj1ryt|f|}W n  tk
r   tf |}Y nX ntd|tjd dS W d d }~X Y n4 t+k
r^ } ztd|tjd dS d }~X Y nX n|j,stjj }|
st2|tj\}}
|syt|f|}W n  tk
r   tf |}Y nX n|std!tjd dS xZ|D ]R\}}y|j3|f| W n4 tk
r2 } ztd|tjd dS d }~X Y nX qW j4}j}|r:|rd|kry\d }d }d|kr|(dd\}}d|krd }|r|rt5||f|}nt5|f|}W n4 tk
r } ztd|tjd dS d }~X Y nX nJyt"|f|}W n8 t+tfk
r8 } ztd|tjd dS d }~X Y nX |r|syt6|f|}W n8 t+tfk
r } ztd|tjd dS d }~X Y nX yt-|d"}W n4 t.k
r } ztd#|tjd dS d }~X Y nX n8|sd$t7j8d%dkrt9f |}n
t:f |}tj;j}|s.|r"|
|_<nt=tj;|_<|stj>d&kr|j?d'krt@||j<d(}d |_<ydd lA}W n tBk
r   Y nX |jCjD|d d d)dd*}|d+d}tE|dkrtF|tGr|d } |d }!tH| |!|}j,	sztI|||| W d |	r|J  X dS ztyXxRtjjK }"|"	s&P |
	s<t2|"tjd }"tI|"||| tL|d,	r|M  	qW dS  tNk
	r|   dS X W d |	r|J  X d S )-Nr   uW   Pygments version %s, (c) 2006-2021 by Georg Brandl, Matthäus Chajdas and contributors.c                s    t  fddt D  S )Nc             3   s   | ]\}}| kr|V  qd S )Nr'   ).0kv)optr'   r(   	<genexpr>   s    z5main_inner.<locals>.is_only_option.<locals>.<genexpr>)anyvarsitems)rP   )argns)rP   r(   is_only_option   s    z"main_inner.<locals>.is_only_optionL   r>   z-Vr0   r1   r2   r?   c             S   s   g | ]}| d qS )s)rstrip)rM   argr'   r'   r(   
<listcomp>   s    zmain_inner.<locals>.<listcomp>c             3   s   | ]}| kV  qd S )Nr'   )rM   r[   )allowed_typesr'   r(   rQ      s    zmain_inner.<locals>.<genexpr>H)r0   r1   r2   r!   r"   T
inencodingencodingoutencoding)r_   )r3   z.pyr*   zError:z5Error: -s option not usable when input file specifiedrbzError: cannot read infile:z7Error: when using -s a lexer has to be selected with -lwbzError: cannot open outfile:Z256TERM)win32cygwin)ZTerminalZTerminal256)r`   F)convertr#   	autoresetwrapescapeinsideflush)Ohelp
print_helpVr4   r   rW   r8   r9   mainrR   rL   r^   r<   r)   OPr$   r%   getNr   r   rB   Cstdinbufferreadr   r   Safl	INPUTFILEr   Zget_style_defsr/   Fboolxrsplitr   r   r   rY   open	Exceptionr   r   gr	   Z
add_filteror   r   osenvironr   r   stdoutr`   r
   platformr5   r   Zcolorama.initialiseImportError
initialisewrap_streamlen
isinstancer   r   r   closereadlinehasattrrk   KeyboardInterrupt)#parserrU   rV   largsr[   r:   r5   Zparsed_optsZp_optvaluer_   ra   r0   inpZS_optZa_optZf_optZfmtererrZF_optsZallow_custom_lexer_formatterZ	lexernamefilenamecodeZinfninfpr-   r.   Zoutfnoutfilecoloramarj   leftrightliner'   )r]   rU   r(   
main_inner   s   


















r   c               @   s   e Zd ZdddZdS )HelpFormatterrX      Nc             C   sH   |d kr0yt  jd }W n tk
r.   Y nX tj| |||| d S )NrX   )shutilget_terminal_sizecolumnsr   argparser   __init__)selfprogindent_incrementmax_help_positionwidthr'   r'   r(   r     s    zHelpFormatter.__init__)rX   r   N)__name__
__module____qualname__r   r'   r'   r'   r(   r     s   r   c             C   s  d}t j|dtd}|d}| }|jdddd |jd	d
dd |jddddd |jdddd |jddddd |jddddd |jdddd |jddd d! |d"}|jd#d
d$d |jd%d
d&d |jd'd
d(d |d)}| }|jd*d+d,d |jd-d.d/d0d1 |jd2d3d4d |jd5d
d6d |jd7d8d9d:d;d< |jd=d
d>d |jd?d@d
dAd |jdBdCdDd || dEdF }y
t||S  tk
r   |j	rt
tjdG t
dHtjdG t
dItjdG t
dJtjdG t
dKtjdG t
dHtjdG t
tjdG  dLdFl}	|	jt  }
|
dM  }t|
dNkrl|dO|
dP dQdL  dEdF  7 }t
tjdG t
dRtjdG t
|tjdG t
dStjdG dES X dFS )Tz(
    Main command line entry point.
    z?Highlight an input file and write the result to an output file.F)descriptionadd_helpformatter_classzMain operationz-lZLEXERz~Specify the lexer to use.  (Query names with -L.)  If not given and -g is not present, the lexer is guessed from the filename.)metavarrl   z-g
store_truez`Guess the lexer from the file contents, or pass through as plain text if nothing can be guessed.)actionrl   z-FzFILTER[:options]r+   znAdd a filter to the token stream.  (Query names with -L.) Filter options are given after a colon if necessary.)r   r   rl   z-fZ	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-OzOPTION=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-oZ
OUTPUTFILEz8Where to write the output.  Defaults to standard output.r|   ?z5Where to read the input.  Defaults to standard input.)nargsrl   zOperation 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*Special modes - do not do any highlightingz-SzSTYLE -f formatterzqPrint style definitions for STYLE for a formatter given with -f. The argument given by -a is formatter dependent.z-L*Z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.)r   r   rl   z-NZFILENAMEzGuess 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storerX   )NAMEZTYPEzrPrint detailed help for the object <name> of type <type>, where <type> is one of "lexer", "formatter" or "filter".)r   r   r   rl   z-VzPrint the package version.z-hz--helpzPrint this help.z-aZARGzKFormatter-specific additional argument for the -S (print style sheet) mode.r"   N)r3   zA*****************************************************************z3An unhandled exception occurred while highlighting.z9Please report the whole traceback to the issue tracker atz.<https://github.com/pygments/pygments/issues>.r      z	
   (f%s)
z*** Error while highlighting:z>*** If this is a bug you want to report, please rerun with -v.)r   ArgumentParserr   add_argument_groupadd_mutually_exclusive_groupadd_argument
parse_argsr   r   rO   r4   r8   r9   	tracebackformat_exceptionexc_infor#   r   r$   )argsdescr   Z	operationZlexerselflagsZspecial_modes_groupZspecial_modesrU   r   rD   msgr'   r'   r(   ro     s    





&
ro   )6r6   r   r8   r   r   textwrapr   Zpygmentsr   r   Zpygments.utilr   r   r   r   r	   r
   r   Zpygments.lexersr   r   r   r   r   r   Zpygments.lexers.specialr   Zpygments.formatters.latexr   r   Zpygments.formattersr   r   r   r   r   Zpygments.formatters.terminalr   Zpygments.formatters.terminal256r   Zpygments.filtersr   r   Zpygments.stylesr   r   r)   r/   r<   rL   r   r   argvro   r'   r'   r'   r(   <module>	   s0   $ 3  B