o
    1cOe                     @   s  d dl m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mZ d dl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&m'Z' ddl(m)Z) ddl*m+Z+m,Z,m-Z-m.Z.m/Z/ ddl0m1Z1 ddl2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: ddl;m<Z< dd	l=m Z  ddl>m?Z? e@ dkZAdZBdZCdddddddddd	d ee+ d!eeD d"eDd#eeE d$eFd%eFd&eFd'eeeEef  d(eDd)eeeG eGee gef fd*d+ZHeG d,d- d-ZIeG d.d/ d/ZJeG d0d1 d1ZKeG d2d3 d3ZLG d4d5 d5e3ZMG d6d7 d7ZNeOd8krZdd9l*m+Z+ e+ Z*d dlZd:ed)dfd;d<ZPd:ed)dfd=d>ZQdAd?d@ZReR  dS dS )B    )absolute_importN)	dataclassfield)walk_tb)
ModuleTypeTracebackType)	AnyCallableDictIterableListOptionalSequenceTypeUnion)guess_lexer_for_filename)CommentKeywordNameNumberOperatorString)Text)Token   )pretty)
loop_first	loop_last)Columns)ConsoleConsoleOptionsConsoleRenderableRenderResultgroup)	Constrain)RegexHighlighterReprHighlighter)Panel)render_scope)Style)Syntax)ThemeWindows
   P   d      FT )	consolewidthextra_linestheme	word_wrapshow_localsindent_guidessuppress
max_framesr2   r3   r4   r5   r6   r7   r8   r9   r:   returnc        	      
      s   | du r
t tj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
yN   tj	} t_	| Y S w )a8  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.
        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.
        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.

    N)filetype_value	tracebackr;   c                    s*    tj| || d d S )N)r3   r4   r5   r6   r7   r8   r9   r:   )print	Tracebackfrom_exception)r=   r>   r?   )	r4   r8   r:   r7   r9   r5   traceback_consoler3   r6   r1   S/var/www/html/django/env/lib/python3.10/site-packages/pip/_vendor/rich/traceback.py
