o
    hb                     @  sf   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dZ
	ddddZdddZdS )    )annotationsN)StringIO)	FrameType   )ExcInfoexc_infor   returnstrc                 C  s`   | dkrdS 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.
    )NNNMISSINGr   r      N
)r   	tracebackprint_exceptiongetvalueclose)r   sios r   G/var/www/html/ai/venv/lib/python3.10/site-packages/structlog/_frames.py_format_exception   s   r   additional_ignoreslist[str] | Nonetuple[FrameType, str]c                   s   dg| pg  }t  }|jdpd tt fdd|D rD|jdu r,d 	 | fS |j}|jdp6d tt fdd|D s | fS )z
    Remove all intra-structlog calls and return the relevant app frame.

    Arguments:

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

    Returns:

        tuple of (frame, name)
    	structlog__name__?c                 3  s    | ]}  |V  qd S N)
startswith).0inamer   r   	<genexpr>7   s    z1_find_first_app_frame_and_name.<locals>.<genexpr>N)sys	_getframe	f_globalsgetanytuplef_back)r   ignoresfr   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_stack@   s   
r3   )r   r   r   r	   r   )r   r   r   r   )r.   r   r   r	   )
__future__r   r$   r   ior   typesr   typingr   r   r-   r3   r   r   r   r   <module>   s   
