o
    =g5|                  #   @   s  d dl Z d dlZd dlZd dlZd dl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mZmZmZmZmZmZmZmZ d dl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$ d dl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z.m/Z/m0Z0m1Z1m2Z2 ddl3m4Z4 ddl5m6Z6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? dd	l@m"Z" ddlAmBZB ejCdkZDdZEdZFdddddddeEeFdddd dd!d"ee. d#eeG d$eeG d%eGd&eeH d'eId(eId)eGd*eGd+eId,eeI d-eId.eeeHef  d/eGd0eeeJ eJee gef fd1d2ZKeG d3d4 d4ZLeG d5d6 d6ZMeG d7d8 d8ZNeG d9d: d:ZOG d;d< d<e6ZPG d=d> d>ZQeRd?krreKdd@ d dlZdAed0dfdBdCZSdAed0dfdDdEZTdHdFdGZUeU  dS dS )I    N)	dataclassfield)islice)walk_tb)
ModuleTypeTracebackType)
AnyCallableDictIterableListOptionalSequenceTupleTypeUnion)guess_lexer_for_filename)CommentKeywordNameNumberOperatorString)Text)Token)ClassNotFound   )pretty)	loop_last)Columns)ConsoleConsoleOptionsConsoleRenderableRenderResultgroup)	Constrain)RegexHighlighterReprHighlighter)Panel)render_scope)Style)Syntax)Themewin32
   P   d   X      FT )consolewidth
code_widthextra_linestheme	word_wrapshow_localslocals_max_lengthlocals_max_stringlocals_hide_dunderlocals_hide_sunderindent_guidessuppress
max_framesr4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   returnc                    s   | du r	t ddn| jrdu rdndtt dtdtt ddf 	
fdd	d
tddffdd}zt }|| tj	W S  t
y]   tj	}t_	| Y S w )a  Install a rich traceback handler.

    Once installed, any tracebacks will be printed with syntax highlighting and rich formatting.


    Args:
        console (Optional[Console], optional): Console to write exception to. Default uses internal Console instance.
        width (Optional[int], optional): Width (in characters) of traceback. Defaults to 100.
        code_width (Optional[int], optional): Code width (in characters) of traceback. Defaults to 88.
        extra_lines (int, optional): Extra lines of code. Defaults to 3.
        theme (Optional[str], optional): Pygments theme to use in traceback. Defaults to ``None`` which will pick
            a theme appropriate for the platform.
        word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.
        show_locals (bool, optional): Enable display of local variables. Defaults to False.
        locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
            Defaults to 10.
        locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
        locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
        locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
        indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
        suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.

    Returns:
        Callable: The previous exception handler that was replaced.

    NT)stderrtype_value	tracebackrB   c                    s8    tj| || 
