o
    MfOe                     @   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	d ee+ d!eeD d"eDd#eeE d$eFd%eFd&eFd'eeeEef  d(eDd)eeeG eGee gef fd*d+ZHeG d,d- d-ZIeG d.d/ d/ZJeG d0d1 d1ZKeG d2d3 d3ZLG d4d5 d5e3ZMG d6d7 d7ZNeOd8krZdd9l*m+Z+ e+ Z*d dlZd:ed)dfd;d<ZPd:ed)dfd=d>ZQdAd?d@ZReR  dS dS )B    )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_framesr2   r3   r4   r5   r6   r7   r8   r9   r:   returnc        	      
      s   | du r
t tjdn| dtt dtdtt ddf	f	dd d	tddf fd
d}	zt }
|	|
 tj	W S  t
yN   tj	} t_	| Y S w )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   \/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/pip/_vendor/rich/traceback.py
excepthookE   s   zinstall.<locals>.excepthookipc              	      sl   i j  dtdtdd f fdd}dddtdtdtdd f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_syntaxrM   c                    st     }| rdn|d }dd}d|rdnd}t|D ]}|du r( n|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                   @   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fdee dee	 de	dee
 dededede	de	deee
ef  de	fddZedd	dd
d
deeddf
dee dedee dee	 de	dee
 dededede	de	deee
ef  de	dd fddZed
eefdee dedee dede	de	defd d!Zd"ed#edefd$d%Ze d&edefd'd(Zed)e
d*e
de
fd+d,Ze d-edefd.d/Z dS )0rA   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 r$t  \}}}|d u s|d u s|d u rtd| j||||d}|| _|| _|| _t|p2d| _	|| _
|| _|| _|| _|	| _g | _|
D ]-}t|tsd|jd us\J |dtj|j}n|}tjtj|}| j| qI|dkrtd|| _d S 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?   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_exceptionc                    s  g }d}ddl m}	 dtdtfdd}
	 t|
|j|
||d	}t|tr<t|j	p*d|j
p.d
|jp2d|jp6d|jd|_|| |jj}t|D ]F\}}|jj}|re|dsetj|setj|	|}t|pid
||jj|r| fdd|j D ndd}|| d|jv r|jdd= qIt|dd}|r|jr|j}|}|j}|rd}q|j }|r|jrt|dds|j}|}|j}|rd}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 w )z1Don't allow exceptions from __str__ to propegate.z<exception str() failed>)rq   rd   )r   r1   r1   rD   safe_strR  s
   
z#Traceback.extract.<locals>.safe_strT)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____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  s~   

		



zTraceback.extractr2   optionsc                 c   sR   | j }| }|j}ti d|td|td|td|tjd|t	d|t
tdd d	|td
|ttdd d|t	d|tjd|tjd|tjd|tjd|td|td|tjtdd dd}t }tt| jjD ]\}}	|	jrt| |	d|dddd}
t|
| j}
|| |
V  W d    n1 sw   Y  |	jd ur|| tt| |	j|ddd| jd| jV  W d    n1 sw   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  qt#dV  qd S ) Nr   pygments.textpygments.stringpygments.functionpygments.numberzrepr.indentT)dimzrepr.strz
repr.brace)boldz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{   c                 c   s    t  }t }|jdkr%t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_errorrh   codec                 C   sl   t j|d }|s(|d}|dkr|d | n|}|dr(d| v r(dS | j|p3t||j	}|S )Nr   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_lexerr   c                 #   s    t  }j}i  dtdtf fdd}dtdtt ffdd}d }jdkr8tjd	 t|j	jd	  }d
}t
|j	D ]\}}	|rL||v rLd}q?|rd|d usTJ 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|
sdV  |V  |	jdr||	E d H  q?|sz-||	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 }~q?d }~ww |	jr
t|g||	dd n|V  q?d S )!Nrh   r;   c                    sV     | }|du r)t| dddd}| }W d   n1 s w   Y  | | < |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)rR   openread)rh   r   	code_file)
code_cacher1   rD   	read_code  s   
	
z*Traceback._render_stack.<locals>.read_coder   c                 3   s,    | j rt| j d j j jdV  d S 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  s    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j
NrA   __main__)r   ac                 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>   Duncan IdahoThufir HawatPaul AtreidesVladimir Harkonnen)NFT)
charactersatomic_types)r  )r  r   zedr1   r1   rD   foo  s
   	r%  c                   C   s>   zzt d W W d S    t Y W d S    tjdd Y d S )Nr   Tr   )r%  slfkjsldkfjr2   print_exceptionr1   r1   r1   rD   r    s   r  )r;   N)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


