a
    �˜ëjŸ’  ã                   @   s  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
 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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+m,Z, ddl-m.Z. ddl/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6 ddl7m8Z8 ddl9m:Z:m;Z; ddl<m=Z= ddl>m?Z? ddl@mAZA ddlBmCZCmDZD dd	lEm#Z# ddlFmGZG ejHdkZIdZJdZKeDeDeeeLeLeLf  dœdd„ZMdddd dd!d!eJeKdd"ddd"d#dd$œee0 eeL eeL eLeeN eOeOeLeLeeL eOeeO ee3 eOeeeNef  eLeeeP ePee gef d%œd&d'„ZQeG d(d)„ d)ƒƒZReG d*d+„ d+ƒƒZSeG d,d-„ d-ƒƒZTeG d.d/„ d/ƒƒZUG d0d1„ d1e:ƒZVG d2d3„ d3ƒZWeXd4k�reQd"d5� d dlZedd6œd7d8„ZYedd6œd9d:„ZZdd;œd<d=„Z[e[ƒ  dS )>é    N)Ú	dataclassÚfield)Úislice)Úwalk_tb)Ú
ModuleTypeÚTracebackType)ÚAnyÚCallableÚDictÚIterableÚListÚOptionalÚSequenceÚSetÚTupleÚTypeÚUnion)Úguess_lexer_for_filename)ÚCommentÚKeywordÚNameÚNumberÚOperatorÚString)ÚText)ÚToken)ÚClassNotFoundé   )Úpretty)Úloop_first_lastÚ	loop_last)ÚColumns)ÚConsoleÚConsoleOptionsÚConsoleRenderableÚOverflowMethodÚGroupÚRenderResultÚgroup)Ú	Constrain)ÚRegexHighlighterÚReprHighlighter)ÚPanel)Úrender_scope)ÚStyle)ÚSyntaxÚSyntaxPosition)ÚThemeÚwin32é
   éP   )ÚstartÚendÚreturnc           	      c   sx   | \}}|\}}||kr&|||fV  nNt t||d ƒƒD ]:\}}}|rT||dfV  q8|rf|d|fV  q8|ddfV  q8dS )z­Yield start and end positions per line.

    Args:
        start: Start position.
        end: End position.

    Returns:
        Iterable of (LINE, COLUMN1, COLUMN2).
    r   éÿÿÿÿr   N)r   Úrange)	r5   r6   Úline1Úcolumn1Zline2Úcolumn2ÚfirstÚlastÚline_no© r@   úM/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/rich/traceback.pyÚ_iter_syntax_lines8   s    rB   éd   éX   é   FTr@   )ÚconsoleÚwidthÚ
