o
    ˷e)                     @   s   d dl Z d dlZd dlZd dl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 d dlmZmZmZmZmZmZ eeZG dd dZdS )	    N)Counter)escape)	FrameTypeTracebackType)UnionIterableList)style_with_executing_nodeOptionsLine	FrameInfoVariableRepeatedFramesc                   @   s&  e Zd ZddddddddddddddddZd+d	ee fd
dZded	efddZd+d	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fddZdd Zded	efddZded	e
e fd d!Zd"ed	efd#d$Zd%d& Zd	efd'd(Zded	efd)d*ZdS ),
SerializerNFTmonokaiz
bg:#005080)options	pygmentedshow_executing_nodepygments_formatter_clspygments_formatter_kwargspygments_styleexecuting_node_modifieruse_code_qualnamestrip_leading_indenthtmlchaincollapse_repeated_framesshow_variablesc                C   s   |d u rt  }|r2|js2|rt||}|d u r&|
r ddlm} nddlm} |dd|i|p.i |_|| _|| _|	| _	|
| _
|| _|| _|| _|| _d S )Nr   )HtmlFormatter)Terminal256Formatterstyle )r
   pygments_formatterr	   pygments.formatters.htmlr   pygments.formatters.terminal256r   r   r   r   r   r   r   r   r   )selfr   r   r   r   r   r   r   r   r   r   r   r   r   r!   r!   M/var/www/ideatree/venv/lib/python3.10/site-packages/stack_data/serializing.py__init__   s0   

zSerializer.__init__returnc                 C   s   |d u r
t  d }g }| jr;|jd ur$| |j}tj |d d< n|jd ur;|j	s;| |j}tj
 |d d< || | |S )N   tail)sysexc_infor   	__cause__format_exception	traceback_cause_messagestrip__context____suppress_context___context_messageappendformat_traceback_part)r%   eresultr!   r!   r&   r/   I   s   
zSerializer.format_exceptionr8   c                 C   s6   t | |jpt d t t|jt|dddS )N   )typemessage )frames	exceptionr+   )	dictformat_stack__traceback__r,   r-   r;   __name__r0   	_some_str)r%   r8   r!   r!   r&   r7   Z   s   z Serializer.format_traceback_partc                 C   s0   |d u r	t  j}t| tj|| j| jdS )N)r   )	inspectcurrentframef_backlistformat_stack_datar   
stack_datar   r   )r%   frame_or_tbr!   r!   r&   rA   d   s   
zSerializer.format_stackstackc                 c   s\    |D ](}t |tr| |sqtdddi| |V  qtdddi| |V  qd S )Nr;   framerepeated_framesr!   )
isinstancer   should_include_framer@   format_frameformat_repeated_frames)r%   rL   itemr!   r!   r&   rI   r   s   

zSerializer.format_stack_datarN   c                 C   s.   t t|j dd d}tdd |D dS )Nc                 S   s   | d  | d d j fS )Nr)   r   )co_name)rS   r!   r!   r&   <lambda>   s    z3Serializer.format_repeated_frames.<locals>.<lambda>keyc                 S   s$   g | ]\\}}}t |j||d qS ))namelinenocount)r@   rT   ).0coderY   rZ   r!   r!   r&   
<listcomp>   s    
z5Serializer.format_repeated_frames.<locals>.<listcomp>)r>   )sortedr   
frame_keysitemsr@   )r%   rN   countsr!   r!   r&   rR   }   s   z!Serializer.format_repeated_framesrM   c                 C   sf   t |tst|| j}t| jr|j n|jj|j	|j
t| |jd}| jr1t| ||d< |S )N)rX   filenamerY   lines	variables)rO   r   r   r@   r   	executingcode_qualnamer\   rT   rb   rY   rH   format_linesrc   r   format_variables)r%   rM   r9   r!   r!   r&   rQ      s   

zSerializer.format_framec                 c   sB    |D ]}t |trtdddi| |V  qtddV  qd S )Nr;   lineline_gap)r;   r!   )rO   r   r@   format_line)r%   rc   ri   r!   r!   r&   rg      s   
zSerializer.format_linesri   c                 C   s$   t |j|j|j| j| j| jddS )N)r   escape_htmlr   )
is_currentrY   text)r@   rm   rY   renderr   r   r   )r%   ri   r!   r!   r&   rk      s   zSerializer.format_line
frame_infoc                 c   sL    zt |jdd dD ]}| |V  qW d S  ty%   td Y d S w )Nc                 S   s   | j S N)rX   )vr!   r!   r&   rU      s    z-Serializer.format_variables.<locals>.<lambda>rV   z Error in getting frame variables)r^   rd   format_variable	Exceptionlogr?   )r%   rp   varr!   r!   r&   rh      s   zSerializer.format_variablesrv   c                 C   s"   t | |j| | |jdS )N)rX   value)r@   format_variable_partrX   format_variable_valuerw   )r%   rv   r!   r!   r&   rs      s   
zSerializer.format_variablec                 C   s   | j rt|S |S rq   )r   rl   )r%   rn   r!   r!   r&   rx      s   zSerializer.format_variable_partc                 C   s   t |S rq   )repr)r%   rw   r!   r!   r&   ry      s   z Serializer.format_variable_valuec                 C   s   dS )NTr!   )r%   rp   r!   r!   r&   rP      s   zSerializer.should_include_framerq   )rC   
__module____qualname__r'   r   r@   r/   BaseExceptionr7   rA   r   r   r   r   rI   rR   r   r   rQ   rg   r   rk   rh   r   rs   rx   strry   boolrP   r!   r!   r!   r&   r      s@    2

r   )rE   loggingr,   r0   collectionsr   r   r   rl   typesr   r   typingr   r   r   rJ   r	   r
   r   r   r   r   	getLoggerrC   ru   r   r!   r!   r!   r&   <module>   s     
	