B
    ods                 @   s  d dl mZ 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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C dkZDdZEdZFddddddeEeFdddddd ee. eeG eGeeH eIeIeGeGeIeeI eIeeeHef  eGeeeJ eJee gef d!d"d#ZKeG d$d% d%ZLeG d&d' d'ZMeG d(d) d)ZNeG d*d+ d+ZOG d,d- d-e6ZPG d.d/ d/ZQeRd0krdd1l-m.Z. e. Z-d dlZedd2d3d4ZSedd2d5d6ZTdd7d8d9ZUeU  dS ):    )absolute_importN)	dataclassfield)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Windows
   P   d      FT )console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)r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   returnc                s   | dkrt ddn| jr(dkr(dntt ttt dd	
fdd tdd fdd	}yt }|| tj	S  t
k
r   tj	} t_	|S X 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.
        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	tracebackr@   c                s6   
 tj| || 	td d S )N)r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   )print	Tracebackfrom_exceptionbool)rB   rC   rD   )r5   r=   r;   r<   r9   r:   r?   r8   r>   r6   traceback_consoler4   r7   r2   L/var/www/html/venv/lib/python3.7/site-packages/pip/_vendor/rich/traceback.py
excepthooka   s"    zinstall.<locals>.excepthook)ipr@   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kwargsr@   c                 s   | | | dS )zEwrap the default ip.showtraceback to store info for ip._showtracebackNr2   )rM   rN   )default_showtracebacktb_datar2   rJ   ipy_show_traceback~   s    zCinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_show_tracebackF)	is_syntax)rM   rR   rN   r@   c                sv     }| rdn|d }dd}d|r2dnd}x t|D ]}|dkrPP |j}qBW  |d |d | i dS )z2Internally called traceback from ip._showtracebackN   running_compiled_codeF	tb_offsetr   r   )_get_exc_infogetrangetb_next)rR   rM   rN   	exc_tupletbcompiledrU   _)rK   rL   rP   r2   rJ   ipy_display_traceback   s    
zFinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_display_tracebackc                 s    | ddi|S )NrR   Tr2   )rM   rN   )r^   r2   rJ   <lambda>   s   z9install.<locals>.ipy_excepthook_closure.<locals>.<lambda>)showtracebackr   rH   _showtracebackshowsyntaxerror)rL   rQ   )rK   )rO   rL   r^   rP   rJ   ipy_excepthook_closurez   s    z'install.<locals>.ipy_excepthook_closure)r    
is_jupyterr   BaseExceptionr   r   r   get_ipythonsysrK   	Exception)r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   rc   rL   old_excepthookr2   )rK   r5   r=   r;   r<   r9   r:   r?   r8   r>   r6   rI   r4   r7   rJ   install0   s     )*)rj   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__intrp   rq   r   r
   r   Noder2   r2   r2   rJ   rk      s
   
rk   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offsetrl   rp   rm   msgN)rr   rs   rt   rw   rv   ru   r2   r2   r2   rJ   ry      s
   
ry   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)rr   rs   rt   ru   rv   r   r   ry   r   rH   r   listr   r   rk   r2   r2   r2   rJ   r|      s
   
r|   c               @   s   e Zd ZU ee ed< dS )TracestacksN)rr   rs   rt   r   r|   rv   r2   r2   r2   rJ   r      s   
r   c               @   s   e Zd ZdgZdS )PathHighlighterz(?P<dim>.*/)(?P<bold>.+)N)rr   rs   rt   
highlightsr2   r2   r2   rJ   r      s   r   c               @   sp  e Zd ZdZddddddZ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f  e	dddZe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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 )%rF   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.
        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)ro   z.pyz.pxdz.pyxz.pxiNr0   r1   FTr2   )r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   )tracer4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   c            C   s  |d krHt  \}}}|d ks.|d ks.|d kr6td| j||||d}|| _|| _|| _t|pdd| _	|| _