code_widthÚextra_linesÚthemeÚ	word_wrapÚshow_localsÚlocals_max_lengthÚlocals_max_stringÚlocals_max_depthÚlocals_hide_dunderÚlocals_hide_sunderÚlocals_overflowÚindent_guidesÚsuppressÚ
max_frames)rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   r7   c                    s¼   | du rt dd�n| ‰ˆjr(ˆdu r(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 )
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.
        code_width (Optional[int], optional): Code width (in characters) of traceback. Defaults to 88.
        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_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
        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.
        locals_overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.
        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Ú	tracebackr7   c                    s@   t j| ||ˆˆ ˆˆˆˆ
ˆˆˆˆtˆƒˆˆˆˆ	d�}ˆ |¡ d S )N©rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   )Ú	TracebackÚfrom_exceptionÚboolÚprint)rW   rX   rY   Zexception_traceback)rH   rI   rS   rP   rQ   rO   rM   rN   rR   rU   rL   rT   rJ   Útraceback_consolerG   rK   r@   rA   Ú
excepthook‹   s*    îzinstall.<locals>.excepthook)Úipr7   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Úkwargsr7   c                     s   |‰ˆ | i |¤Ž dS )zEwrap the default ip.showtraceback to store info for ip._showtracebackNr@   ©rb   rc   )Údefault_showtracebackÚtb_datar@   rA   Úipy_show_tracebackª   s    zCinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_show_tracebackF)Ú	is_syntax)rb   rh   rc   r7   c                    s~   ˆ  ¡ }| rdn|d }ˆ dd¡}ˆ d¡}|du rB|r>dnd}t|ƒD ]}|du rZ qb|j}qJˆ |d |d |ƒ i ‰dS )z2Internally called traceback from ip._showtracebackNé   Zrunning_compiled_codeFÚ	tb_offsetr   r   )Z_get_exc_infoÚgetr9   Útb_next)rh   rb   rc   Z	exc_tupleÚtbZcompiledrj   Ú_)r`   ra   rf   r@   rA   Úipy_display_traceback°   s    
zFinstall.<locals>.ipy_excepthook_closure.<locals>.ipy_display_tracebackc                     s   ˆ | ddi|¤ŽS )Nrh   Tr@   rd   )ro   r@   rA   Ú<lambda>Í   s   ÿÿÿz9install.<locals>.ipy_excepthook_closure.<locals>.<lambda>)Zshowtracebackr   r]   Z_showtracebackZshowsyntaxerror)ra   rg   )r`   )re   ra   ro   rf   rA   Úipy_excepthook_closure¦   s    ÿþz'install.<locals>.ipy_excepthook_closure)r"   Z
is_jupyterr   ÚBaseExceptionr   r   r   Zget_ipythonÚsysr`   Ú	Exception)rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rq   ra   Úold_excepthookr@   )rH   r`   rI   rS   rP   rQ   rO   rM   rN   rR   rU   rL   rT   rJ   r_   rG   rK   rA   ÚinstallT   s*    /ÿÿýü.+rv   c                   @   st   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Zeeeeef eeef f  ed< dS )	ÚFrameÚfilenameÚlinenoÚnameÚ ÚlineNÚlocalsÚlast_instruction)Ú__name__Ú
__module__Ú__qualname__ÚstrÚ__annotations__Úintr|   r}   r   r
   r   ÚNoder~   r   r@   r@   r@   rA   rw   Ý   s   
rw   c                   @   sL   e Zd ZU eed< eed< eed< eed< eed< eed�Ze	e ed< dS )	Ú_SyntaxErrorÚoffsetrx   r|   ry   Úmsg©Údefault_factoryÚnotesN)
r   r€   r�   r„   rƒ   r‚   r   Úlistr‹   r   r@   r@   r@   rA   r†   ç   s   
r†   c                   @   sˆ   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< e
ed�Zee ed	< dZe	ed
< e
ed�Zed ed< dS )ÚStackÚexc_typeÚ	exc_valueNÚsyntax_errorFÚis_causer‰   Úframesr‹   Úis_groupÚTraceÚ
exceptions)r   r€   r�   r‚   rƒ   r�   r   r†   r‘   r]   r   rŒ   r’   r   rw   r‹   r“   r•   r@   r@   r@   rA   r�   ñ   s   
r�   c                   @   s   e Zd ZU ee ed< dS )r”   ÚstacksN)r   r€   r�   r   r�   rƒ   r@   r@   r@   rA   r”   ý   s   
r”   c                   @   s   e Zd ZdgZdS )ÚPathHighlighterz(?P<dim>.*/)(?P<bold>.+)N)r   r€   r�   Z
highlightsr@   r@   r@   rA   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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ee
ef  e	dœdd„Zedd	d
dddeedd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e eeee
ef  e	d dœdd„ƒZedeedddddœee eee 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 )'r[   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.
        code_width (Optional[int], optional): Number of code characters used to traceback. Defaults to 88.
        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_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
        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.
        locals_overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.
        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)r{   z.pyz.pxdz.pyxz.pxiNrC   rD   rE   FTr@   )rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   Úlocals_overlowrS   rT   rU   )ÚtracerG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rš   rS   rT   rU   c                C   s*  |d u rHt  ¡ \}}}|d u s.|d u s.|d u r6tdƒ‚| j||||d�}|| _|| _|| _|| _t 	|pjd¡| _
