o
    
i                     @   sh   d dl Z d dlmZmZmZ ddlmZmZmZ esdndZ	es"dndZ
es(d	nd
ZG dd deZdS )    N)OptionalTupleUnion   )NO_UTF8colorsupports_ansiu   └─z|_u   ├─z|__u   ──__c                   @   s   e Zd Zddddde ddfdeeef d	eeef d
eeef dedee dededefddZ	dedefddZ
dd Zdd Zdd ZdS )TracebackPrinterredblueyellow   Ncolor_errorcolor_tbcolor_highlightindenttb_base
tb_excludetb_range_starttb_range_endc	           	      C   st   || _ || _|| _d| | _|dkrdt tjj}n	|dur&d|}|| _	t
|| _|| _|| _t | _dS )a  Initialize a traceback printer.

        color_error (Union[str, int]): Color name or code for errors.
        color_tb (Union[str, int]): Color name or code for traceback headline.
        color_highlight (Union[str, int]): Color name or code for highlights.
        indent (int): Indentation in spaces.
        tb_base (Optional[str]): Optional name of directory to use to show relative paths. For
            example, "thinc" will look for the last occurence of "/thinc/" in
            a path and only show path to the right of it.
        tb_exclude (tuple): List of filenames to exclude from traceback.
        tb_range_start (int): The starting index from a traceback to include.
        tb_range_end (int): The final index from a traceback to include. If None
            the traceback will continue until the last record.
        RETURNS (TracebackPrinter): The traceback printer.
         .z{}{}Nz/{}/)r   r   r   r   formatosgetcwdpathsepr   tupler   r   r   r   )	selfr   r   r   r   r   r   r   r    r"   L/home/ubuntu/.local/lib/python3.10/site-packages/wasabi/traceback_printer.py__init__   s   


zTracebackPrinter.__init__titlereturnc                    s|   | dd}| dd} jrt| jdd}|r'dd fdd	|D  nd
}|r1 ||nd
}d j|||}|S )a  Output custom formatted tracebacks and errors.

        title (str): The message title.
        *texts (str): The texts to print (one per line).
        RETURNS (str): The formatted traceback. Can be printed or raised
            by custom exception.
        	highlightFtbNTfgbold
c                    s   g | ]} j | qS r"   )r   ).0textr!   r"   r#   
<listcomp>@   s    z-TracebackPrinter.__call__.<locals>.<listcomp> z

{}{}{}{}
)getr   r   r   join_get_tracebackr   r   )r!   r%   textssettingsr'   r(   infomsgr"   r/   r#   __call__4   s   $zTracebackPrinter.__call__c                    s   fdd|D }j d ur|jj  n|jd   fddtD }d| }d}jr>t|jdd}dj||j	d	S )
Nc                    s    g | ]}|d    js|qS )r   )endswithr   )r-   recordr/   r"   r#   r0   G   s     z3TracebackPrinter._get_traceback.<locals>.<listcomp>c                    s2   g | ]\}\}}}} |||||t qS r"   )_format_tracebacklen)r-   ir   linefnr.   r'   r!   tb_ranger"   r#   r0   M   s    r,   z
Traceback:Tr)   z

{indent}{title}
{indent}{tb})r%   r(   r   )
r   r   	enumerater3   stripr   r   r   r   r   )r!   r(   r'   tb_listtb_datar%   r"   rA   r#   r4   E   s   
zTracebackPrinter._get_tracebackc           
      C   s   d}||d kr
t ntt|  }	| jr!| j|v r!|| jdd }||d kr.| |||nd}| jr?t|dd}t|dd}|j| j	||	|||dS )Nz1{base_indent}{indent} {fn} in {path}:{line}{text}r   r1   T)r+   )	underline)base_indentr?   r   r.   r@   r   )
	LINE_EDGE	LINE_FORK	LINE_PATHr   rsplit_format_user_errorr   r   r   r   )
r!   r   r?   r@   r.   r>   countr'   templater   r"   r"   r#   r<   Y   s    z"TracebackPrinter._format_tracebackc                 C   sT   d| d }| j rt|| jd}|r"| j r"t|| jd}|||}d| j||S )Nz  z >>>)r*   z

{}  {} {})r   r   r   r   replacer   r   )r!   r.   r>   r'   spacingformatted_highlightr"   r"   r#   rM   k   s   
z#TracebackPrinter._format_user_error)__name__
__module____qualname__r    r   strintr   r   r$   r9   r4   r<   rM   r"   r"   r"   r#   r
      s<    


	
(r
   )r   typingr   r   r   utilr   r   r   rI   rJ   rK   objectr
   r"   r"   r"   r#   <module>   s    