a
    sh                     @   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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+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9m:Z: ddl;m<Z< ddl=m>Z> ddl?m@Z@ ddlAmBZBmCZC dd	lDm#Z# ddlEmFZF ejGdkZHdZIdZJeCeCeeeKeKeKf  dddZLdddd dd!d!eIeJd"dd"d#dd$ee0 eeK eeK eKeeM eNeNeKeKeNeeN eNeeeMef  eKeeeO eOee gef d%d&d'ZPeG d(d) d)ZQeG d*d+ d+ZReG d,d- d-ZSeG d.d/ d/ZTG d0d1 d1e9ZUG d2d3 d3ZVeWd4krePd"d5 d dlZedd6d7d8ZXedd6d9d:ZYdd;d<d=ZZeZ  dS )>    N)	dataclassfield)islice)walk_tb)
ModuleTypeTracebackType)AnyCallableDictIterableListOptionalSequenceSetTupleTypeUnion)guess_lexer_for_filename)CommentKeywordNameNumberOperatorString)Text)Token)ClassNotFound   )pretty)loop_first_last	loop_last)Columns)ConsoleConsoleOptionsConsoleRenderableGroupRenderResultgroup)	Constrain)RegexHighlighterReprHighlighter)Panel)render_scope)Style)SyntaxSyntaxPosition)Themewin32
   P   )startendreturnc           	      c   sx   | \}}|\}}||kr&|||fV  nNt t||d D ]:\}}}|rT||dfV  q8|rf|d|fV  q8|ddfV  q8dS )zYield start and end positions per line.

    Args:
        start: Start position.
        end: End position.

    Returns:
        Iterable of (LINE, COLUMN1, COLUMN2).
    r   r   N)r   range)	r4   r5   line1column1Zline2column2firstlastline_no r?   V/var/www/html/assistant/venv/lib/python3.9/site-packages/pip/_vendor/rich/traceback.py_iter_syntax_lines7   s    rA   d   X      FTr?   )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_frames)rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   r6   c                    s   | du rt ddn| jr(du r(dntt ttt dd 	
fddtddfdd	}zt }|| tj	W S  t
y   tj	}t_	| Y S 0 dS )
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	tracebackr6   c                    s<   t j| || 
t	d}| d S )NrF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   )	Tracebackfrom_exceptionboolprint)rT   rU   rV   Zexception_traceback)rG   rH   rP   rN   rO   rL   rM   rR   rK   rQ   rI   traceback_consolerF   rJ   r?   r@   
excepthook   s&    zinstall.<locals>.excepthook)ipr6   c                    sb   i j  ttd d fdd}ddtttd dfdd_|_ fd	d
_d S )N)argskwargsr6   c                     s   | | i | dS )zEwrap the default ip.showtraceback to store info for ip._showtracebackNr?   r_   r`   )default_showtracebacktb_datar?   r@   ipy_show_traceback   s    zCinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_show_tracebackF)	is_syntax)r_   re   r`   r6   c                    s~     }| rdn|d }dd}d}|du rB|r>dnd}t|D ]}|du rZ qb|j}qJ |d |d | i dS )z2Internally called traceback from ip._showtracebackN   Zrunning_compiled_codeF	tb_offsetr   r   )Z_get_exc_infogetr8   tb_next)re   r_   r`   Z	exc_tupletbZcompiledrg   _)r]   r^   rc   r?   r@   ipy_display_traceback   s    
zFinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_display_tracebackc                     s    | ddi|S )Nre   Tr?   ra   )rl   r?   r@   <lambda>   s   z9install.<locals>.ipy_excepthook_closure.<locals>.<lambda>)Zshowtracebackr   rZ   Z_showtracebackZshowsyntaxerror)r^   rd   )r]   )rb   r^   rl   rc   r@   ipy_excepthook_closure   s    z'install.<locals>.ipy_excepthook_closure)r"   Z
is_jupyterr   BaseExceptionr   r   r   Zget_ipythonsysr]   	Exception)rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rn   r^   old_excepthookr?   )rG   r]   rH   rP   rN   rO   rL   rM   rR   rK   rQ   rI   r\   rF   rJ   r@   installS   s*    +*+rs   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__intry   rz   r   r
   r   Noder{   r   r?   r?   r?   r@   rt      s   
rt   c                   @   sL   e Zd ZU eed< eed< eed< eed< eed< eedZe	e ed< dS )	_SyntaxErroroffsetru   ry   rv   msgdefault_factorynotesN)
r|   r}   r~   r   r   r   r   listr   r   r?   r?   r?   r@   r      s   
r   c                   @   s   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< e
edZee ed	< dZe	ed
< e
edZed ed< dS )Stackexc_type	exc_valueNsyntax_errorFis_causer   framesr   is_groupTrace
exceptions)r|   r}   r~   r   r   r   r   r   r   rZ   r   r   r   r   rt   r   r   r   r?   r?   r?   r@   r      s   
r   c                   @   s   e Zd ZU ee ed< dS )r   stacksN)r|   r}   r~   r   r   r   r?   r?   r?   r@   r      s   
r   c                   @   s   e Zd ZdgZdS )PathHighlighterz(?P<dim>.*/)(?P<bold>.+)N)r|   r}   r~   Z
highlightsr?   r?   r?   r@   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ddddee ee	 ee	 e	ee
 eee	e	eeeeee
ef  e	dddZedd	d
dddeeddddddee eee ee	 ee	 e	ee
 eee	e	eeeeee
ef  e	d dddZedeeddddee eee ee	e	eeeee  ed
ddZeeedddZe eedddZee
e
e
dd d!Ze e ed"d#d$Z!dS )&rX   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pythonZcythonZpyrex)rx   z.pyz.pxdz.pyxz.pxiNrB   rC   rD   FTr?   rW   )tracerF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   c                C   s  |d u rHt  \}}}|d u s.|d u s.|d u r6td| j||||d}|| _|| _|| _|| _t	|pjd| _
|| _|| _|| _|| _|	| _|
| _|| _g | _|D ]Z}t|ts|jd usJ |dtj|j}n|}tjtj|}| j| q|dkrtd|nd| _d S )Nz9Value for 'trace' required if not called in except: blockrK   Z	ansi_darkz+ must be a module with '__file__' attributer      )rp   exc_info
ValueErrorextractr   rF   rG   rH   r.   Z	get_themerI   rJ   rK   rP   rL   rM   rN   rO   rQ   
isinstancer   __file__ospathdirnamenormpathabspathappendmaxrR   )selfr   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   r   r   rV   Zsuppress_entityr   r?   r?   r@   __init__  sB    
zTraceback.__init__)r   r   rV   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   r6   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.
        )rK   rL   rM   rN   rO   )rF   rG   rH   rI   rJ   rK   rP   rL   rM   rN   rO   rQ   rR   )r   )clsr   r   rV   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   Zrich_tracebackr?   r?   r@   rY   S  s4    -zTraceback.from_exception)rK   rL   rM   rN   rO   _visited_exceptions)
r   r   rV   rK   rL   rM   rN   rO   r   r6   c          !         s  g }
d}ddl m} t|ddp"g }|	du r2t n|	}ttddd}t||j||||d	}tj	d
krt
|ttfrd|_|jD ]@}||v rq|| |jtjt|||j| |d qt
|trt|jpd|jpd|jpd|jpd|j|d|_|
| |jj}tttt f  tttt f  d fdd}t!|D ]0\}}|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st)j*+|st)j*,||}|j-.ddrqJt/|p d||j"j0|rLfdd||j-1 D nd|d}|| |j-.ddrJ|jdd= qJ|st|dd}|dur||ur|j2}|}|j}d}qF|j3}|durt|dds|j2}|}|j}d}qFqqFt4|
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_CWDZ	__notes__N)_objectr6   c                 S   s$   z
t | W S  ty   Y dS 0 dS )z1Don't allow exceptions from __str__ to propagate.z<exception str() failed>N)r   rq   )r   r?   r?   r@   safe_str  s    
z#Traceback.extract.<locals>.safe_str)r   r   r   r   )rD      T)rK   rL   rN   rO   r   ?rx   )r   ru   rv   ry   r   r   )iter_localsr6   c                 3   sR    ss| E dH  dS | D ]2\}} r2| dr2qrB| drBq||fV  qdS )z-Extract locals from an iterator of key pairs.N__rk   
startswith)r   keyrU   )rN   rO   r?   r@   
get_locals  s    
z%Traceback.extract.<locals>.get_localsrf   r   <Z_rich_traceback_omitc                    s6   i | ].\}}t |st |s|tj| d qS ))
max_length
max_string)inspect
isfunctionisclassr   traverse).0r   rU   )rL   rM   r?   r@   
<dictcomp>.  s   z%Traceback.extract.<locals>.<dictcomp>)ru   rv   rw   rz   r{   _rich_traceback_guard	__cause____suppress_context__)r   )5Zpip._vendor.richr   getattrsetr   r   r   r|   rp   version_infor   ZBaseExceptionGroupZExceptionGroupr   r   addr   rX   r   type__traceback__SyntaxErrorr   r   ru   rv   r   r   r   r   r   r   objectr   f_codeco_filenamef_lastinextr   Zco_positionsr   r   r   isabsjoinf_localsrh   rt   co_nameitems	__class____context__r   )!r   r   r   rV   rK   rL   rM   rN   rO   r   r   r   r   r   grouped_exceptionsr   stack	exceptionr   r   frame_summaryr>   ru   r{   Zinstruction_indexZinstruction_positionZ
start_lineZend_lineZstart_columnZ
end_columnframecauser   r?   )rN   rO   rL   rM   r@   r     s    


	



zTraceback.extract)rE   optionsr6   c                 #   s  j }|  |j}t|t|t|t|tj|t	|t
tdd |t|ttdd |t	|tj|tj|tj|tj|t|t|tjtdd dddt t tttd fdd	ttjjD ]\}}||V  qd S )
NT)Zdim)Zbold)r   pygments.textpygments.stringpygments.functionpygments.numberzrepr.indentzrepr.strz
repr.bracezrepr.numberzrepr.bool_truezrepr.bool_falsez	repr.nonezscope.borderzscope.equalsz	scope.keyzscope.key.specialF)Zinherit)r   r=   r6   c           	   
   3   s  | j r\t| d dddd}t|j} |V  W d    n1 sR0    Y  | jd ur܈8 tt| j dddjdjV  W d    n1 s0    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  | jD ]}t	d
|V  q | jrt| jdD ]\\}}g }t|jD ]\}}||| qddV  ttt| d| ddjV  qN|s| jrtdV  ntdV  d S )Nz7[traceback.title]Traceback [dim](most recent call last)ztraceback.borderT)r   r   )titlestyleborder_styleexpandpaddingztraceback.border.syntax_error)r   r   r   r   rF   z: ztraceback.exc_type)z[NOTE] ztraceback.noter   rx   zSub-exception #ztraceback.group.border)r   r   zI
[i]The above exception was the direct cause of the following exception:
zH
[i]During handling of the above exception, another exception occurred:
)r   r+   _render_stackr(   rF   Z	use_themer   _render_syntax_errorr   assembler   r   r   r   r   	enumerater   r    r   r   r%   r   from_markup)	r   r=   Zstack_renderableZnoteZgroup_noZgroup_exceptionr   Z
group_lastZgroup_stackZbackground_stylerE   highlighterrender_stackr   Ztraceback_themer?   r@   r   z  sv    $

$


	z0Traceback.__rich_console__.<locals>.render_stack)rI   Zget_background_styleZget_style_for_tokenr0   	TextTokenr   r   r   ZFunctionr   r   r-   r   ConstantZ	Delimiterr   r*   r'   r   rZ   r&   r    reversedr   r   )r   rE   r   rI   Ztoken_styler=   r   r?   r   r@   __rich_console__[  s8    "CzTraceback.__rich_console__)r   r6   c                 c   s   t  }t }|jdkrVtj|jrVt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   ru   r   r   existsr   r   r   rv   ry   rstripZno_wrapminr   lenZstylizer   )r   r   r   path_highlighterr   Zsyntax_error_textr   r?   r?   r@   r     s(    

zTraceback._render_syntax_error)ru   coder6   c                 C   s   t j|d }|sP|d}|dkr2|d | n|}|drPd| v rPdS z| j|pht||j	W S  t
y~   Y dS 0 d S )Nr7   r   z#!r   r   )r   r   splitextindexr   lowerLEXERSrh   r   rw   r   )r   ru   r   extZnew_line_index
first_liner?   r?   r@   _guess_lexer  s    
zTraceback._guess_lexer)r   r6   c                 #   s  t  }j}ttt dfdd}d }jdkrRtjd t|jjd  }d}t	|jD ]\}}|r|||v r|d}q`|r|d usJ t
dt| d	d
ddV  d}|dk}	|j t fddjD }
tj|jrt
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sV|	sVdV  |V  |jdrz||E d H  q`|
s`zrt|j}d|}|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 }~0 0 |j d ur|j \}}t!||D ]\}}}zH|dkr||d  }t|t|"  }|dkrt||d  }W n t#y   Y qNY n0 |j$d||f||fd qN|j%rt&|g||ddn|V  q`d S ) N)r   r6   c                 3   s&   | j r"t| j d j j jdV  d S )Nrz   )r   rP   r   r   )rz   r,   rP   rL   rM   )r   )r   r?   r@   render_locals  s    z.Traceback._render_stack.<locals>.render_localsr   rf   FTz
... z frames hidden ...centerztraceback.error)Zjustifyr   c                 3   s   | ]}  |V  qd S )Nr   )r   r   )frame_filenamer?   r@   	<genexpr>      z*Traceback._render_stack.<locals>.<genexpr>r   r   r   r   z in r   r   zin r   rx   )rI   Zline_numbersZ
line_rangeZhighlight_linesrJ   rG   rP   dedentr   r   r7   ztraceback.error_range)r   r4   r5   )r   )'r   rI   rt   r   r$   rR   r8   r   r   r   r   ru   anyrQ   r   r   r   r   r   rv   rw   r   	linecachegetlinesr   r  r.   rH   rJ   rG   rP   rq   r{   rA   lstrip
IndexErrorZstylize_rangerz   r!   )r   r   r   rI   r  Zexclude_framesZexcludedZframe_indexr   r<   Z
suppressedr   Z
code_linesr   Z
lexer_namesyntaxerrorr4   r5   r9   r:   r;   ry   r?   )r  r   r@   r     s    

	







