
    g(                    d    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  G d d      Zy)	    )annotationsN)Any)config)magic)open_python_filec                  &    e Zd ZdZd ZddZddZy)ScriptCachez,Thread-safe cache of Python script bytecode.c                D    i | _         t        j                         | _        y )N)_cache	threadingLock_lockselfs    `/var/www/openai/venv/lib/python3.12/site-packages/streamlit/runtime/scriptrunner/script_cache.py__init__zScriptCache.__init__   s    &(^^%
    c                z    | j                   5  | j                  j                          ddd       y# 1 sw Y   yxY w)z~Remove all entries from the cache.

        Notes
        -----
        Threading: SAFE. May be called on any thread.
        N)r   r   clearr   s    r   r   zScriptCache.clear"   s%     ZZKK ZZs   1:c           	        t         j                  j                  |      }| j                  5  | j                  j                  |d      }||cddd       S t        |      5 }|j                         }ddd       t        j                  d      rt        j                  |      }t        |dddd      }|| j                  |<   |cddd       S # 1 sw Y   _xY w# 1 sw Y   yxY w)a\  Return the bytecode for the Python script at the given path.

        If the bytecode is not already in the cache, the script will be
        compiled first.

        Raises
        ------
        Any Exception raised while reading or compiling the script.

        Notes
        -----
        Threading: SAFE. May be called on any thread.
        Nzrunner.magicEnabledexecr      )modeflagsdont_inheritoptimize)ospathabspathr   r   getr   readr   
get_optionr   	add_magiccompile)r   script_pathbytecodeffilebodys        r   get_bytecodezScriptCache.get_bytecode,   s     ggook2ZZ{{{D9H#	 Z "+.!668 /   !67 ??8[A H (0DKK$9 Z /. Zs*    CC!C2ACC	CC%N)returnNone)r&   strr+   r   )__name__
__module____qualname____doc__r   r   r*    r   r   r	   r	      s    6&
 -r   r	   )
__future__r   os.pathr   r   typingr   	streamlitr   streamlit.runtime.scriptrunnerr   streamlit.source_utilr   r	   r2   r   r   <module>r9      s&    #     0 2? ?r   