B
    ufe                 @   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& ddl'm(Z( ddl)m*Z* ddl+m,Z,m-Z-m.Z.m/Z/m0Z0 ddl1m2Z2 ddl3m4Z4m5Z5 ddl6m7Z7 ddl8m9Z9 ddl:m;Z; ddl<m=Z= dd	l>m Z  ddl?m@Z@ eA dkZBdZCdZDdddddddddd 	ee, eeE eEeeF eGeGeGeeeFef  eEeeeH eHee gef d!
d"d#ZIeG d$d% d%ZJeG d&d' d'ZKeG d(d) d)ZLeG d*d+ d+ZMG d,d- d-e4ZNG d.d/ d/ZOePd0krdd1l+m,Z, e, Z+d dlZedd2d3d4ZQedd2d5d6ZRdd7d8d9ZSeS  dS ):    )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)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indent_guidessuppress
max_frames)
r2   r3   r4   r5   r6   r7   r8   r9   r:   returnc    	      
      s   | dkrt tj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 )	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   \/home/ankuromar296_gmail_com/myenv/lib/python3.7/site-packages/pip/_vendor/rich/traceback.py
excepthookF   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._showtracebackNr1   )rG   rH   )default_showtracebacktb_datar1   rD   ipy_show_traceback_   s    zCinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_show_tracebackF)	is_syntax)rG   rL   rH   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   Zrunning_compiled_codeF	tb_offsetr   r   )Z_get_exc_infogetrangetb_next)rL   rG   rH   Z	exc_tupletbZcompiledrN   _)rE   rF   rJ   r1   rD   ipy_display_tracebacke   s    
zFinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_display_tracebackc                 s    | ddi|S )NrL   Tr1   )rG   rH   )rT   r1   rD   <lambda>   s   z9install.<locals>.ipy_excepthook_closure.<locals>.<lambda>)Zshowtracebackr   boolZ_showtracebackZshowsyntaxerror)rF   rK   )rE   )rI   rF   rT   rJ   rD   ipy_excepthook_closure[   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:   rW   rF   Z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__intrc   rd   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offsetr_   rc   r`   msgN)re   rf   rg   rj   ri   rh   r1   r1   r1   rD   rl      s
   
rl   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)re   rf   rg   rh   ri   rr   r   rl   rs   rV   r   listru   r   r^   r1   r1   r1   rD   ro      s
   
ro   c               @   s   e Zd ZU ee ed< dS )TracestacksN)re   rf   rg   r   ro   ri   r1   r1   r1   rD   rw      s   
rw   c               @   s   e Zd ZdgZdS )PathHighlighterz(?P<dim>.*/)(?P<bold>.+)N)re   rf   rg   
highlightsr1   r1   r1   rD   ry      s   ry   c               @   sR  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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f
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f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 )"rA   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)rb   z.pyz.pxdz.pyxz.pxiNr/   r0   FTr1   )tracer3   r4   r5   r6   r7   r8   locals_max_lengthlocals_max_stringr9   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)r7   Z	ansi_darkz+ must be a module with '__file__' attributer      )rX   exc_info
ValueErrorextractr}   r3   r4   r*   Z	get_themer5   r6   r7   r8   r~   r   r9   
isinstancerh   __file__AssertionErrorospathdirnamenormpathabspathappendmaxr:   )selfr}   r3   r4   r5   r6   r7   r8   r~   r   r9   r:   rp   rq   r?   Zsuppress_entityr   r1   r1   rD   __init__   s4    

zTraceback.__init__)rp   rq   r?   r3   r4   r5   r6   r7   r8   r~   r   r9   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.
        )r7   )
r3   r4   r5   r6   r7   r8   r~   r   r9   r:   )r   )clsrp   rq   r?   r3   r4   r5   r6   r7   r8   r~   r   r9   r:   Zrich_tracebackr1   r1   rD   rB      s    &zTraceback.from_exception)rp   rq   r?   r7   r~   r   r;   c                s  g }d}ddl m}	 ttddd}
xpt|
|j|
||d}t|trxt|j	pTd|j
p\d|jpdd|jpld	|jd
|_|| |jj}xt|D ]\}}|jj}|r|dstj|stj|	|}|jddrqt|pd||jj|r fdd|j D ndd}|| |jddr|jdd= qW t|dd}|rb|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.

        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)rh   r\   )r   r1   r1   rD   safe_strS  s    z#Traceback.extract.<locals>.safe_str)rp   rq   rs   ?rb   )rm   r_   r`   rc   rn   <Z_rich_traceback_omitc                s"   i | ]\}}t j| d |qS ))
max_length
max_string)r   traverse).0keyr>   )r~   r   r1   rD   
<dictcomp>x  s   z%Traceback.extract.<locals>.<dictcomp>N)r_   r`   ra   rd   _rich_traceback_guard	__cause__T__suppress_context__)rx   )#pip._vendor.richr   r   rh   ro   re   r   SyntaxErrorrl   rm   r_   r`   r{   rn   rr   r   ru   r   f_codeco_filename
startswithr   r   isabsjoinf_localsrO   r^   co_nameitemsgetattr	__class____traceback____context__rw   )r   rp   rq   r?   r7   r~   r   rx   rs   r   r   stackr   frame_summaryline_nor_   framecauser}   r1   )r~   r   rD   r   5  sf    

	 
zTraceback.extract)r2   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   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}   rx   ru   r'   _render_stackr$   r3   	use_themerr   _render_syntax_errorr   assemblerp   rn   rq   rs   from_markup)r   r2   r   r5   background_styleZtoken_styleZtraceback_themehighlighterlastr   Zstack_renderabler1   r1   rD   __rich_console__  sv    