t	d d S )Nr5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   )print	Tracebackfrom_exceptionbool)rD   rE   rF   )r6   r7   r?   r=   r>   r;   r<   rA   r:   r@   r8   traceback_consoler5   r9   r3   M/var/www/html/venv/lib/python3.10/site-packages/pip/_vendor/rich/traceback.py
excepthookb   s(   zinstall.<locals>.excepthookipc              	      sl   i j  dtdtdd f fdd}dddtdtdtdd ffd	d
_|_ fdd_d S )NargskwargsrB   c                     s   | | i | dS )zEwrap the default ip.showtraceback to store info for ip._showtracebackNr3   rP   rQ   )default_showtracebacktb_datar3   rM   ipy_show_traceback   s   zCinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_show_tracebackF)	is_syntaxrV   c                    st     }| rdn|d }dd}d|rdnd}t|D ]}|du r( n|j}q  |d |d | i dS )z2Internally called traceback from ip._showtracebackN   running_compiled_codeF	tb_offsetr   r   )_get_exc_infogetrangetb_next)rV   rP   rQ   	exc_tupletbcompiledrY   _)rN   rO   rT   r3   rM   ipy_display_traceback   s   zFinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_display_tracebackc                     s    | ddi|S )NrV   Tr3   rR   )rb   r3   rM   <lambda>   s    z9install.<locals>.ipy_excepthook_closure.<locals>.<lambda>)showtracebackr   rK   _showtracebackshowsyntaxerror)rO   rU   )rN   )rS   rO   rb   rT   rM   ipy_excepthook_closure|   s    z'install.<locals>.ipy_excepthook_closure)r    
is_jupyterr   BaseExceptionr   r   r   get_ipythonsysrN   	Exception)r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rg   rO   old_excepthookr3   )r6   rN   r7   r?   r=   r>   r;   r<   rA   r:   r@   r8   rL   r5   r9   rM   install/   s4   +()rn   c                   @   st   e Zd ZU eed< eed< eed< dZeed< dZee	ee
jf  ed< dZeeeeef eeef f  ed< dS )	Framefilenamelinenoname lineNlocalslast_instruction)__name__
__module____qualname__str__annotations__intrt   ru   r   r
   r   Noderv   r   r3   r3   r3   rM   ro      s   
 ,ro   c                   @   s6   e Zd ZU eed< eed< eed< eed< eed< dS )_SyntaxErroroffsetrp   rt   rq   msgN)rw   rx   ry   r|   r{   rz   r3   r3   r3   rM   r~      s   
 r~   c                   @   sP   e Zd ZU eed< eed< dZee ed< dZe	ed< e
edZee ed< dS )	Stackexc_type	exc_valueNsyntax_errorFis_cause)default_factoryframes)rw   rx   ry   rz   r{   r   r   r~   r   rK   r   listr   r   ro   r3   r3   r3   rM   r      s   
 r   c                   @   s   e Zd ZU ee ed< dS )TracestacksN)rw   rx   ry   r   r   r{   r3   r3   r3   rM   r      s   
 r   c                   @   s   e Zd ZdgZdS )PathHighlighterz(?P<dim>.*/)(?P<bold>.+)N)rw   rx   ry   
highlightsr3   r3   r3   rM   r      s    
r   c                $   @   s  e Zd ZdZddddddZ	d6dd	d
dddeedddddddee dee	 dee	 de	dee
 dedede	de	dedededeee
ef  de	fddZedd	d
dddeedddddddee d ed!ee dee	 dee	 de	dee
 dedede	de	dedededeee
