U
    ;»{jh\  ã                   @   sL  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'm(Z( ddl)m*Z*m+Z+ ddl,m-Z-m.Z. dd„ Z/dd„ Z0dd„ Z1dd„ Z2dd„ Z3dd„ Z4G dd„ dej5ƒZ5ej6fdd„Z7dS )z¼
    pygments.cmdline
    ~~~~~~~~~~~~~~~~

    Command line interface.

    :copyright: Copyright 2006-2024 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              
   C   sŠ   i }| s|S | D ]t}|  ¡ sq| d¡}|D ]V}|  ¡ }z$| dd¡\}}|  ¡ }|  ¡ }W n tk
rx   d||< Y q,X |||< q,q|S )Nú,ú=é   T)ÚstripÚsplitÚ
ValueError)Zo_strsÚoptsZo_strZo_argsZo_argZo_keyZo_val© r(   ú=/tmp/pip-install-zsn1f9xv/pip/pip/_vendor/pygments/cmdline.pyÚ_parse_options!   s"    
r*   c                 C   sV   g }| s|S | D ]@}d|krB|  dd¡\}}| |t|gƒf¡ q| |i f¡ q|S )Nú:r#   )r%   Úappendr*   )Zf_strsÚfiltersZf_strÚfnameÚfoptsr(   r(   r)   Ú_parse_filters6   s    r0   c              	   C   sÌ   z˜| dkr4t |ƒ}td|j› d�ƒ tt|jƒƒ n`| dkrft|ƒ}td|j› d�ƒ tt|jƒƒ n.| dkr”t|ƒ}td|› d�ƒ tt|jƒƒ W dS  ttfk
rÆ   t| › d	�t	j
d
� Y dS X d S )NÚlexerzHelp on the z lexer:Ú	formatterz formatter:Úfilterz filter:r   z not found!©Úfiler#   )r   ÚprintÚnamer   Ú__doc__r   r   ÚAttributeErrorr&   ÚsysÚstderr)Úwhatr7   Úclsr(   r(   r)   Ú_print_helpC   s"    r>   c                 C   sÚ  | dkrŽt ƒ  t dƒ t dƒ g }tƒ D ]@\}}}}d |¡d ||rXdd |¡ d pZdf}| |¡ q(| ¡  |D ]}t d	j|Ž ƒ qv�nH| d
k�r$t ƒ  t dƒ t dƒ g }tƒ D ]F}t|ƒ}	d |j¡d |	|j	rîdd |j	¡ d pðdf}| |¡ q¸| ¡  |D ]}t d	j|Ž ƒ �qn²| dk�r~t ƒ  t dƒ t dƒ t
ƒ D ]0}
t|
ƒ}t d|
 d ƒ t dt|ƒ› �ƒ �qJnX| dk�rÖt ƒ  t dƒ t dƒ tƒ D ]0}
t|
ƒ}t d|
 d ƒ t dt|ƒ› �ƒ �q¤d S )Nr1   zLexers:z~~~~~~~z, r+   z(filenames ú)Ú z* {}
    {} {}r2   zFormatters:z~~~~~~~~~~~r3   zFilters:z~~~~~~~~z* z    ÚstylezStyles:)r6   r   Újoinr,   ÚsortÚformatr   r   ÚaliasesÚ	filenamesr   r   r   r    )r<   ÚinfoÚfullnameÚnamesÚextsÚ_ÚtupÚir=   Údocr7   r(   r(   r)   Ú_print_listW   sZ    ÿ

ÿÿ



rO   c                 C   s  dd l }i }d| krDi }tƒ D ]\}}}}|||dœ||< q||d< d| kr‚i }tƒ D ]"}t|ƒ}	|j|j|	dœ||j< qV||d< d| krºi }tƒ D ]}
t|
ƒ}d	t|ƒi||
< q”||d
< d| kròi }t	ƒ D ]}
t
|
ƒ}d	t|ƒi||
< qÌ||d< | |tj¡ d S )Nr   r1   )rE   rF   Ú	mimetypesZlexersr2   )rE   rF   rN   Ú
formattersr3   rN   r-   rA   Zstyles)Újsonr   r   r   rE   rF   r7   r   r   r   r    Údumpr:   Ústdout)Zrequested_itemsrR   ÚresultrG   rH   rI   rF   rP   r=   rN   r7   r(   r(   r)   Ú_print_list_as_jsonŠ   sH    ý
ý
 ÿ

 ÿ
rV   c           &         sR
  ˆj r|  ¡  dS ˆjr,tdt› d�ƒ dS ‡fdd„}ˆjd k	�rtƒ }tˆƒ ¡ D ]\}}|rV| 	|¡ qV| 
