a
    $lJhb                     @   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*m+Z+ ddl,m-Z- ddl.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9 ddl:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZAmBZB dd	lCm"Z" ddlDmEZE ejFdkZGdZHdZIeBeBeeeJeJeJf  dddZKdddd dd!d!eHeId"dd"d#dd$ee/ eeJ eeJ eJeeL eMeMeJeJeMeeM eMeeeLef  eJeeeN eNee gef d%d&d'ZOeG d(d) d)ZPeG d*d+ d+ZQeG d,d- d-ZReG d.d/ d/ZSG d0d1 d1e8ZTG d2d3 d3ZUeVd4kreOd"d5 d dlZedd6d7d8ZWedd6d9d:ZXdd;d<d=ZYeY  dS )>    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_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)	r3   r4   line1column1Zline2column2firstlastline_no r>   L/var/www/shaz/venv/lib/python3.9/site-packages/pip/_vendor/rich/traceback.py_iter_syntax_lines6   s    r@   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)rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r5   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	tracebackr5   c                    s<   t j| || 
t	d}| d S )NrE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   )	Tracebackfrom_exceptionboolprint)rS   rT   rU   Zexception_traceback)rF   rG   rO   rM   rN   rK   rL   rQ   rJ   rP   rH   traceback_consolerE   rI   r>   r?   
excepthook   s&    zinstall.<locals>.excepthook)ipr5   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kwargsr5   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^   rd   r_   r5   c                    st     }| rdn|d }dd}d|r2dnd}t|D ]}|du rP qX|j}q@ |d |d | i dS )z2Internally called traceback from ip._showtracebackN   Zrunning_compiled_codeF	tb_offsetr   r   )Z_get_exc_infogetr7   tb_next)rd   r^   r_   Z	exc_tupletbZcompiledrf   _)r\   r]   rb   r>   r?   ipy_display_traceback   s    zFinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_display_tracebackc                     s    | ddi|S )Nrd   Tr>   r`   )rk   r>   r?   <lambda>   s   z9install.<locals>.ipy_excepthook_closure.<locals>.<lambda>)Zshowtracebackr   rY   Z_showtracebackZshowsyntaxerror)r]   rc   )r\   )ra   r]   rk   rb   r?   ipy_excepthook_closure   s    z'install.<locals>.ipy_excepthook_closure)r!   Z
is_jupyterr   BaseExceptionr   r   r   Zget_ipythonsysr\   	Exception)rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rm   r]   old_excepthookr>   )rF   r\   rG   rO   rM   rN   rK   rL   rQ   rJ   rP   rH   r[   rE   rI   r?   installR   s*    +*)rr   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__intrx   ry   r   r
   r   Noderz   r   r>   r>   r>   r?   rs      s   
rs   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offsetrt   rx   ru   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   rY   r   r   r   r   rs   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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 )&rW   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)rw   z.pyz.pxdz.pyxz.pxiNrA   rB   rC   FTr>   rV   )tracerE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   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rJ   Z	ansi_darkz+ must be a module with '__file__' attributer      )ro   exc_info
ValueErrorextractr   rE   rF   rG   r-   Z	get_themerH   rI   rJ   rO   rK   rL   rM   rN   rP   
isinstancer~   __file__ospathdirnamenormpathabspathappendmaxrQ   )selfr   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r   r   rU   Zsuppress_entityr   r>   r>   r?   __init__  sB    
zTraceback.__init__)r   r   rU   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   r5   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.
        rJ   rK   rL   rM   rN   )rE   rF   rG   rH   rI   rJ   rO   rK   rL   rM   rN   rP   rQ   )r   )clsr   r   rU   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   Zrich_tracebackr>   r>   r?   rX   P  s4    -zTraceback.from_exceptionr   )	r   r   rU   rJ   rK   rL   rM   rN   r5   c                   s  g }	d}
ddl m} t|ddp"g }ttddd}t||j|||
|d	}tjd
krt	|t
tfrd|_|jD ]*}|jtjt|||j| d qrt	|trt|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st'j()|st'j(*||}|j+,ddrq t-|pd||j j.|r"fdd||j+/ D nd|d}|| |j+,ddr |jdd= q t|dd}|r||j0}|}|j}d}
q4|j1}|rt|dds|j0}|}|j}d}
q4qq4t2|	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)_objectr5   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~   rp   )r   r>   r>   r?   safe_str  s    
z#Traceback.extract.<locals>.safe_str)r   r   r   r   )rC      T)rJ   rK   rM   rN   ?rw   )r   rt   ru   rx   r   r   )iter_localsr5   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__rj   
startswith)r   keyrT   )rM   rN   r>   r?   
get_locals  s    
z%Traceback.extract.<locals>.get_localsre   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   rT   )rK   rL   r>   r?   
<dictcomp>"  s   z%Traceback.extract.<locals>.<dictcomp>)rt   ru   rv   ry   rz   _rich_traceback_guard	__cause____suppress_context__)r   )3Zpip._vendor.richr   getattrr   r~   r   r{   ro   version_infor   ZBaseExceptionGroupZExceptionGroupr   r   r   rW   r   type__traceback__SyntaxErrorr   r   rt   ru   r   r   r   r   r   r   objectr   f_codeco_filenamef_lastinextr   Zco_positionsr   r   r   isabsjoinf_localsrg   rs   co_nameitems	__class____context__r   )r   r   r   rU   rJ   rK   rL   rM   rN   r   r   r   r   r   stack	exceptionr   r   frame_summaryr=   rt   rz   Zinstruction_indexZinstruction_positionZ
start_lineZend_lineZstart_columnZ
end_columnframecauser   r>   )rM   rN   rK   rL   r?   r     s    


	



zTraceback.extract)rD   optionsr5   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<   r5   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   rE   z: ztraceback.exc_type)z[NOTE] ztraceback.noter   rw   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'   rE   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_exceptionZgrouped_exceptionsZ
group_lastZgroup_stackZbackground_stylerD   highlighterrender_stackr   Ztraceback_themer>   r?   r   k  sv    $

$


	z0Traceback.__rich_console__.<locals>.render_stack)rH   Zget_background_styleZget_style_for_tokenr/   	TextTokenr   r   r   ZFunctionr   r   r,   r   ConstantZ	Delimiterr   r)   r&   r   rY   r%   r   reversedr   r   )r   rD   r   rH   Ztoken_styler<   r   r>   r   r?   __rich_console__L  s8    "CzTraceback.__rich_console__)r   r5   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   rt   r   r   existsr   r   r~   ru   rx   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)rt   coder5   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 )Nr6   r   z#!r   r   )r   r   splitextindexr   lowerLEXERSrg   r   rv   r   )r   rt   r   extZnew_line_index
first_liner>   r>   r?   _guess_lexer  s    
zTraceback._guess_lexer)r   r5   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   r5   c                 3   s&   | j r"t| j d j j jdV  d S )Nry   )r   rO   r   r   )ry   r+   rO   rK   rL   )r   )r   r>   r?   render_locals  s    z.Traceback._render_stack.<locals>.render_localsr   re   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   rw   )rH   Zline_numbersZ
line_rangeZhighlight_linesrI   rF   rO   dedentr   r   r6   ztraceback.error_range)r   r3   r4   )r   )'r   rH   rs   r   r#   rQ   r7   r   r   r   r   rt   anyrP   r   r   r   r   r~   ru   rv   r   	linecachegetlinesr   r   r-   rG   rI   rF   rO   rp   rz   r@   lstrip
IndexErrorZstylize_rangery   r    )r   r   r   rH   r   Zexclude_framesZexcludedZframe_indexr   r;   Z
suppressedr   Z
code_linesr   Z
lexer_namesyntaxerrorr3   r4   r8   r9   r:   rx   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~   rY   r   r   r   r   classmethodr   r   rn   r   rX   r   r!   r"   r%   r   r&   r   r   r   r   r   r>   r>   r>   r?   rW      s   
 5H 4frW   __main__r   )ar5   c                 C   s   d}t ||   d S )Nr   )rZ   )r  Zoner>   r>   r?   bar^  s    r  c                 C   s   d}h ddd}t |  d S )NT>   zVladimir HarkonnenzThufir HawatzDuncan IdahozPaul Atreides)NFT)
charactersZatomic_types)r  )r  r   Zzedr>   r>   r?   food  s
    	r  )r5   c                   C   s   t d d S )Nr   )r  r>   r>   r>   r?   r
  q  s    r
  )Zr   r  r   ro   Zdataclassesr   r   	itertoolsr   rU   r   typesr   r   typingr   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   rw   r   Z_loopr   r   columnsr    rD   r!   r"   r#   r$   r%   r&   Z	constrainr'   r   r(   r)   Zpanelr*   Zscoper+   r   r,   r	  r-   r.   r   rH   r/   platformWINDOWSr  r  r   r@   r~   rY   rn   rr   rs   r   r   r   r   rW   r{   r  r  r
  r>   r>   r>   r?   <module>   s   0  
 		    b