ef  de	d"d f"d#d$Zedeeddd%dee d ed!ee dede	de	deded"efd&d'Zd(ed)ed"efd*d+Ze d,ed"efd-d.Zed/e
d0e
d"e
fd1d2Ze d3ed"efd4d5Z dS )7rI   a  A Console renderable that renders a traceback.

    Args:
        trace (Trace, optional): A `Trace` object produced from `extract`. Defaults to None, which uses
            the last exception.
        width (Optional[int], optional): Number of characters used to traceback. Defaults to 100.
        code_width (Optional[int], optional): Number of code characters used to traceback. Defaults to 88.
        extra_lines (int, optional): Additional lines of code to render. Defaults to 3.
        theme (str, optional): Override pygments theme used in traceback.
        word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.
        show_locals (bool, optional): Enable display of local variables. Defaults to False.
        indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
        locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
            Defaults to 10.
        locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
        locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
        locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
        suppress (Sequence[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
        max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.

    textpythoncythonpyrex)rs   z.pyz.pxdz.pyxz.pxiNr0   r1   r2   FTr3   rG   tracer5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   c                C   s"  |d u r$t  \}}}|d u s|d u s|d u rtd| j||||d}|| _|| _|| _|| _t	|p5d| _
|| _|| _|| _|| _|	| _|
| _|| _g | _|D ]-}t|tsm|jd useJ |dtj|j}n|}tjtj|}| j| qR|dkrtd|| _d S d| _d S )Nz9Value for 'trace' required if not called in except: blockr:   	ansi_darkz+ must be a module with '__file__' attributer      )rk   exc_info
ValueErrorextractr   r5   r6   r7   r+   	get_themer8   r9   r:   r?   r;   r<   r=   r>   r@   
isinstancerz   __file__ospathdirnamenormpathabspathappendmaxrA   )selfr   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   r   r   rF   suppress_entityr   r3   r3   rM   __init__   s@   
"zTraceback.__init__r   r   rF   rB   c                C   s>   | j ||||	|
|||d}| |||||||	||
|||||dS )a  Create a traceback from exception info

        Args:
            exc_type (Type[BaseException]): Exception type.
            exc_value (BaseException): Exception value.
            traceback (TracebackType): Python Traceback object.
            width (Optional[int], optional): Number of characters used to traceback. Defaults to 100.
            code_width (Optional[int], optional): Number of code characters used to traceback. Defaults to 88.
            extra_lines (int, optional): Additional lines of code to render. Defaults to 3.
            theme (str, optional): Override pygments theme used in traceback.
            word_wrap (bool, optional): Enable word wrapping of long lines. Defaults to False.
            show_locals (bool, optional): Enable display of local variables. Defaults to False.
            indent_guides (bool, optional): Enable indent guides in code and locals. Defaults to True.
            locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
                Defaults to 10.
            locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
            locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
            locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.
            suppress (Iterable[Union[str, ModuleType]]): Optional sequence of modules or paths to exclude from traceback.
            max_frames (int): Maximum number of frames to show in a traceback, 0 for no maximum. Defaults to 100.

        Returns:
            Traceback: A Traceback instance that may be printed.
        r:   r;   r<   r=   r>   )r5   r6   r7   r8   r9   r:   r?   r;   r<   r=   r>   r@   rA   )r   )clsr   r   rF   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rich_tracebackr3   r3   rM   rJ   *  s4   -zTraceback.from_exceptionr   c             	      s>  g }	d}
ddl m} dtdtfdd}	 t||j|||
d	}t|tr<t|j	p*d|j
p.d
|jp2d|jp6d|jd|_|	| |jj}dttttf  dttttf  f fdd}t|D ]\}}|jj}d}tjdkr|jd }tt|j ||d }|\}}}}|dur|dur|dur|dur||f||ff}|r|dstj |stj!||}|j"#ddrqat$|pd
||jj%|rՇfdd||j"& D nd|d}|| |j"#ddr|jdd= qat'|dd}|r|j(}|}|j)}d}
q|j*}|rt'|dds|j(}|}|j)}d}
q	 t+|	d}|S )a  Extract traceback information.

        Args:
            exc_type (Type[BaseException]): Exception type.
            exc_value (BaseException): Exception value.
            traceback (TracebackType): Python Traceback object.
            show_locals (bool, optional): Enable display of local variables. Defaults to False.
            locals_max_length (int, optional): Maximum length of containers before abbreviating, or None for no abbreviation.
                Defaults to 10.
            locals_max_string (int, optional): Maximum length of string before truncating, or None to disable. Defaults to 80.
            locals_hide_dunder (bool, optional): Hide locals prefixed with double underscore. Defaults to True.
            locals_hide_sunder (bool, optional): Hide locals prefixed with single underscore. Defaults to False.

        Returns:
            Trace: A Trace instance which you can use to construct a `Traceback`.
        Fr   )_IMPORT_CWD_objectrB   c                 S   s    zt | W S  ty   Y dS w )z1Don't allow exceptions from __str__ to propagate.z<exception str() failed>)rz   rl   )r   r3   r3   rM   safe_str  s
   
