
    gp                       d dl m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 d dlZd dlZ ed      j#                         Z edeeed	d
      Z eej.                  j1                               Zeh dk(  sJ  e eej4                  j6                  j8                        j:                  j:                  j:                  j:                  j=                               Z e eej8                        j:                  j=                               Z  e eej8                        j:                  j=                               Z!ee e!fZ"ddZ# ed      dd       Z$ddZ%ddZ&ddZ' ed      dd       Z(ddZ)y)    )annotationsN)	lru_cache)Path)CodeType	FrameType)	TypedDict.	StackInfo)code.filepathcode.linenocode.functionF)total>   r   r   r   c                    t        |       }|j                         r	 |j                  t              }dt        |      iS # t        $ r Y w xY w)Nr   )r   is_absoluterelative_to_CWD
ValueErrorstr)filepaths     Q/var/www/openai/venv/lib/python3.12/site-packages/logfire/_internal/stack_info.pyget_filepath_attributer      sQ    :D	##D)D SY''  		s   ? 	A
Ai   )maxsizec                    t        | j                        }| j                  dk7  r.t        j                  dk\  r| j
                  n| j                  |d<   | j                  |d<   |S )Nz<module>)      r   r   )r   co_filenameco_namesysversion_infoco_qualnameco_firstlineno)coderesults     r   get_code_object_infor%   '   sY    #D$4$45F||z!696F6F'6Q$"2"2W[WcWc //F=M    c                L    i t        | j                        d| j                  iS )Nr   )r%   f_codef_lineno)frames    r   get_stack_info_from_framer+   0   s+    
u||
,u~~ r&   c                 :    t               \  } }| rt        |       S i S )zGet the stack info for the first calling frame in user code.

    See is_user_code for details.
    Returns an empty dict if no such frame is found.
    )get_user_frame_and_stacklevelr+   )r*   _stacklevels     r   get_user_stack_infor/   7   s$     78E;(//Ir&   c                     t        j                         } d}| r-t        | j                        r| |fS | j                  } |dz  }| r-y)zGet the first calling frame in user code and a corresponding stacklevel that can be passed to `warnings.warn`.

    See is_user_code for details.
    Returns `(None, 0)` if no such frame is found.
    r      )Nr   )inspectcurrentframeis_user_coder(   f_back)r*   
stacklevels     r   r-   r-   C   sM       "EJ
%*$$a
	 
 r&   i    c                    t        t        | j                        j                               j	                  t
              xs+ | j                  j	                  d      xs | j                  dv  S )a  Check if the code object is from user code.

    A code object is not user code if:
    - It is from a file in
        - the standard library
        - site-packages (specifically wherever opentelemetry is installed)
        - the logfire package
        - an unknown location (e.g. a dynamically generated code object) indicated by a filename starting with '<'
    - It is a list/dict/set comprehension.
        These are artificial frames only created before Python 3.12,
        and they are always called directly from the enclosing function so it makes sense to skip them.
        On the other hand, generator expressions and lambdas might be called far away from where they are defined.
    <)z
<listcomp>z
<dictcomp>z	<setcomp>)r   r   r   absolute
startswithNON_USER_CODE_PREFIXESr   )r#   s    r   r4   r4   S   sc      	D!!"++-.99:PQ 	E&&s+	E<<DD r&   c                N    t               \  }}t        j                  | ||       y )N)r6   category)r-   warningswarn)msgr=   _framer6   s       r   warn_at_user_stacklevelrB   i   s    68FJMM#*x@r&   )r   r   returnr
   )r#   r   rC   r
   )r*   r   rC   r
   )rC   r
   )rC   ztuple[FrameType | None, int])r#   r   rC   bool)r@   r   r=   ztype[Warning])*
__future__r   r2   r   r>   	functoolsr   pathlibr   typesr   r   typingr   opentelemetry.sdk.traceopentelemetrylogfireresolver   r   intr
   set__annotations__keysSTACK_INFO_KEYSsdktrace__file__parentr9   SITE_PACKAGES_DIRPYTHON_LIB_DIRLOGFIRE_DIRr;   r   r%   r+   r/   r-   r4   rB    r&   r   <module>r[      sX   "  
    %   CykS_b#ckpq	i//4467KK KK]..44==>EELLSSZZccef T'**+22;;=>$w''(//88:;+^[I ( 4 	  4 *Ar&   