o
    tdfD                     @   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 d dl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RepeatedFrames)some_strc                   @   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
   Zpygments_formatterr	   Zpygments.formatters.htmlr   Z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"   _/var/www/html/software/conda/envs/catlas/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-   J   s   
zSerializer.format_exceptionr6   c                 C   s4   t | |jpt d t t|jt|dddS )N   )typemessage )frames	exceptionr)   )dictformat_stack__traceback__r*   r+   r9   __name__r   )r#   r6   r"   r"   r$   r5   [   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#   Zframe_or_tbr"   r"   r$   r?   e   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 )Nr9   framerepeated_framesr"   )
isinstancer   should_include_framer>   format_frameformat_repeated_frames)r#   rH   itemr"   r"   r$   rF   s   s   

zSerializer.format_stack_datarJ   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)rO   r"   r"   r$   <lambda>   s    z3Serializer.format_repeated_frames.<locals>.<lambda>keyc                 S   s$   g | ]\\}}}t |j||d qS ))namelinenocount)r>   rP   ).0coderU   rV   r"   r"   r$   
<listcomp>   s    
z5Serializer.format_repeated_frames.<locals>.<listcomp>)r<   )sortedr   Z
frame_keysitemsr>   )r#   rJ   countsr"   r"   r$   rN   ~   s   z!Serializer.format_repeated_framesrI   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)rT   filenamerU   lines	variables)rK   r   r   r>   r   Z	executingZcode_qualnamerX   rP   r]   rU   rE   format_linesr^   r   format_variables)r#   rI   r7   r"   r"   r$   rM      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 )Nr9   lineZline_gap)r9   r"   )rK   r   r>   format_line)r#   r^   rb   r"   r"   r$   r`      s   
zSerializer.format_linesrb   c                 C   s$   t |j|j|j| j| j| jddS )N)r   escape_htmlr   )
is_currentrU   text)r>   re   rU   renderr   r   r   )r#   rb   r"   r"   r$   rc      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)rT   )vr"   r"   r$   rQ      s    z-Serializer.format_variables.<locals>.<lambda>rR   z Error in getting frame variables)rZ   r_   format_variable	Exceptionlogr=   )r#   rh   varr"   r"   r$   ra      s   zSerializer.format_variablesrn   c                 C   s"   t | |j| | |jdS )N)rT   value)r>   format_variable_partrT   format_variable_valuero   )r#   rn   r"   r"   r$   rk      s   
zSerializer.format_variablec                 C   s   | j rt|S |S ri   )r   rd   )r#   rf   r"   r"   r$   rp      s   zSerializer.format_variable_partc                 C   s   t |S ri   )repr)r#   ro   r"   r"   r$   rq      s   z Serializer.format_variable_valuec                 C   s   dS )NTr"   )r#   rh   r"   r"   r$   rL      s   zSerializer.should_include_frameri   )rA   
__module____qualname__r%   r   r>   r-   BaseExceptionr5   r?   r   r   r   r   rF   rN   r   r   rM   r`   r   rc   ra   r   rk   rp   strrq   boolrL   r"   r"   r"   r$   r      s@    2

r   )rB   loggingr*   r.   collectionsr   r   r   rd   typesr   r   typingr   r   r   rG   r	   r
   r   r   r   r   Zstack_data.utilsr   	getLoggerrA   rm   r   r"   r"   r"   r$   <module>   s     
