o
    Rh[                     @   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-2025 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 ]9}|  sq|d}|D ]*}|  }z|dd\}}|  }|  }W n ty;   d||< Y qw |||< qq|S )N,=   T)stripsplit
ValueError)o_strsoptso_stro_argso_argo_keyo_val r.   R/home/air/sanwanet/backup_V2/venv/lib/python3.10/site-packages/pygments/cmdline.py_parse_options!   s&   


r0   c                 C   sV   g }| s|S | D ] }d|v r!| dd\}}||t|gf q||i f q|S )N:r#   )r%   appendr0   )f_strsfiltersf_strfnamefoptsr.   r.   r/   _parse_filters6   s   r8   c              	   C   s   zP| dkrt |}td|j d tt|j W dS | dkr7t|}td|j d tt|j W dS | dkrNt|}td| d tt|j W dS  ttfyf   t|  d	t	j
d
 Y dS w )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)whatr?   clsr.   r.   r/   _print_helpC   s(   	rF   c                 C   s  | dkrGt   t d t d g }t D ] \}}}}d|d ||r,dd| d p-df}|| q|  |D ]	}t d	j|  q;d S | d
krt   t d t d g }t D ]#}t|}	d|jd |	|j	rvdd|j	 d pwdf}|| q[|  |D ]	}t d	j|  qd S | dkrt   t d t d t
 D ]}
t|
}t d|
 d  t dt|  qd S | dkrt   t d t d t D ]}
t|
}t d|
 d  t dt|  qd S d S )Nr9   zLexers:z~~~~~~~z, r1   z(filenames ) z* {}
    {} {}r:   zFormatters:z~~~~~~~~~~~r;   zFilters:z~~~~~~~~z* z    stylezStyles:)r>   r   joinr2   sortformatr   r   aliases	filenamesr   r   r   r    )rD   infofullnamenamesexts_tupirE   docr?   r.   r.   r/   _print_listW   sd   


rW   c                 C   s  dd l }i }d| v r"i }t D ]\}}}}|||d||< q||d< d| v rAi }t D ]}t|}	|j|j|	d||j< q+||d< d| v r]i }t D ]}
t|
}d	t|i||
< qJ||d
< d| v ryi }t	 D ]}
t
|
}d	t|i||
< qf||d< ||tj d S )Nr   r9   )rM   rN   	mimetypeslexersr:   )rM   rN   rV   
formattersr;   rV   r4   rI   styles)jsonr   r   r   rM   rN   r?   r   r   r   r    dumprB   stdout)requested_itemsr\   resultrO   rP   rQ   rN   rX   rE   rV   r?   r.   r.   r/   _print_list_as_json   sD   




ra   c           &         s
  j r	|   dS jrtdt d dS fdd}jd urt }t D ]\}}|r5|	| q*|
d |
d |rJ| tj dS jsStd	d
g h d dd jD }t fdd|D rr| tj dS |sv }js|D ]}t| q{dS t| dS jr|ds| tj dS j\}}	|dvr| tj dS t||	S tjpg }
jpg D ]}z
|dd\}	}W n ty   d|
|< Y qw ||
|	< q|
d|
d}|
d|
d}jrtj}|d u rt}t|jd  dS jr,tjj ! }zt"||d}W n t#y"   t}Y nw t|jd  dS j$}j%}|d urj&}|sE| tj dS j'sMj(rU| tj dS z||
d< t)|fi |
}W n t#y~ } zt|tjd W Y d }~dS d }~ww t|*|pd	 dS j%d ur| tj dS t+j,pg }t-j.}d }j'}|r.|rd|v rz2d }d }	d|v r|/dd\}}	d|	v rd }	|r|	rt0||	fi |
}nt0|fi |
}W nE t#y } ztd|tjd W Y d }~dS d }~ww z
t1|fi |
}W n t2t#fy- } ztd|tjd W Y d }~dS d }~ww d }j(rj3rAtdtjd dS j(}zt4|d}|! }W d    n	1 sZw   Y  W n t5y| } ztd |tjd W Y d }~dS d }~ww |st6|\}}|szt7||fi |
}W n t#y } z5j8rz
t"|fi |
}W n  t#y   td/i |
}Y nw td|tjd W Y d }~dS W Y d }~nbd }~w t2y } ztd|tjd W Y d }~dS d }~ww nAj3s(tjj ! }|st9|tj\}}|s'z
t"|fi |
}W n t#y&   td/i |
}Y nw n|s4td!tjd dS |D ]-\}}z|j:|fi | W q6 t#yc } ztd|tjd W Y d }~ dS d }~ww j;}j&}|r|rd|v rz2d }d }	d|v r|/dd\}}	d|	v rd }	|r|	rt<||	fi |
}nt<|fi |
}W nE t#y } ztd|tjd W Y d }~dS d }~ww z
t)|fi |
}W n t2t#fy } ztd|tjd W Y d }~dS d }~ww |r@|sz
t=|fi |
}W n t2t#fy } ztd|tjd W Y d }~dS d }~ww zt4|d"} W nN t5y? } ztd#|tjd W Y d }~dS d }~ww |snt>j?d$d	d%v rUt@d/i |
}nd&t>j?d'd	v rgtAd/i |
}ntBd/i |
}tjCj } |s|r|||_DntEtjC|_D|stjFd(v r|jGd)v rtH| |jDd*} d |_Dzdd lI}!W n
 tJy   Y nw |!jKjL| d d d+dd,} |