z#Traceback.extract.<locals>.safe_strT)r   r   r   ?rs   )r   rp   rq   rt   r   iter_localsc                 3   sT     ss| E dH  dS | D ]\}} r| drqr"| dr"q||fV  qdS )z-Extract locals from an iterator of key pairs.N__ra   
startswith)r   keyrE   )r=   r>   r3   rM   
get_locals  s   
z%Traceback.extract.<locals>.get_localsN)r2      rW   r   <_rich_traceback_omitc                    s6   i | ]\}}t |st |s|tj| d qS ))
max_length
max_string)inspect
isfunctionisclassr   traverse).0r   rE   )r;   r<   r3   rM   
<dictcomp>  s    z%Traceback.extract.<locals>.<dictcomp>)rp   rq   rr   ru   rv   _rich_traceback_guard	__cause____suppress_context__)r   ),pip._vendor.richr   r   rz   r   rw   r   SyntaxErrorr~   r   rp   rq   r   r   r   r   r   r   r   objectr   f_codeco_filenamerk   version_infof_lastinextr   co_positionsr   r   r   isabsjoinf_localsr[   ro   co_nameitemsgetattr	__class____traceback____context__r   )r   r   r   rF   r:   r;   r<   r=   r>   r   r   r   r   stackr   r   frame_summaryline_norp   rv   instruction_indexinstruction_position
start_lineend_linestart_column
end_columnframecauser   r3   )r=   r>   r;   r<   rM   r   s  s   





zTraceback.extractr4   optionsc                 c   sR   | j }| }|j}ti d|td|td|td|tjd|t	d|t
tdd d	|td
|ttdd d|t	d|tjd|tjd|tjd|tjd|td|td|tjtdd dd}t }tt| jjD ]\}}	|	jrt| |	d|dddd}
t|
| j}
|| |
V  W d    n1 sw   Y  |	jd ur|| tt| |	j|ddd| jd| jV  W d    n1 sw   Y  t|	j ddf||	jj V  n|	j!rt|	j ddf||	j!V  n
t|	j dfV  |s&|	j"r t#dV  qt#dV  qd S ) Nr   pygments.textpygments.stringpygments.functionpygments.numberzrepr.indentT)dimzrepr.strz
repr.brace)boldzrepr.numberzrepr.bool_truezrepr.bool_falsez	repr.nonezscope.borderzscope.equalsz	scope.keyzscope.key.specialF)inheritz7[traceback.title]Traceback [dim](most recent call last)ztraceback.border)r   r   )titlestyleborder_styleexpandpaddingztraceback.border.syntax_error)r   r   r   r   r5   z: ztraceback.exc_typezI
[i]The above exception was the direct cause of the following exception:
zH
[i]During handling of the above exception, another exception occurred:
)$r8   get_background_styleget_style_for_tokenr,   	TextTokenr   r   r   Functionr   r   r*   r   Constant	Delimiterr   r'   r   reversedr   r   r   r(   _render_stackr%   r5   	use_themer   _render_syntax_errorr   assembler   r   r   r   from_markup)r   r4   r   r8   background_styletoken_styletraceback_themehighlighterlastr   stack_renderabler3   r3   rM   __rich_console__  s   
	







zTraceback.__rich_console__r   c                 c   s    t  }t }|jdkr,tj|jr,tjd|j dfdt|j	dfdd}||V  ||j
 }d|_t|jd	 t|}|d
|| |tjdd|  d dd7 }|V  d S )Nz<stdin> r   :r   r   r   r   Tr   zbold underline
u   [traceback.offset]▲[/])r'   r   rp   r   r   existsr   r   rz   rq   rt   rstripno_wrapminr   lenstylizer   )r   r   r   path_highlighterr   syntax_error_textr   r3   r3   rM   r   _  s*   


