a
    ibòfOe  ã                   @   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œ	ee+ eeD eDeeE eFeFeFeeeEef  eDeeeG eGee gef d œ
d!d"„ZHeG d#d$„ d$ƒƒZIeG d%d&„ d&ƒƒZJeG d'd(„ d(ƒƒZKeG d)d*„ d*ƒƒZLG d+d,„ d,e3ƒZMG d-d.„ d.ƒZNeOd/k�rždd0l*m+Z+ e+ƒ Z*d dlZedd1œd2d3„ZPedd1œd4d5„ZQdd6œd7d8„ZReRƒ  dS )9é    )Ú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_frames)
r2   r3   r4   r5   r6   r7   r8   r9   r:   Úreturnc        	      
      sš   | du rt tj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 )	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   úW/home/httpd/docs/test/DocsMgr/lib/python3.9/site-packages/pip/_vendor/rich/traceback.pyÚ
excepthookE   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   |‰ˆ | 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_syntax)rG   rM   rH   r;   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é   Úrunning_compiled_codeFÚ	tb_offsetr   r   )Ú_get_exc_infoÚgetÚrangeÚtb_next)rM   rG   rH   Ú	exc_tupleÚtbÚcompiledrP   Ú_)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   )rY   r1   rD   Ú<lambda>   s   ÿÿÿz9install.<locals>.ipy_excepthook_closure.<locals>.<lambda>)Úshowtracebackr   ÚboolÚ_showtracebackÚshowsyntaxerror)rF   rL   )rE   )rJ   rF   rY   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:   r_   rF   Úold_excepthookr1   )
rE   r4   r8   r:   r7   r9   r5   rC   r3   r6   rD   Úinstall#   s     ü )rf   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__Úintrl   rm   r   r
   r   ÚNoder1   r1   r1   rD   rg   �   s
   
rg   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Úoffsetrh   rl   ri   ÚmsgN)rn   ro   rp   rs   rr   rq   r1   r1   r1   rD   ru   ˜   s
   
ru   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)rn   ro   rp   rq   rr   r{   r   ru   r|   r\   r   Úlistr~   r   rg   r1   r1   r1   rD   rx   ¡   s
   
rx   c                   @   s   e Zd ZU ee ed< dS )ÚTraceÚstacksN)rn   ro   rp   r   rx   rr   r1   r1   r1   rD   r€   ª   s   
r€   c                   @   s   e Zd ZdgZdS )ÚPathHighlighterz(?P<dim>.*/)(?P<bold>.+)N)rn   ro   rp   Ú
highlightsr1   r1   r1   rD   r‚   ¯   s   r‚   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ÚpythonÚcythonÚpyrex)rk   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 rHt  ¡ \}}}|d u s.|d u s.|d u r6tdƒ‚| j||||d�}|| _|| _|| _t |pdd¡| _	|| _
|| _|| _|| _|	| _g | _|
D ]Z}t|tƒsÈ|jd us¸J |›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©r7   Ú	ansi_darkz+ must be a module with '__file__' attributer   é   )r`   Úexc_infoÚ
ValueErrorÚextractrˆ   r3   r4   r*   Ú	get_themer5   r6   r7   r8   r‰   rŠ   r9   Ú
isinstancerq   Ú__file__ÚosÚpathÚdirnameÚnormpathÚabspathÚappendÚmaxr:   )Úselfrˆ   r3   r4   r5   r6   r7   r8   r‰   rŠ   r9   r:   ry   rz   r?   Úsuppress_entityr•   r1   r1   rD   Ú__init__Ï   s<    ÿÿ
ÿþzTraceback.__init__)ry   rz   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.
        r‹   )
r3   r4   r5   r6   r7   r8   r‰   rŠ   r9   r:   )r�   )Úclsry   rz   r?   r3   r4   r5   r6   r7   r8   r‰   rŠ   r9   r:   Úrich_tracebackr1   r1   rD   rB   ý   s     &ÿõzTraceback.from_exception)ry   rz   r?   r7   r‰   rŠ   r;   c                    s¤  g }d}ddl m}	 ttdœdd„}
t|
|jƒ|
|ƒ|d�}t|tƒrtt|j	pPd|j
pXd|jp`d|jphd	|jd
�|_| |¡ |jj}t|ƒD ]Œ\}}|jj}|rÆ| d¡sÆtj |¡sÆtj |	|¡}t|pÎd||jj|rô‡ ‡fdd„|j ¡ D ƒndd�}||ƒ d|jv rŽ|jdd…= qŽt|ddƒ}|�rR|j�rR|j}|}|j}|�rRd}q$|j }|�r–|j�r–t|ddƒ�s–|j}|}|j}|�r–d}q$�q–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 0 dS )z1Don't allow exceptions from __str__ to propegate.z<exception str() failed>N)rq   rd   )r¡   r1   r1   rD   Úsafe_strR  s    
z#Traceback.extract.<locals>.safe_str)ry   rz   r|   ú?rk   )rv   rh   ri   rl   rw   ú<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)rh   ri   rj   rm   Ú_rich_traceback_guardÚ	__cause__TÚ__suppress_context__)r�   )"Úpip._vendor.richr    r   rq   rx   rn   r’   ÚSyntaxErrorru   rv   rh   ri   r„   rw   r{   r™   r~   r   Úf_codeÚco_filenameÚ
startswithr”   r•   ÚisabsÚjoinrg   Úco_nameÚf_localsÚitemsÚgetattrÚ__traceback__Ú	__class__Ú__context__r€   )rž   ry   rz   r?   r7   r‰   rŠ   r�   r|   r    r¢   Ústackr™   Úframe_summaryÚline_norh   ÚframeÚcauserˆ   r1   rª   rD   r�   4  sz    ý
û
	øú	ó
