a
    lcD                     @   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+ee d	d
dZeedddZd,ee d	ddZ	e
eeef  e
e dddZeedddZeeeef edddZdd ZeedddZee
e dd d!Zeed"d#d$Zd%d& Zed	d'd(Zeed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  }|rd|jsd|r&t||}|d u rL|
r@ddlm} nddlm} |f 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/django/DPS/env/lib/python3.9/site-packages/stack_data/serializing.py__init__   s0    
zSerializer.__init__)returnc                 C   s   |d u rt  d }g }| jrv|jd urH| |j}tj |d d< n.|jd urv|j	sv| |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_exception)r6   r&   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)stackr&   c                 c   sZ   |D ]P}t |tr:| |sqtf ddi| |V  qtf ddi| |V  qd S )Nr9   framerepeated_frames)
isinstancer   should_include_framer>   format_frameformat_repeated_frames)r"   rH   itemr#   r#   r$   rF   s   s    

zSerializer.format_stack_data)rJ   r&   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>       z3Serializer.format_repeated_frames.<locals>.<lambda>keyc                 S   s$   g | ]\\}}}t |j||d qS ))namelinenocount)r>   rP   ).0coderV   rW   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_frames)rI   r&   c                 C   sf   t |tst|| j}t| jr(|j n|jj|j	|j
t| |jd}| jrbt| ||d< |S )N)rU   filenamerV   lines	variables)rK   r   r   r>   r   Z	executingZcode_qualnamerY   rP   r^   rV   rE   format_linesr_   r   format_variables)r"   rI   r7   r#   r#   r$   rM      s    

zSerializer.format_framec                 c   s@   |D ]6}t |tr.tf ddi| |V  qtddV  qd S )Nr9   lineZline_gap)r9   )rK   r   r>   format_line)r"   r_   rc   r#   r#   r$   ra      s    
zSerializer.format_lines)rc   r&   c                 C   s$   t |j|j|j| j| j| jddS )N)r   escape_htmlr   )
is_currentrV   text)r>   rf   rV   renderr   r   r   )r"   rc   r#   r#   r$   rd      s    zSerializer.format_line)
frame_infor&   c                 c   sJ   z(t |jdd dD ]}| |V  qW n tyD   td Y n0 d S )Nc                 S   s   | j S N)rU   )vr#   r#   r$   rQ      rR   z-Serializer.format_variables.<locals>.<lambda>rS   z Error in getting frame variables)r[   r`   format_variable	Exceptionlogr=   )r"   ri   varr#   r#   r$   rb      s
    zSerializer.format_variables)ro   r&   c                 C   s"   t | |j| | |jdS )N)rU   value)r>   format_variable_partrU   format_variable_valuerp   )r"   ro   r#   r#   r$   rl      s    
zSerializer.format_variablec                 C   s   | j rt|S |S d S rj   )r   re   )r"   rg   r#   r#   r$   rq      s    zSerializer.format_variable_partc                 C   s   t |S rj   )repr)r"   rp   r#   r#   r$   rr      s    z Serializer.format_variable_valuec                 C   s   dS )NTr#   )r"   ri   r#   r#   r$   rL      s    zSerializer.should_include_frame)N)N)rA   
__module____qualname__r%   r   r>   r-   BaseExceptionr5   r?   r   r   r   r   rF   rN   r   r   rM   ra   r   rd   rb   r   rl   rq   strrr   boolrL   r#   r#   r#   r$   r      s:   2
r   )rB   loggingr*   r.   collectionsr   r   r   re   typesr   r   typingr   r   r   rG   r	   r
   r   r   r   r   Zstack_data.utilsr   	getLoggerrA   rn   r   r#   r#   r#   r$   <module>   s    