excepthookE   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kwargsr;   c                     s   | | i | dS )zEwrap the default ip.showtraceback to store info for ip._showtracebackNr1   rG   rH   )default_showtracebacktb_datar1   rD   ipy_show_traceback^   s   zCinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_show_tracebackF)	is_syntaxrM   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   Zrunning_compiled_codeF	tb_offsetr   r   )Z_get_exc_infogetrangetb_next)rM   rG   rH   Z	exc_tupletbZcompiledrO   _)rE   rF   rK   r1   rD   ipy_display_tracebackd   s   zFinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_display_tracebackc                     s    | ddi|S )NrM   Tr1   rI   )rU   r1   rD   <lambda>   s    z9install.<locals>.ipy_excepthook_closure.<locals>.<lambda>)Zshowtracebackr   boolZ_showtracebackZshowsyntaxerror)rF   rL   )rE   )rJ   rF   rU   rK   rD   ipy_excepthook_closureZ   s    z'install.<locals>.ipy_excepthook_closure)r   sysstderrr   BaseExceptionr   r   r   get_ipythonrE   	Exception)r2   r3   r4   r5   r6   r7   r8   r9   r:   rX   rF   old_excepthookr1   )
rE   r4   r8   r:   r7   r9   r5   rC   r3   r6   rD   install#   s(    )r_   c                   @   sL   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S )Framefilenamelinenoname lineNlocals)__name__
__module____qualname__str__annotations__intre   rf   r   r
   r   Noder1   r1   r1   rD   r`      s   
 r`   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offsetra   re   rb   msgN)rg   rh   ri   rl   rk   rj   r1   r1   r1   rD   rn      s   
 rn   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)rg   rh   ri   rj   rk   rt   r   rn   ru   rW   r   listrw   r   r`   r1   r1   r1   rD   rq      s   
 rq   c                   @   s   e Zd ZU ee ed< dS )TracestacksN)rg   rh   ri   r   rq   rk   r1   r1   r1   rD   ry      s   
 ry   c                   @   s   e Zd ZdgZdS )PathHighlighterz(?P<dim>.*/)(?P<bold>.+)N)rg   rh   ri   
highlightsr1   r1   r1   rD   r{      s    
r{   c                   @   s  e Zd ZdZddddddZddd	dd
d
deeddfdee dee	 de	de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f
dee dedee dee	 de	de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fdee dede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
d*e
de
fd+d,Ze d-edefd.d/Z dS )0rA   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.
        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.
        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pythonZcythonZpyrex)rd   z.pyz.pxdz.pyxz.pxiNr/   r0   FTr1   tracer3   r4   r5   r6   r7   r8   locals_max_lengthlocals_max_stringr9   r:   c                 C   s  |d u r$t  \}}}|d u s|d u s|d u rtd| j||||d}|| _|| _|| _t|p2d| _	|| _
|| _|| _|| _|	| _g | _|
D ]-}t|tsd|jd us\J |dtj|j}n|}tjtj|}| j| qI|dkrtd|| _d S d| _d S )Nz9Value for 'trace' required if not called in except: blockr7   Z	ansi_darkz+ must be a module with '__file__' attributer      )rY   exc_info
ValueErrorextractr   r3   r4   r*   Z	get_themer5   r6   r7   r8   r   r   r9   
isinstancerj   __file__ospathdirnamenormpathabspathappendmaxr:   )selfr   r3   r4   r5   r6   r7   r8   r   r   r9   r:   rr   rs   r?   Zsuppress_entityr   r1   r1   rD   __init__   s<   
"zTraceback.__init__rr   rs   r?   r;   c                 C   s0   | 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.
            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.
            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   )
r3   r4   r5   r6   r7   r8   r   r   r9   r:   )r   )clsrr   rs   r?   r3   r4   r5   r6   r7   r8   r   r   r9   r:   Zrich_tracebackr1   r1   rD   rB      s    &zTraceback.from_exceptionc                    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}t|D ]F\}}|jj}|re|dsetj|setj|	|}t|pid
||jj|r| fdd|j D ndd}|| d|jv r|jdd= qIt|dd}|r|jr|j}|}|j}|rd}q|j }|r|jrt|dds|j}|}|j}|rd}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.

        Returns:
            Trace: A Trace instance which you can use to construct a `Traceback`.
        Fr   )_IMPORT_CWD_objectr;   c                 S   s    zt | W S  ty   Y dS w )z1Don't allow exceptions from __str__ to propegate.z<exception str() failed>)rj   r]   )r   r1   r1   rD   safe_strR  s
   
z#Traceback.extract.<locals>.safe_strT)rr   rs   ru   ?rd   )ro   ra   rb   re   rp   <c                    s"   i | ]\}}|t j| d qS ))
max_length
max_string)r   traverse).0keyr>   r   r   r1   rD   
<dictcomp>u  s    z%Traceback.extract.<locals>.<dictcomp>N)ra   rb   rc   rf   _rich_traceback_guard	__cause____suppress_context__)rz   )"pip._vendor.richr   r   rj   rq   rg   r   SyntaxErrorrn   ro   ra   rb   r}   rp   rt   r   rw   r   f_codeco_filename
startswithr   r   isabsjoinr`   co_namef_localsitemsgetattr__traceback__	__class____context__ry   )r   rr   rs   r?   r7   r   r   rz   ru   r   r   stackr   Zframe_summaryline_nora   framecauser   r1   r   rD   r   4  s~   

		



zTraceback.extractr2   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   r3   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:
)$r5   Zget_background_styleZget_style_for_tokenr+   	TextTokenr   r   r   ZFunctionr   r   r)   r   ConstantZ	Delimiterr   r&   r   reversedr   rz   rw   r'   _render_stackr$   r3   	use_themert   _render_syntax_errorr   assemblerr   rp   rs   ru   from_markup)r   r2   r   r5   background_styleZtoken_styleZtraceback_themehighlighterlastr   Zstack_renderabler1   r1   rD   __rich_console__  s   
	