ÿþ
ý
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ƒ }tt| jjƒƒD �]P\}}	|	j�r,t|  |	¡d|ddd	d
�}
t|
| jƒ}
| |¡� |
V  W d   ƒ n1 �s"0    Y  |	jd u�r°| |¡�8 tt|  |	j¡|ddd	| jd�| jƒV  W d   ƒ n1 �s‚0    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  qÂt #d¡V  qÂd S )NT)Údim)Ú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)Ú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   Úget_background_styleÚget_style_for_tokenr+   Ú	TextTokenr   r   r   ÚFunctionr   r   r)   r   ÚConstantÚ	Delimiterr   r&   r   Úreversedrˆ   r�   r~   r'   Ú_render_stackr$   r3   Ú	use_themer{   Ú_render_syntax_errorr   Úassemblery   rw   rz   r|   Úfrom_markup)r›   r2   rÂ   r5   Úbackground_styleÚtoken_styleÚtraceback_themeÚhighlighterÚlastr½   Ústack_renderabler1   r1   rD   Ú__rich_console__Ÿ  sˆ    ðíú&
ú÷&
þþÿÿzTraceback.__rich_console__)r{   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>ú rÆ   ©ú:rÅ   rÈ   rÅ   ©rË   Tr   zbold underlineÚ
u   [traceback.offset]â–²[/])r&   r‚   rh   r   rÙ   rq   ri   rl   ÚrstripÚno_wrapÚminrv   ÚlenÚstylizerÚ   )r›   r{   rÞ   Úpath_highlighterr„   Úsyntax_error_textrv   r1   r1   rD   rØ   í  s&    
ü
þzTraceback._render_syntax_error)rh   Úcoder;   c                 C   sl   t j |¡d }|sP| d¡}|dkr2|d |… n|}| d¡rPd| ¡ v rPdS | j |¡pft||ƒj	}|S )Néÿÿÿÿræ   z#!r…   )
r”   r•   ÚsplitextÚindexr³   ÚlowerÚLEXERSrR   r   rj   )rž   rh   rî   ÚextÚnew_line_indexÚ
first_lineÚ
lexer_namer1   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	}t
|j	ƒD �]¢\}}	|r”||v r”d
}qx|rÄ|d us¤J ‚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¡�s8|
�s8dV  |V  |	j d¡�r\||	ƒE d H  qx|sxzZ||	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 }~qxd }~0 0 |	j�rt|g||	ƒ¢dd�n|V  qxd S ) N)rh   r;   c                    sV   ˆ   | ¡}|du rRt| dddd��}| ¡ }W d  ƒ n1 s@0    Y  |ˆ | < |S )z·Read files, and cache results on filename.

            Args:
                filename (str): Filename to read

            Returns:
                str: Contents of file
            NÚrtzutf-8Úreplace)ÚencodingÚerrors)rR   ÚopenÚread)rh   rî   Ú	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 )Nrm   )rÊ   r8   r¥   r¦   )rm   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  ó    z*Traceback._render_stack.<locals>.<genexpr>rÆ   rå   rã   rÈ   z in rÇ   rÅ   r¤   rk   éX   )r5   Úline_numbersÚ
line_rangeÚhighlight_linesr6   Ú
code_widthr8   Údedentræ   )rÎ   )r‚   r5   rq   rg   r   r!   r:   rS   rê   r~   Ú	enumerater   rh   Úanyr9   rÙ   ri   rj   r³   rø   r*   r4   r6   r8   rd   rm   r   )r›   r½   rì   r5   r  r  Úexclude_framesÚexcludedÚframe_indexrÀ   ÚfirstÚ
suppressedr„   rî   r÷   ÚsyntaxÚerrorr1   )r   r  r›   rD   rÖ     s”    

þýú


þó
ÿùÿþû÷zTraceback._render_stack)!rn   ro   rp   Ú__doc__ró   ÚLOCALS_MAX_LENGTHÚLOCALS_MAX_STRINGr   r€   rs   rq   r\   r   r   r   r�   Úclassmethodr   r   rb   r   rB   r�   r   r    r"   rá   r#   ru   rØ   rø   rx   rÖ   r1   r1   r1   rD   rA   ³   s    û
ôô.òñ6ùøkþNrA   Ú__main__)r   )Úar;   c                 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>   zVladimir HarkonnenzPaul AtreideszDuncan IdahozThufir Hawat)NFT)Ú
charactersZatomic_types)r  )r  r¬   Zzedr1   r1   rD   Úfoo�  s
    ù	r   )r;   c                   C   s@   z"zt dƒ W n   t Y n0 W n   tjdd� Y n0 d S )Nr   Tr‹   )r   Zslfkjsldkfjr2   Úprint_exceptionr1   r1   r1   rD   r  œ  s    r  )SÚ
__future__r   r”   Úplatformr`   Údataclassesr   r   r?   r   Útypesr   r   Útypingr   r	   r
   r   r   r   r   r   r   Úpip._vendor.pygments.lexersr   Úpip._vendor.pygments.tokenr   r   r   r   r   r   r   rÑ   r   rk   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  rs   rq   r\   rb   rf   rg   ru   rx   r€   r‚   rA   rn   r  r   r  r1   r1   r1   rD   Ú<module>   sˆ   , öõl   T