|| _|| _|| _|| _|	| _|
| _|| _|| _|| _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©rL   Z	ansi_darkz+ must be a module with '__file__' attributer   é   ) rs   Úexc_infoÚ
ValueErrorÚextractr›   rG   rH   rI   r/   Z	get_themerJ   rK   rL   rS   rM   rN   rO   rP   rQ   rR   rT   Ú
isinstancer‚   Ú__file__ÚosÚpathÚdirnameÚnormpathÚabspathÚappendÚmaxrU   )Úselfr›   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rš   rS   rT   rU   rŽ   r�   rY   Zsuppress_entityr¤   r@   r@   rA   Ú__init__'  sF    ÿÿ
ÿþzTraceback.__init__rZ   )rŽ   r�   rY   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   r7   c                C   sD   | 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.
            code_width (Optional[int], optional): Number of code characters used to traceback. Defaults to 88.
            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_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
            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.
            locals_overflow (OverflowMethod, optional): How to handle overflowing locals, or None to disable. Defaults to None.
            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.
        )rL   rM   rN   rO   rP   rQ   )rG   rH   rI   rJ   rK   rL   rS   rM   rN   rO   rP   rQ   rš   rT   rU   )r    )ÚclsrŽ   r�   rY   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   rQ   rR   rS   rT   rU   Zrich_tracebackr@   r@   rA   r\   `  s:    1÷ðzTraceback.from_exception)rL   rM   rN   rO   rP   rQ   Ú_visited_exceptions)rŽ   r�   rY   rL   rM   rN   rO   rP   rQ   r­   r7   c          "         s  g }d}ddl m} t|ddƒp"g }|
du r2tƒ n|
}ttdœdd„}t||jƒ||ƒ||d	�}tj	d
krÆt
|ttfƒrÆd|_|jD ]@}||v r’q„| |¡ |j tjt|ƒ||j|ˆˆ ˆ|d�¡ q„t
|tƒ�rt|jpÜd|jpäd|jpìd|jpôd|j|d�|_| |¡ |jj}tttt f  tttt f  dœ‡ ‡fdd„}t!|ƒD �]2\}}|j"j#}d}tj	d
k�rÔ|j$d }t%t&|j" '¡ ||d ƒƒ}|\}}}}|du�rÔ|du�rÔ|du�rÔ|du�rÔ||f||ff}|�r| (d¡�st)j* +|¡�st)j* ,||¡}|j- .dd¡�r�qJt/|�p d||j"j0|�rN‡‡‡fdd„||j- 1¡ ƒD ƒnd|d�}||ƒ |j- .dd¡�rJ|jdd…= �qJ|�söt|ddƒ} | du�r¼| |u�r¼| j2}| }| j}d}qF|j3} | du�röt|ddƒ�sö| j2}| }| j}d}qF�qöqFt4|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_max_depth (int, optional): Maximum depths of locals before truncating, or None to disable. Defaults to None.
            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_CWDZ	__notes__N)Ú_objectr7   c                 S   s$   z
t | ƒW S  ty   Y dS 0 dS )z1Don't allow exceptions from __str__ to propagate.z<exception str() failed>N)r‚   rt   )r¯   r@   r@   rA   Úsafe_strÜ  s    
z#Traceback.extract.<locals>.safe_str)rŽ   r�   r‘   r‹   )rE   é   T)rL   rM   rP   rQ   r­   ú?r{   )r‡   rx   ry   r|   rˆ   r‹   )Úiter_localsr7   c                 3   sR   ˆ sˆs| E dH  dS | D ]2\}}ˆ r2|  d¡r2qˆrB|  d¡rBq||fV  qdS )z-Extract locals from an iterator of key pairs.NÚ__rn   ©Ú
startswith)r³   ÚkeyrX   )rP   rQ   r@   rA   Ú
get_locals  s    
z%Traceback.extract.<locals>.get_localsri   r   ú<Z_rich_traceback_omitc              	      s8   i | ]0\}}t  |¡st  |¡s|tj|ˆˆˆ d �“qS ))Ú
max_lengthÚ
max_stringÚ	max_depth)ÚinspectÚ
isfunctionÚisclassr   Útraverse)Ú.0r·   rX   )rO   rM   rN   r@   rA   Ú
<dictcomp>D  s   ùüz%Traceback.extract.<locals>.<dictcomp>)rx   ry   rz   r}   r~   Ú_rich_traceback_guardÚ	__cause__Ú__suppress_context__)r–   )5Zrichr®   ÚgetattrÚsetr   r‚   r�   r   rs   Úversion_infor¡   ZBaseExceptionGroupZExceptionGroupr“   r•   Úaddr¨   r[   r    ÚtypeÚ__traceback__ÚSyntaxErrorr†   r‡   rx   ry   r˜   rˆ   r�   r’   r   r   Úobjectr   Úf_codeÚco_filenameÚf_lastiÚnextr   Zco_positionsr¶   r£   r¤   ÚisabsÚjoinÚf_localsrk   rw   Úco_nameÚitemsÚ	__class__Ú__context__r”   )"r¬   rŽ   r�   rY   rL   rM   rN   rO   rP   rQ   r­   r–   r‘   r®   r‹   Úgrouped_exceptionsr°   ÚstackÚ	exceptionr¨   r¸   Úframe_summaryr?   rx   r~   Zinstruction_indexZinstruction_positionZ
start_lineZend_lineZstart_columnZ
end_columnÚframeÚcauser›   r@   )rP   rQ   rO   rM   rN   rA   r    °  sä    !ÿü


øÿú	
þ
ýÿûÿþýüþöùîÿ
zTraceback.extract)rF   Úoptionsr7   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ttdœ‡ ‡‡‡‡‡fdd	„ƒ‰ttˆjjƒƒD ]\}}ˆ||ƒV  qèd S )
NT)Zdim)Z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)Zinherit)rÚ   r>   r7   c           	   
   3   sØ  | j r\tˆ | ¡dˆ dddd�}t|ˆjƒ}ˆ ˆ¡� |V  W d   ƒ n1 sR0    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  | jD ]}t 	d
ˆ|ƒ¡V  �q | j�r¬t| jdƒD ]\\}}g }t|jƒD ]\}}| ˆ||ƒ¡ �qddV  ttt|Ž d|› �dd�ˆjƒV  �qN|�sÔ| j�rÈt d¡V  nt d¡V  d S )Nz7[traceback.title]Traceback [dim](most recent call last)ztraceback.borderT)r   r   )ÚtitleÚstyleÚborder_styleÚexpandÚpaddingztraceback.border.syntax_error)rå   ræ   rç   rè   rG   z: ztraceback.exc_type)z[NOTE] ztraceback.noter   r{   zSub-exception #ztraceback.group.border)rä   ræ   zI
[i]The above exception was the direct cause of the following exception:
zH
[i]During handling of the above exception, another exception occurred:
)r’   r,   Ú_render_stackr)   rG   Z	use_themer�   Ú_render_syntax_errorr   ÚassemblerŽ   rˆ   r�   r‹   r“   Ú	enumerater•   r    r–   r¨   r&   r‘   Úfrom_markup)	rÚ   r>   Zstack_renderableZnoteZgroup_noZgroup_exceptionrÙ   Z
group_lastZgroup_stack©Zbackground_stylerF   ÚhighlighterÚrender_stackrª   Ztraceback_themer@   rA   rð   ‘  sv    ú$

ú÷$
þþ
ýú
	ÿÿz0Traceback.__rich_console__.<locals>.render_stack)rJ   Zget_background_styleZget_style_for_tokenr1   Ú	TextTokenr   r   r   ZFunctionr   r   r.   r   ÚConstantZ	Delimiterr   r+   r(   r�   r]   r'   r    Úreversedr›   r–   )rª   rF   rß   rJ   Ztoken_styler>   rÚ   r@   rî   rA   Ú__rich_console__r  s8    ðí"CzTraceback.__rich_console__)r�   r7   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>ú rá   ©ú:rà   rã   rà   ©rå   Tr   zbold underlineÚ
u   [traceback.offset]â–²[/])r+   r—   rx   r£   r¤   Úexistsr   rë   r‚   ry   r|   ÚrstripZno_wrapÚminr‡   ÚlenZstylizerí   )rª   r�   rï   Úpath_highlighterr˜   Zsyntax_error_textr‡   r@   r@   rA   rê   Ø  s(    
ü
þzTraceback._render_syntax_error)rx   Úcoder7   c                 C   s„   t j |¡d }|sP| d¡}|dkr2|d |… n|}| d¡rPd| ¡ v rPdS z| j |¡pht||ƒj	W S  t
y~   Y dS 0 d S )Nr8   rù   z#!r™   r˜   )r£   r¤   ÚsplitextÚindexr¶   ÚlowerÚLEXERSrk   r   rz   r   )r¬   rx   rÿ   ÚextZnew_line_indexÚ
first_liner@   r@   rA   Ú_guess_lexerï  s    
zTraceback._guess_lexer)rÚ   r7   c                 #   s  t ƒ }ˆj}ttt dœ‡fdd„}d }ˆjdkrRtˆjd t|jƒˆjd  ƒ}d}t	|jƒD �]š\}}|r|||v r|d}q`|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 |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¡�sV|	�sVdV  |V  |j d¡�rz||ƒE d H  q`|
s`zrt |j¡}d |¡}|�s W q`ˆ |j|¡}t|||d|jˆj |jˆj f|jhˆjˆjˆjdd�
}dV  W n< t�y, } z"t
 d|› �df¡V  W Y d }~q`d }~0 0 |j d u�rØ|j \}}t!||ƒD ]ˆ\}}}zH|dk�r„||d  }t|ƒt| "¡ ƒ }|dk�ržt||d  ƒ}W n t#�yº   Y �qNY n0 |j$d||f||fd� �qN|j%�röt&|g||ƒ¢dd�n|V  q`d S ) N)rÝ   r7   c              	   3   s.   | j r*t| j dˆ jˆ jˆ jˆ jˆ jd�V  d S )Nr}   )rä   rS   rº   r»   r¼   Zoverflow)r}   r-   rS   rM   rN   rO   rR   )rÝ   )rª   r@   rA   Úrender_locals  s    ùz.Traceback._render_stack.<locals>.render_localsr   ri   FTz