|| _|| _|| _|| _|	| _|
| _g | _xb|D ]Z}t|ts|jd k	st|dtj|j}n|}tjtj|}| j| qW |dkrtd|nd| _d S )Nz9Value for 'trace' required if not called in except: block)r8   	ansi_darkz+ must be a module with '__file__' attributer      )rg   exc_info
ValueErrorextractr   r4   r5   r+   	get_themer6   r7   r8   r=   r9   r:   r;   r<   r>   
isinstanceru   __file__AssertionErrorospathdirnamenormpathabspathappendmaxr?   )selfr   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r}   r~   rD   suppress_entityr   r2   r2   rJ   __init__   s8    

zTraceback.__init__)r}   r~   rD   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   c            C   s<   | j |||||	|
||d}| ||||||||	|
||||dS )ae  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.
            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.
        )r8   r9   r:   r;   r<   )r4   r5   r6   r7   r8   r=   r9   r:   r;   r<   r>   r?   )r   )clsr}   r~   rD   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   r>   r?   rich_tracebackr2   r2   rJ   rG   $  s.    +zTraceback.from_exception)r8   r9   r:   r;   r<   )	r}   r~   rD   r8   r9   r:   r;   r<   r@   c         	      s  g }	d}
ddl m} ttddd}xt||j|||
d}t|trxt|j	pTd|j
p\d|jpdd|jpld	|jd
|_|	| |jj}ttttf  ttttf  d fdd}xt|D ]\}}|jj}|r|dstj|stj||}|jddrqt|pd||jj|rBfdd||j  D ndd}|| |jddr|jdd= qW t!|dd}|r|j"}|}|j#}d}
q(|j$}|rt!|dds|j"}|}|j#}d}
q(P q(W 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)_objectr@   c             S   s"   yt | S  tk
r   dS X dS )z1Don't allow exceptions from __str__ to propagate.z<exception str() failed>N)ru   rh   )r   r2   r2   rJ   safe_str  s    z#Traceback.extract.<locals>.safe_str)r}   r~   r   ?ro   )rz   rl   rm   rp   r{   )iter_localsr@   c             3   sV    ss| E dH  dS x:| D ]2\}} r4| dr4qrD| drDq||fV  qW dS )z-Extract locals from an iterator of key pairs.N__r]   )
startswith)r   keyrC   )r;   r<   r2   rJ   
get_locals  s    
z%Traceback.extract.<locals>.get_locals<_rich_traceback_omitc                s"   i | ]\}}t j| d |qS ))
max_length
max_string)r   traverse).0r   rC   )r9   r:   r2   rJ   
<dictcomp>  s   z%Traceback.extract.<locals>.<dictcomp>N)rl   rm   rn   rq   _rich_traceback_guard	__cause__T__suppress_context__)r   )&pip._vendor.richr   r   ru   r|   rr   r   SyntaxErrorry   rz   rl   rm   r   r{   r   r   r   r   r   objectr   f_codeco_filenamer   r   r   isabsjoinf_localsrW   rk   co_nameitemsgetattr	__class____traceback____context__r   )r   r}   r~   rD   r8   r9   r:   r;   r<   r   r   r   r   stackr   r   frame_summaryline_norl   framecauser   r2   )r;   r<   r9   r:   rJ   r   j  sj    

 	$
zTraceback.extract)r3   optionsr@   c             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 }x:tt| jjD ]$\}}	|	jrt| |	d|ddd	d
}
t|
| j}
|| |
V  W d Q R X |	jd k	r||. tt| |	j|ddd	| jd| jV  W d Q R X t|	j ddf||	jj V  n>|	j!rt|	j ddf||	j!V  nt|	j dfV  |s|	j"rt#dV  qt#dV  qW d S )NT)dim)bold)r   zpygments.textzpygments.stringzpygments.functionz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)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   r4   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:
)$r6   get_background_styleget_style_for_tokenr,   	TextTokenr   r   r   Functionr   r   r*   r   Constant	Delimiterr   r'   r   reversedr   r   r   r(   _render_stackr%   r4   	use_themer   _render_syntax_errorr   assembler}   r{   r~   r   from_markup)r   r3   r   r6   background_styletoken_styletraceback_themehighlighterlastr   stack_renderabler2   r2   rJ   __rich_console__  sv    