zTraceback._render_syntax_errorrp   codec                 C   s   t j|d }|s(|d}|dkr|d | n|}|dr(d| v r(dS z| j|p4t||j	W S  t
y?   Y dS w )Nr  z#!r   r   )r   r   splitextindexr   lowerLEXERSr[   r   rr   r   )r   rp   r
  extnew_line_index
first_liner3   r3   rM   _guess_lexerv  s   
zTraceback._guess_lexerr   c                 #   s   t  }j}dtdtfdd}dtdtt ffdd}d }jdkr4tjd	 t|j	jd	  }d
}t
|j	D ]\}}	|rI||v rId}q;|ra|d usQJ tdt| ddddV  d
}|dk}
|	j t fddjD }tj|	jrtj|t|	jdddt|	jdfd|	jdfdd}ntjd|	jdfdt|	jdfdd}|	jds|
sdV  |V  |	jdr||	E d H  q;|s>z2||	j}|sW q;|	j|}t|||d|	jj |	jj f|	jhjjjd
d
}dV  W n ty } ztd| dfV  W Y d }~q;d }~ww |	jd ur,|	j\}}|jd||dd  |	jr;t |g||	d!d"n|V  q;d S )#Nrp   rB   c                 S   s   d t| S )zRead files, and cache results on filename.

            Args:
                filename (str): Filename to read

            Returns:
                str: Contents of file
            rs   )r   	linecachegetlines)rp   r3   r3   rM   	read_code  s   	z*Traceback._render_stack.<locals>.read_coder   c                 3   s,    | j rt| j d j j jdV  d S d S )Nru   )r   r?   r   r   )ru   r)   r?   r;   r<   )r   )r   r3   rM   render_locals  s   z.Traceback._render_stack.<locals>.render_localsr   rW   FTz
... z frames hidden ...centerztraceback.error)justifyr   c                 3   s    | ]}  |V  qd S Nr   )r   r   )frame_filenamer3   rM   	<genexpr>  s    z*Traceback._render_stack.<locals>.<genexpr>r   r   r   r   z in r   r   zin r   rs   )r8   line_numbers
line_rangehighlight_linesr9   r6   r?   dedentr  ztraceback.error_range)r   startendstyle_beforer   )r   )!r   r8   rz   ro   r   r"   rA   r\   r  r   	enumerater   rp   anyr@   r   r   r  r   rq   rr   r   r  r+   r7   r9   r6   r?   rl   rv   stylize_rangeru   r   )r   r   r  r8   r  r  exclude_framesexcludedframe_indexr   first
suppressedr   r
  
lexer_namesyntaxerrorr!  r"  r3   )r  r   rM   r     s   

	




zTraceback._render_stackr  )!rw   rx   ry   __doc__r  LOCALS_MAX_LENGTHLOCALS_MAX_STRINGr   r   r|   rz   rK   r   r   r   r   classmethodr   r   ri   r   rJ   r   r    r!   r#   r   r$   r~   r   r  r   r   r3   r3   r3   rM   rI      s   
	

5	
H	
 
NrI   __main__r   ac                 C   s   d}t ||   d S )Nr   )rH   )r4  oner3   r3   rM   bar  s   r6  c                 C   s   d}h ddd}t |  d S )NT>   Duncan IdahoThufir HawatPaul AtreidesVladimir Harkonnen)NFT)
charactersatomic_types)r6  )r4  r   zedr3   r3   rM   foo  s
   	r>  c                   C   s   t d d S )Nr   )r>  r3   r3   r3   rM   r.    s   r.  )rB   N)Vr   r  r   rk   dataclassesr   r   	itertoolsr   rF   r   typesr   r   typingr   r	   r
   r   r   r   r   r   r   r   pip._vendor.pygments.lexersr   pip._vendor.pygments.tokenr   r   r   r   r   r   r   r   r   pip._vendor.pygments.utilr   rs   r   _loopr   columnsr   r4   r    r!   r"   r#   r$   	constrainr%   r   r&   r'   panelr(   scoper)   r   r*   r-  r+   r   r8   r,   platformWINDOWSr0  r1  r|   rz   rK   ri   rn   ro   r~   r   r   r   rI   rw   r6  r>  r.  r3   r3   r3   rM   <module>   s    0 
	

 	    
1