zTraceback.__rich_console__)rr   r;   c             c   s   t  }t }|jdkrHt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&   ry   r_   r   r   rh   r`   rc   rstripno_wrapminrm   lenstylizer   )r   rr   r   path_highlighterr{   Zsyntax_error_textrm   r1   r1   rD   r     s"    


zTraceback._render_syntax_error)r_   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LEXERSrO   r   ra   r   )r   r_   r   extZnew_line_index
first_liner1   r1   rD   _guess_lexer  s    
zTraceback._guess_lexer)r   r;   c             #   s&  t  }j}i  ttd fdd}ttt dfdd}d }jdkrjtjd t|j	jd  }d	}xt
|j	D ]\}}	|r||krd
}q||r|d k	st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<|
s<dV  |V  |	jdr`||	E d H  q||s|yZ||	j}|	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 q|X |	jrt|f||	ddn|V  q|W d S ) N)r_   r;   c          	      sB     | }|dkr>t| dddd}| }W dQ R X | | < |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)rO   openread)r_   r   Z	code_file)
code_cacher1   rD   	read_code  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 )Nrd   )r   r8   r   r   )rd   r(   r8   r~   r   )r   )r   r1   rD   render_locals*  s    z.Traceback._render_stack.<locals>.render_localsr   rM   FTz
... z frames hidden ...centerztraceback.error)justifyr   c             3   s   | ]}  |V  qd S )N)r   )r   r   )frame_filenamer1   rD   	<genexpr>M  s    z*Traceback._render_stack.<locals>.<genexpr>zpygments.string)r   )r   zpygments.textzpygments.numberz in zpygments.functionzpygments.textr   rb   X   )r5   Zline_numbersZ
line_rangeZhighlight_linesr6   Z
code_widthr8   dedentr   r   )r   )ry   r5   rh   r^   r   r!   r:   rP   r   ru   	enumerater   r   r_   anyr9   r   r`   ra   r   r   r*   r4   r6   r8   r\   rd   r   )r   r   r   r5   r   r   Zexclude_framesZexcludedZframe_indexr   firstZ
suppressedr{   r   Z
lexer_namesyntaxerrorr1   )r   r   r   rD   r     sx    





$zTraceback._render_stack)!re   rf   rg   __doc__r   LOCALS_MAX_LENGTHLOCALS_MAX_STRINGr   rw   rj   rh   rV   r   r   r   r   classmethodr   r   rZ   r   rB   r   r   r    r"   r   r#   rl   r   r   ro   r   r1   r1   r1   rD   rA      sT   >":'aLrA   __main__)r   )ar;   c             C   s   d}t ||   d S )Nr   )r@   )r   oner1   r1   rD   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zedr1   r1   rD   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)r7   )r   Zslfkjsldkfjr2   print_exceptionr1   r1   r1   rD   r     s    r   )T
__future__r   r   platformrX   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   Zpip._vendor.pygments.utilr   rb   r   _loopr   columnsr   r2   r   r    r!   r"   r#   	constrainr$   r   r%   r&   panelr'   scoper(   r   r)   r   r*   r{   r5   r+   systemWINDOWSr   r   rj   rh   rV   rZ   r]   r^   rl   ro   rw   ry   rA   re   r   r   r   r1   r1   r1   rD   <module>   sl   , 0$a			   R

