o
    ˷e<!                     @   s   d dl Z d dlZd dlZd dlmZ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 G dd dZdS )    N)	FrameTypeTracebackType)UnionIterable)	style_with_executing_nodeOptionsLine	FrameInfoLINE_GAPVariableRepeatedFramesBlankLineRange
BlankLines)assert_c                   @   sR  e Zd Zddddddddddd	d
ddddddddddZdd Zd4ddddZd4ddddZddddZd4dee	 fddZ
d4dee	 fddZdeeeef  dee	 fddZdede	fd d!Zd"eeeef dee	 fd#d$Zd%ede	fd&d'Zd(ede	fd)d*Zd+d, Zd%edee	 fd-d.Zd/ede	fd0d1Zde	fd2d3ZdS )5	FormatterNFTmonokaiz
bg:#005080^z-->z(...):z{:4} | )options	pygmentedshow_executing_nodepygments_formatter_clspygments_formatter_kwargspygments_styleexecuting_node_modifierexecuting_node_underlinecurrent_line_indicatorline_gap_stringline_number_gap_stringline_number_format_stringshow_variablesuse_code_qualnameshow_linenosstrip_leading_indenthtmlchaincollapse_repeated_framesc                C   s   |d u rt  }|r)|js)|rt||}|d u rddlm} |dd|i|p%i |_|| _|| _tt|dkt	d || _
|	p@d| _|
| _|| _|| _|| _|| _|| _|| _|| _|| _|| _|| _| jsq| jjtjkrst	dd S d S )	Nr   )Terminal256Formatterstyle   z3executing_node_underline must be a single character z@BlankLines.SINGLE option can only be used when show_linenos=True )r   pygments_formatterr   pygments.formatters.terminal256r'   r   r   r   len
ValueErrorr   r   r   r   r   r    r"   r!   r#   r$   r%   r   r&   blank_linesr   SINGLE)selfr   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r+   r+   L/var/www/ideatree/venv/lib/python3.10/site-packages/stack_data/formatting.py__init__   sL   


zFormatter.__init__c                    s    fdd}|t _d S )Nc                    s     | d S N)print_exception)_etypeevalue_tbr2   r+   r3   
excepthookN   s   z&Formatter.set_hook.<locals>.excepthook)sysr;   )r2   r;   r+   r:   r3   set_hookM   s   
zFormatter.set_hookfilec                C   s   | j | ||d d S Nr>   )print_linesformat_exception)r2   er?   r+   r+   r3   r6   S   s   zFormatter.print_exceptionc                C   s*   |d u r	t  j}| j| ||d d S r@   )inspectcurrentframef_backrA   format_stack)r2   frame_or_tbr?   r+   r+   r3   print_stackV   s   
zFormatter.print_stackc                C   s*   |d u rt j}|D ]	}t||dd q	d S )Nr*   )r?   end)r<   stderrprint)r2   linesr?   liner+   r+   r3   rA   \   s
   zFormatter.print_linesreturnc                 c   s    |d u rt  d }| jr6|jd ur!| |jE d H  tjV  n|jd ur6|js6| |jE d H  tj	V  dV  | 
|jE d H  tt||E d H  d S )Nr)   z#Traceback (most recent call last):
)r<   exc_infor%   	__cause__rB   	traceback_cause_message__context____suppress_context___context_messagerG   __traceback__format_exception_onlytype)r2   rC   r+   r+   r3   rB   b   s   


zFormatter.format_exceptionc                 c   s8    |d u r
t  j}| tj|| j| jdE d H  d S )N)r&   )rD   rE   rF   format_stack_datar	   
stack_datar   r&   )r2   rH   r+   r+   r3   rG   s   s   
zFormatter.format_stackstackc                 c   s8    |D ]}t |tr| |E d H  q| |V  qd S r5   )
isinstancer	   format_frameformat_repeated_frames)r2   r\   itemr+   r+   r3   rZ      s   
zFormatter.format_stack_datarepeated_framesc                 C   s   d |jS )Nz&    [... skipping similar frames: {}]
)formatdescription)r2   ra   r+   r+   r3   r_      s   z Formatter.format_repeated_framesframec                 c   s    t |tst|| j}| |V  |jD ]&}t |tr#| |V  qt |tr/| |V  qt	|t
u  | jd V  q| jrUz| |E d H  W d S  tyT   Y d S w d S )N
)r]   r	   r   format_frame_headerrM   r   format_liner   format_blank_lines_linenumbersr   r
   r   r    format_variables	Exception)r2   rd   rN   r+   r+   r3   r^      s$   



zFormatter.format_frame
frame_infoc                 C   s&   dj || jr|j dS |jjdS )NzC File "{frame_info.filename}", line {frame_info.lineno}, in {name}
)rk   name)rb   r!   	executingcode_qualnamecodeco_name)r2   rk   r+   r+   r3   rf      s   
zFormatter.format_frame_headerrN   c                 C   s   d}| j r|jr| j }ndt| j  }|d7 }nd}| jr&|| j|j7 }|}||j| j| j	| j
dd 7 }| jrf| jsf|jD ]%}|j|j }|j|j }||kre|d|t|  | j||   d 7 }q@|S )Nr*       )r   escape_htmlr#   re   )r   
is_currentr.   r"   r   rb   linenorenderr   r$   r#   r   executing_node_rangesstartleading_indentrJ   r   )r2   rN   resultprefix
line_rangerx   rJ   r+   r+   r3   rg      s>   

zFormatter.format_linec                 C   sP   | j rdt| j  d }nd}|j|jkr || j|j d S |d| j S )Nrq   rr   re   z   {}
)r   r.   begin_lineno
end_linenor   rb   r   )r2   
blank_linerz   r+   r+   r3   rh      s   z(Formatter.format_blank_lines_linenumbersc              	   c   sD    t |jdd dD ]}z
| |d V  W q
 ty   Y q
w d S )Nc                 S   s   | j S r5   )rl   )vr+   r+   r3   <lambda>   s    z,Formatter.format_variables.<locals>.<lambda>)keyre   )sorted	variablesformat_variablerj   )r2   rk   varr+   r+   r3   ri      s   zFormatter.format_variablesr   c                 C   s   d |j| |jS )Nz{} = {})rb   rl   format_variable_valuevalue)r2   r   r+   r+   r3   r      s   
zFormatter.format_variablec                 C   s   t |S r5   )repr)r2   r   r+   r+   r3   r      s   zFormatter.format_variable_valuer5   )__name__
__module____qualname__r4   r=   r6   rI   rA   r   strrB   rG   r   r	   r   rZ   r_   r   r   r^   rf   r   rg   rh   ri   r   r   r   r+   r+   r+   r3   r      sP    @
	 
&
r   )rD   r<   rR   typesr   r   typingr   r   r[   r   r   r   r	   r
   r   r   r   r   stack_data.utilsr   r   r+   r+   r+   r3   <module>   s    ,