d¡ | 
d¡ |r–|  tj¡ dS ˆj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òˆ }ˆj�s|D ]}t|ƒ qþnt|ƒ dS ˆj�rj|dƒ�s<|  tj¡ dS ˆj\}}	|dk�r`|  tj¡ dS t||	ƒS tˆj�pvg ƒ}
ˆj�p„g D ]B}z| dd¡\}	}W n tk
�r¼   d|
|< Y n
X ||
|	< �q†|
 d|
 d¡¡}|
 d|
 d¡¡}ˆj�r tˆjƒ}|d k�rt}t|jd ƒ dS ˆj�rrtjj  !¡ }zt"||d�}W n t#k
�r^   t}Y nX t|jd ƒ dS ˆj$}ˆj%}|d k	�r.ˆj&}|�s¤|  tj¡ dS ˆj'�s´ˆj(�rÄ|  tj¡ dS z||
d< t)|f|
Ž}W n8 t#k
�r } zt|tjd� W Y ¢dS d }~X Y nX t| *|�p$d	¡ƒ dS ˆj%d k	�rJ|  tj¡ dS t+ˆj,�pVg ƒ}t-ˆj.ƒ}d }ˆj'}|�rn|�rd|k�rz\d }d }	d|k�r¶| /dd¡\}}	d|	k�r¶d }	|�rÒ|	�rÒt0||	f|
Ž}nt0|f|
Ž}W n: t#k
�r } ztd|tjd� W Y ¢dS d }~X Y nX nPzt1|f|
Ž}W n> t2t#fk
�rl } ztd|tjd� W Y ¢dS d }~X Y nX d }ˆj(�rØˆj3�r”td tjd� dS ˆj(}z"t4|d!ƒ�}| !¡ }W 5 Q R X W n: t5k
�rö } ztd"|tjd� W Y ¢dS d }~X Y nX |�s
t6|ƒ\}}|�sTzt7||f|
Ž}W n² t#k
�rœ } zZˆj8�rrzt"|f|
Ž}W n  t#k
�rn   tf |
Ž}Y nX ntd|tjd� W Y ¢dS W 5 d }~X Y n: t2k
�rÔ } ztd|tjd� W Y ¢dS d }~X Y nX n|ˆj3�s<tjj  !¡ }|�st9|tjƒ\}}|�sTzt"|f|
Ž}W n  t#k
�r8   tf |
Ž}Y nX n|�sTtd#tjd� dS |D ]Z\}}z|j:|f|Ž W n< t#k
�r® } ztd|tjd� W Y ¢ dS d }~X Y nX �qXˆj;}ˆj&}|�rÀ|�rpd|k�rpz\d }d }	d|k�r| /dd¡\}}	d|	k�rd }	|�r$|	�r$t<||	f|
Ž}nt<|f|
Ž}W n: t#k
�rl } ztd|tjd� W Y ¢dS d }~X Y nX nPzt)|f|
Ž}W n> t2t#fk
�r¾ } ztd|tjd� W Y ¢dS d }~X Y nX |�rh|�szt=|f|
Ž}W n> t2t#fk
�r } ztd|tjd� W Y ¢dS d }~X Y nX zt4|d$ƒ} W n: t5k
�rd } ztd%|tjd� W Y ¢dS d }~X Y nX nX|�s¸t>j? d&d	¡d'k�rŽt@f |
Ž}n*d(t>j? d)d	¡k�r®tAf |
Ž}n
tBf |
Ž}tjCj } |�sà|�rÔ||_DntEtjCƒ|_D|�	sLtjFd*k�	rL|jGd+k�	rLtH| |jDd,�} d |_Dzdd lI}!W n tJk
�	r4   Y nX |!jKjL| d d d-dd.�} |
 d/d	¡}"tM|"ƒdk�	rŽtN|tOƒ�	rŽ|"d }#|"d }$tP|#|$|ƒ}ˆj3�	s¾ztR|||| ƒ W 5 |�	r¸|  Q¡  X dS z~z\tjj  S¡ }%|%�	sØ�
q|�	sît9|%tjƒd }%tR|%||| ƒ tT| d0ƒ�	rÂ|  U¡  �	qÂW W ¢$dS  tVk
�
r8   Y W ¢
dS X W 5 |�
rL|  Q¡  X d S )1Nr   zPygments version uD   , (c) 2006-2024 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Úitemsr[   )Úargnsr[   r)   Úis_only_optionÀ   s    z"main_inner.<locals>.is_only_optionÚLrR   é   r@   ú-Vr1   r2   r3   rA   c                 S   s   g | ]}|  d ¡‘qS )Ús)Úrstrip©rX   Úargr(   r(   r)   Ú
<listcomp>Õ   s     zmain_inner.<locals>.<listcomp>c                 3   s   | ]}|ˆ kV  qd S rW   r(   rh   )Úallowed_typesr(   r)   r]   Ö   s     zmain_inner.<locals>.<genexpr>ÚH)r1   r2   r3   r"   r#   TÚ
inencodingÚencodingÚoutencoding)rm   r4   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	COLORTERM)Z	truecolorZ24bitZ256ÚTERM)Úwin32Úcygwin)ZTerminalZTerminal256)rn   F)Úconvertr$   Ú	autoresetÚwrapÚescapeinsideÚflush)WÚhelpÚ
print_helpÚVr6   r   rc   Úsetr_   r`   ÚaddÚdiscardr:   r;   rR   Úmainr^   rO   rV   rl   r>   r*   ÚOÚPr%   r&   ÚgetÚNr   r   rE   ÚCÚstdinÚbufferÚreadr   r   ÚSÚaÚfÚlÚ	INPUTFILEr   Zget_style_defsr0   ÚFÚboolÚxÚrsplitr   r   r   rf   ÚopenÚ	Exceptionr   r   Úgr	   Z
add_filterÚor   r   ÚosÚenvironr   r   r   rT   rn   r
   Úplatformr7   r   Zcolorama.initialiseÚImportErrorÚ