zTraceback._render_stack)N)"r|   r}   r~   __doc__r   LOCALS_MAX_LENGTHLOCALS_MAX_STRINGr   r   r   r   rZ   r   r   r   r   classmethodr   r   ro   r   rY   r   r   r"   r#   r&   r   r'   r   r   r  r   r   r?   r?   r?   r@   rX      s   
 5H
 @frX   __main__r   )ar6   c                 C   s   d}t ||   d S )Nr   )r[   )r  Zoner?   r?   r@   barm  s    r  c                 C   s   d}h ddd}t |  d S )NT>   zThufir HawatzDuncan IdahozPaul AtreideszVladimir Harkonnen)NFT)
charactersZatomic_types)r  )r  r   Zzedr?   r?   r@   foos  s
    	r  )r6   c                   C   s   t d d S )Nr   )r  r?   r?   r?   r@   r    s    r  )[r   r	  r   rp   Zdataclassesr   r   	itertoolsr   rV   r   typesr   r   typingr   r	   r
   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   Zpip._vendor.pygments.utilr   rx   r   Z_loopr   r    columnsr!   rE   r"   r#   r$   r%   r&   r'   Z	constrainr(   r   r)   r*   Zpanelr+   Zscoper,   r   r-   r  r.   r/   r   rI   r0   platformWINDOWSr  r  r   rA   r   rZ   ro   rs   rt   r   r   r   r   rX   r|   r  r  r  r?   r?   r?   r@   <module>   s   4  
 		    n