zTraceback.__rich_console__)r   r@   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> zpygments.string):zpygments.textzpygments.numberzpygments.text)r   Tr   zbold underline
u   [traceback.offset]▲[/])r'   r   rl   r   r   existsr   r   ru   rm   rp   rstripno_wrapminrz   lenstylizer   )r   r   r   path_highlighterr   syntax_error_textrz   r2   r2   rJ   r   5  s$    


zTraceback._render_syntax_error)rl   coder@   c             C   s   t j|d }|sP|d}|dkr2|d | n|}|drPd| krPdS y| j|pht||j	S  t
k
r|   dS X d S )Nr   z#!r   r   )r   r   splitextindexr   lowerLEXERSrW   r   rn   r   )r   rl   r   extnew_line_index
first_liner2   r2   rJ   _guess_lexerL  s    
zTraceback._guess_lexer)r   r@   c             #   s\  t  }j}ttddd}ttt dfdd}d }jdkrbtjd t|j	jd  }d	}xt
|j	D ]\}}	|r||krd
}qt|r|d k	st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sj|
sjdV  |V  |	jdr||	E d H  qt|styb||	j}|swt|	j|}t|||d
|	jj |	jj f|	jhjdjd	d
}dV  W n: tk
r. } ztd| dfV  W d d }~X Y qtX |	jrNt|f||	dd n|V  qtW d S )!N)rl   r@   c             S   s   d t| S )zRead files, and cache results on filename.

            Args:
                filename (str): Filename to read

            Returns:
                str: Contents of file
            ro   )r   	linecachegetlines)rl   r2   r2   rJ   	read_codea  s    	z*Traceback._render_stack.<locals>.read_code)r   r@   c             3   s&   | j r"t| j d j j jdV  d S )Nrq   )r   r=   r   r   )rq   r)   r=   r9   r:   )r   )r   r2   rJ   render_localsl  s    z.Traceback._render_stack.<locals>.render_localsr   rS   FTz
... z frames hidden ...centerztraceback.error)justifyr   c             3   s   | ]}  |V  qd S )N)r   )r   r   )frame_filenamer2   rJ   	<genexpr>  s    z*Traceback._render_stack.<locals>.<genexpr>zpygments.string)r   )r   zpygments.textzpygments.numberz in zpygments.functionzpygments.textzin r   ro   X   )r6   line_numbers
line_rangehighlight_linesr7   
code_widthr=   dedentr   r   )r   )r   r6   ru   rk   r   r"   r?   rX   r   r   	enumerater   r   rl   anyr>   r   r   r   r   rm   rn   r   r   r+   r5   r7   r=   rh   rq   r   )r   r   r   r6   r   r   exclude_framesexcludedframe_indexr   first
suppressedr   r   
lexer_namesyntaxerrorr2   )r   r   rJ   r   \  s    






$zTraceback._render_stack)N)!rr   rs   rt   __doc__r   LOCALS_MAX_LENGTHLOCALS_MAX_STRINGr   r   rw   ru   rH   r   r   r   r   classmethodr   r   re   r   rG   r   r    r!   r#   r   r$   ry   r   r   r|   r   r2   r2   r2   rJ   rF      s`   D$@3rLrF   __main__)r    )ar@   c             C   s   d}t ||   d S )Nr   )rE   )r  oner2   r2   rJ   bar  s    r  c             C   s"   d}ddddhdd}t |  d S )NTzPaul AtreideszVladimir HarkonnenzThufir HawatzDuncan Idaho)NFT)
charactersZatomic_types)r  )r  r   Zzedr2   r2   rJ   foo  s    r  )r@   c               C   s@   y"yt d W n   t Y nX W n   tjdd Y nX d S )Nr   T)r8   )r  Zslfkjsldkfjr3   print_exceptionr2   r2   r2   rJ   r    s    r  )V
__future__r   r   r   platformrg   dataclassesr   r   rD   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   ro   r   _loopr   columnsr   r3   r    r!   r"   r#   r$   	constrainr%   r   r&   r'   panelr(   scoper)   r   r*   r  r+   r   r6   r,   systemWINDOWSr  r  rw   ru   rH   re   rj   rk   ry   r|   r   r   rF   rr   r  r  r  r2   r2   r2   rJ   <module>   sx   0 <$p			    