... z frames hidden ...Úcenterztraceback.error)Zjustifyrå   c                 3   s   | ]}ˆ   |¡V  qd S )Nrµ   )rÁ   r¤   )Úframe_filenamer@   rA   Ú	<genexpr>(  ó    z*Traceback._render_stack.<locals>.<genexpr>rá   rø   rö   rã   z in râ   rà   zin r¹   r{   )rJ   Zline_numbersZ
line_rangeZhighlight_linesrK   rH   rS   Údedentrù   r   r8   ztraceback.error_range)rå   r5   r6   )rè   )'r—   rJ   rw   r   r$   rU   r9   rý   r’   rì   r   rx   ÚanyrT   r£   r¤   rú   rë   r‚   ry   rz   r¶   Ú	linecacheÚgetlinesrÓ   r  r/   rI   rK   rH   rS   rt   r~   rB   ÚlstripÚ
IndexErrorZstylize_ranger}   r!   )rª   rÚ   rþ   rJ   r  Zexclude_framesZexcludedZframe_indexrÝ   r=   Z
suppressedr˜   Z
code_linesrÿ   Z
lexer_nameÚsyntaxÚerrorr5   r6   r:   r;   r<   r|   r@   )r	  rª   rA   ré   ÿ  sÆ    
þýú	û