zTraceback.__rich_console__rt   c                 c   s    t  }t }|jdk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{   ra   r   r   rj   rb   re   rstripno_wrapminro   lenstylizer   )r   rt   r   path_highlighterr}   Zsyntax_error_textro   r1   r1   rD   r     s(   


zTraceback._render_syntax_errorra   codec                 C   sl   t j|d }|s(|d}|dkr|d | n|}|dr(d| v r(dS | j|p3t||j	}|S )Nr   z#!r~   )
r   r   splitextindexr   lowerLEXERSrP   r   rc   )r   ra   r   extZnew_line_index
first_line
lexer_namer1   r1   rD   _guess_lexer  s   
zTraceback._guess_lexerr   c                 #   s    t  }j}i  dtdtf fdd}dtdtt ffdd}d }jdkr8tjd	 t|j	jd	  }d
}t
|j	D ]\}}	|rL||v rLd}q?|rd|d usTJ tdt| ddddV  d
}|dk}
|	jtfddjD }tj|t|	jdddt|	jdfd|	jdfdd}|	jds|
sdV  |V  |	jdr||	E d H  q?|sz-||	j}|	j|}t|||d|	jj |	jj f|	jhjdjd
d
}dV  W n ty } ztd| dfV  W Y d }~q?d }~ww |	jr
t|g||	dd n|V  q?d S )!Nra   r;   c                    sV     | }|du r)t| dddd}| }W d   n1 s w   Y  | | < |S )zRead files, and cache results on filename.

            Args:
                filename (str): Filename to read

            Returns:
                str: Contents of file
            Nrtzutf-8replace)encodingerrors)rP   openread)ra   r   Z	code_file)
code_cacher1   rD   	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 )Nrf   )r   r8   r   r   )rf   r(   r8   r   r   )r   )r   r1   rD   render_locals+  s   z.Traceback._render_stack.<locals>.render_localsr   rN   FTz
... z frames hidden ...centerztraceback.error)justifyr   r   c                 3   s    | ]}  |V  qd S )N)r   )r   r   )frame_filenamer1   rD   	<genexpr>N  s    z*Traceback._render_stack.<locals>.<genexpr>r   r   r   r   z in r   r   r   rd   X   )r5   Zline_numbersZ
line_rangeZhighlight_linesr6   Z
code_widthr8   dedentr   )r   )r{   r5   rj   r`   r   r!   r:   rQ   r   rw   	enumerater   ra   anyr9   r   rb   rc   r   r   r*   r4   r6   r8   r]   rf   r   )r   r   r   r5   r   r   Zexclude_framesZexcludedZframe_indexr   firstZ
suppressedr}   r   r   syntaxerrorr1   )r   r   r   rD   r     s   





zTraceback._render_stack)!rg   rh   ri   __doc__r   LOCALS_MAX_LENGTHLOCALS_MAX_STRINGr   ry   rl   rj   rW   r   r   r   r   classmethodr   r   r[   r   rB   r   r   r    r"   r   r#   rn   r   r   rq   r   r1   r1   r1   rD   rA      s    
	

.	
6j
NrA   __main__)r   ac                 C   s   d}t ||   d S )Nr   )r@   )r   oner1   r1   rD   bar  s   r   c                 C   s   d}h ddd}t |  d S )NT>   Duncan IdahoThufir HawatPaul AtreidesVladimir Harkonnen)NFT)
charactersZatomic_types)r   )r   r   Zzedr1   r1   rD   foo  s
   	r  c                   C   s>   zzt d W W d S    t Y W d S    tjdd Y d S )Nr   Tr   )r  Zslfkjsldkfjr2   print_exceptionr1   r1   r1   rD   r     s   r   )r;   N)S
__future__r   r   platformrY   dataclassesr   r   r?   r   typesr   r   typingr   r	   r
   r   r   r   r   r   r   Zpip._vendor.pygments.lexersr   Zpip._vendor.pygments.tokenr   r   r   r   r   r   r   r   r   rd   r   _loopr   r   columnsr   r2   r   r    r!   r"   r#   	constrainr$   r   r%   r&   panelr'   scoper(   r   r)   r   r*   r}   r5   r+   systemWINDOWSr   r   rl   rj   rW   r[   r_   r`   rn   rq   ry   r{   rA   rg   r   r  r   r1   r1   r1   rD   <module>   s    , 	

l   
T