d-d	}"tM|"dkrtN|tOr|"d }#|"d }$tP|#|$|}j3sztQ||||  W |r| R  dS |r| R  w w zLz6	 tjj S }%|%sn|st9|%tjd }%tQ|%|||  tT| d.r | U  qW W |r-| R  dS dS  tVyC   Y W |rA| R  dS dS w |rL| R  w w )0Nr   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itemsrf   )argnsrf   r/   is_only_option   s    z"main_inner.<locals>.is_only_optionLr\      rH   -V>   r9   rI   r;   r:   c                 S   s   g | ]}| d qS )s)rstriprc   argr.   r.   r/   
<listcomp>   s    zmain_inner.<locals>.<listcomp>c                 3   s    | ]}| vV  qd S rb   r.   rs   )allowed_typesr.   r/   rh      s    zmain_inner.<locals>.<genexpr>H)r9   r:   r;   r"   r#   T
inencodingencodingoutencoding)rx   rI   r<   z.pyr1   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:	COLORTERM)	truecolor24bit256TERM)win32cygwin)TerminalTerminal256)ry   F)convertr$   	autoresetwrapescapeinsideflushr.   )Whelp
print_helpVr>   r   rn   setrj   rk   adddiscardrB   rC   r\   mainri   rW   ra   rw   rF   r0   OPr%   r&   getNr   r   rM   Cstdinbufferreadr   r   Safl	INPUTFILEr   get_style_defsr8   Fboolxrsplitr   r   r   rq   open	Exceptionr   r   gr	   
add_filteror   r   osenvironr   r   r   r^   ry   r
   platformr?   r   colorama.initialiseImportError
initialisewrap_streamlen
isinstancer   r   r   closereadlinehasattrr   KeyboardInterrupt)&parserrl   rm   arg_setrd   re   largsrt   rD   r?   parsed_optsp_optvaluerx   rz   r9   inpS_opta_optf_optfmtererrF_optsallow_custom_lexer_formatter	lexernamefilenamecodeinfninfpr6   r7   outfnoutfilecoloramar   leftrightliner.   )rv   rl   r/   
main_inner   sD  



















	
r   c                   @   s   e Zd ZdddZdS )HelpFormatterro      Nc                 C   sF   |d u rz	t  jd }W n	 ty   Y nw tj| |||| d S )Nro   )shutilget_terminal_sizecolumnsr   argparser   __init__)selfprogindent_incrementmax_help_positionwidthr.   r.   r/   r     s   zHelpFormatter.__init__)ro   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y   Y dJS  t	yg   |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rI|dR|
dS dTdJ  dHdI 7 }ttjdK tdUtjdK t|tjdK tdVtjdK Y dHS w )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-l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.)metavarr   z-g
store_truez`Guess the lexer from the file contents, or pass through as plain text if nothing can be guessed.)actionr   z-FzFILTER[:options]r2   znAdd a filter to the token stream.  (Query names with -L.) Filter options are given after a colon if necessary.)r   r   r   z-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-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-o
OUTPUTFILEz8Where to write the output.  Defaults to standard output.r   ?z5Where to read the input.  Defaults to standard input.)nargsr   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.)r   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*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   r   z-N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storero   )NAMETYPEzrPrint detailed help for the object <name> of type <type>, where <type> is one of "lexer", "formatter" or "filter".)r   r   r   r   rp   zPrint the package version.z-hz--helpzPrint this help.z-aARGzKFormatter-specific additional argument for the -S (print style sheet) mode.r#   Nr   r<   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   re   r>   rB   rC   	tracebackformat_exceptionexc_infor$   r   rL   r%   )argsdescr   	operationlexerselflagsspecial_modes_groupspecial_modesrl   r   rO   msgr.   r.   r/   r     s   

	(r   )8r@   r   rB   r   r   textwrapr   pygmentsr   r   pygments.utilr   r   r   r   r	   r
   r   pygments.lexersr   r   r   r   r   r   pygments.lexers.specialr   pygments.formatters.latexr   r   pygments.formattersr   r   r   r   r   pygments.formatters.terminalr   pygments.formatters.terminal256r   r   pygments.filtersr   r   pygments.stylesr   r    r0   r8   rF   rW   ra   r   r   argvr   r.   r.   r.   r/   <module>   s4    
$ 3,  Q