o
    i3                     @  sX  U 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 Zedeeed	d
dZeej Zeh dksUJ daded< d2ddZeeejjjjjjj eeejj eeejj d3ddZ eddd4ddZ!d5d"d#Z"d6d$d%Z#d7d'd(Z$ed)dd8d+d,Z%d9d0d1Z&dS ):    )annotationsN)	lru_cache)Path)CodeType	FrameType)	TypedDict.	StackInfo)code.filepathcode.linenocode.functionF)total>   r   r
   r    ztuple[str, ...]NON_USER_CODE_PREFIXESpath
str | PathreturnNonec                 C  s   t t|  } t| f7 adS )a  Add a path to the list of prefixes that are considered non-user code.

    This prevents the stack info from including frames from the given path.

    This is for advanced users and shouldn't often be needed.
    By default, the following prefixes are already included:

    - The standard library
    - site-packages (specifically wherever opentelemetry is installed)
    - The logfire package

    This function is useful if you're writing a library that uses logfire and you want to exclude your library's frames.
    Since site-packages is already included, this is already the case by default for users of your library.
    But this is useful when testing your library since it's not installed in site-packages.
    N)strr   absoluter   )r   r   r   b/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/logfire/_internal/stack_info.pyadd_non_user_code_prefix   s   r   filer   c                 C  s>   t | }| rz|t}W n	 ty   Y nw dt|iS )Nr
   )r   is_absoluterelative_to_CWD
ValueErrorr   )r   r   r   r   r   get_filepath_attribute3   s   r   i   )maxsizecoder   c                 C  s<   t | j}| jdk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)r   resultr   r   r   get_code_object_info>   s
   


r)   framer   c                 C  s   i t | jd| jiS )Nr   )r)   f_codef_lineno)r*   r   r   r   get_stack_info_from_frameG   s
   r-   c                  C  s   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*   _stacklevelr   r   r   get_user_stack_infoN   s   
r0   tuple[FrameType | None, int]c                  C  sF   t  } d}| r!t| jr| |fS | j} |d7 }|dkr	 dS | sdS )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      i'  )Nr   )inspectcurrentframeis_user_coder+   f_back)r*   
stacklevelr   r   r   r.   Z   s   

r.   i    boolc                 C  s0   t t| j tp| jdp| 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"   r   
startswithr   r#   )r   r   r   r   r5   o   s
   
r5   msgcategorytype[Warning]c                 C  s   t  \}}tj| ||d d S )N)r7   r<   )r.   warningswarn)r;   r<   _framer7   r   r   r   warn_at_user_stacklevel   s   
rA   )r   r   r   r   )r   r   r   r	   )r   r   r   r	   )r*   r   r   r	   )r   r	   )r   r1   )r   r   r   r8   )r;   r   r<   r=   )'
__future__r   r3   r$   r>   	functoolsr   pathlibr   typesr   r   typingr   opentelemetry.sdk.traceopentelemetrylogfireresolver   r   intr	   set__annotations__keysSTACK_INFO_KEYSr   r   sdktrace__file__parentr   r)   r-   r0   r.   r5   rA   r   r   r   r   <module>   s8    




