o
    ADi                     @  s   d dl mZ d dlZd dl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 dddZ	dejddddZdddZdS )    )annotationsN)StringIO)	FrameType)Callable   )_ASYNC_CALLING_STACK)ExcInfoexc_infor   returnstrc                 C  sT   t  }t| d | d | d d| | }|  |dd dkr(|dd }|S )z`
    Prettyprint an `exc_info` tuple.

    Shamelessly stolen from stdlib's logging module.
    r   r      N
)r   	tracebackprint_exceptiongetvalueclose)r	   sios r   J/var/www/Datamplify/venv/lib/python3.10/site-packages/structlog/_frames.py_format_exception   s   r   )	_getframeadditional_ignoreslist[str] | Noner   Callable[[], FrameType]tuple[FrameType, str]c                C  sx   t dg| pg  }t| }|jdpd}||r8|jdu r(d}	 ||fS |j}|jdp2d}||s||fS )ap  
    Remove all intra-structlog calls and return the relevant app frame.

    Args:
        additional_ignores:
            Additional names with which the first frame must not start.

        _getframe:
            Callable to find current frame. Only for testing to avoid
            monkeypatching of sys._getframe.

    Returns:
        tuple of (frame, name)
    	structlog__name__?N)tupler   get	f_globals
startswithf_back)r   r   ignoresfnamer   r   r   _find_first_app_frame_and_name$   s   


r(   framer   c                 C  sJ   t  }|d tj| |d | }|d dkr|dd }|  |S )z?
    Pretty-print the stack of *frame* like logging would.
    zStack (most recent call last):
)filer   r   N)r   writer   print_stackr   r   )r)   r   sinfor   r   r   _format_stackC   s   
r.   )r	   r   r
   r   )N)r   r   r   r   r
   r   )r)   r   r
   r   )
__future__r   sysr   ior   typesr   typingr   contextvarsr   r   r   r   r(   r.   r   r   r   r   <module>   s   