þó
ÿ


ý
ùÿþû÷zTraceback._render_stack)N)#r   r€   r�   Ú__doc__r  ÚLOCALS_MAX_LENGTHÚLOCALS_MAX_STRINGr   r”   r„   r‚   r]   r%   r   r   r   r«   Úclassmethodr   r   rr   r   r\   r   r    r"   r#   r'   rô   r(   r†   rê   r  r�   ré   r@   r@   r@   rA   r[     sÜ   û
 þîî9ìëOô
ó Cþfr[   Ú__main__rœ   )Úar7   c                 C   s   d}t ||  ƒ d S )Nr   )r^   )r  Zoner@   r@   rA   Ú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zedr@   r@   rA   ÚfooŒ  s
    ù	r  )r7   c                   C   s   t dƒ d S )Nr   )r  r@   r@   r@   rA   r  ™  s    r  )\r½   r  r£   rs   Zdataclassesr   r   Ú	itertoolsr   rY   r   Útypesr   r   Útypingr   r	   r
   r   r   r   r   r   r   r   r   Zpygments.lexersr   Zpygments.tokenr   r   r   r   r   r   r   rñ   r   Zpygments.utilr   r{   r   Z_loopr   r    Úcolumnsr!   rF   r"   r#   r$   r%   r&   r'   r(   Z	constrainr)   rï   r*   r+   Zpanelr,   Zscoper-   rå   r.   r  r/   r0   r˜   rJ   r1   ÚplatformÚWINDOWSr  r  r„   rB   r‚   r]   rr   rv   rw   r†   r�   r”   r—   r[   r   r  r  r  r@   r@   r@   rA   Ú<module>   s¶   4 $	
þïî 
		     

þ