initialiseÚwrap_streamÚlenÚ
isinstancer   r   Úcloser   ÚreadlineÚhasattrry   ÚKeyboardInterrupt)&Úparserra   rb   Zarg_setrY   rZ   Úlargsri   r<   r7   Zparsed_optsZp_optÚvaluerm   ro   r1   ÚinpZS_optZa_optZf_optZfmterÚerrZF_optsZallow_custom_lexer_formatterZ	lexernameÚfilenameÚcodeZinfnÚinfpr.   r/   ZoutfnÚoutfileÚcoloramarx   ÚleftÚrightÚliner(   )rk   ra   r)   Ú
main_inner¶   sð   












ÿÿÿ

ÿ
ÿ    ÿ

r¯   c                   @   s   e Zd Zddd„ZdS )ÚHelpFormatterrd   é   Nc                 C   sH   |d kr0zt  ¡ jd }W n tk
r.   Y nX tj | ||||¡ d S )Nrd   )ÚshutilÚget_terminal_sizeÚcolumnsr“   Úargparser°   Ú__init__)ÚselfÚprogÚindent_incrementÚmax_help_positionÚwidthr(   r(   r)   r¶     s     ÿzHelpFormatter.__init__)rd   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� |jd)d*dd
d+� | d,¡}| ¡ }|jd-d.d/d� |jd0d1d2d3d4� |jd5d6d7d� |jd8d
d9d� |jd:d;d<d=d>d?� |jd@d
dAd� |jdBdCd
dDd� |jdEdFdGd� | | dHdI… ¡}zt||ƒW S  tk
�rÈ   Y dJS  t	k
�rÔ   |j
�r@ttjdK� tdLtjdK� tdMtjdK� tdNtjdK� tdOtjdK� tdLtjdK� ttjdK� ‚ dJdIl}	|	jt ¡ Ž }
|
dP  ¡ }t|
ƒdQk�r˜|dR |
dS  dT¡dJ  ¡ dHdI… ¡7 }ttjdK� tdUtjdK� t|tjdK� tdVtjdK� Y dHS X dIS )Wz(
    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.)Úmetavarrz   z-gÚ
store_truez`Guess the lexer from the file contents, or pass through as plain text if nothing can be guessed.)Úactionrz   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Ä   rz   z-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-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=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.)Únargsrz   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--jsonz=Output as JSON. This can be only used in conjunction with -L.)rz   ÚdefaultrÄ   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WHATz›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Â   rz   z-NZFILENAMEzª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Ústorerd   )ÚNAMEZTYPEzrPrint detailed help for the object <name> of type <type>, where <type> is one of "lexer", "formatter" or "filter".)rÄ   rÆ   rÂ   rz   re   zPrint the package version.z-hz--helpzPrint this help.z-aZARGzKFormatter-specific additional argument for the -S (print style sheet) mode.r#   Nr   r4   zA*****************************************************************z3An unhandled exception occurred while highlighting.z9Please report the whole traceback to the issue tracker atz.<https://github.com/pygments/pygments/issues>.éÿÿÿÿé   z	
   (f{})éþÿÿÿÚ
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¯   ÚBrokenPipeErrorr“   rZ   r6   r:   r;   Ú	tracebackÚformat_exceptionÚexc_infor$   rœ   rD   r%   )ÚargsÚdescr¢   Z	operationZlexerselÚflagsZspecial_modes_groupZspecial_modesra   rÕ   rG   Úmsgr(   r(   r)   r€     s,   ÿ
 þ þ  þ þ  þ  þ þ þ
 þ þ þ	ýÿ þ  þ þ þ   þ þ  þ þÿÿÿ(ÿr€   )8r8   r–   r:   r²   rµ   Útextwrapr   Zpip._vendor.pygmentsr   r   Zpip._vendor.pygments.utilr   r   r   r   r	   r
   r   Zpip._vendor.pygments.lexersr   r   r   r   r   r   Z#pip._vendor.pygments.lexers.specialr   Z%pip._vendor.pygments.formatters.latexr   r   Zpip._vendor.pygments.formattersr   r   r   r   r   Z(pip._vendor.pygments.formatters.terminalr   Z+pip._vendor.pygments.formatters.terminal256r   r   Zpip._vendor.pygments.filtersr   r   Zpip._vendor.pygments.stylesr   r    r*   r0   r>   rO   rV   r¯   r°   Úargvr€   r(   r(   r(   r)   Ú<module>   s2   
$ 3,  Q