o
    h(                     @  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 G dd dZdS )	    )annotationsN)Any)config)magic)open_python_filec                   @  s,   e Zd ZdZdd ZdddZdddZdS )ScriptCachez,Thread-safe cache of Python script bytecode.c                 C  s   i | _ t | _d S )N)_cache	threadingLock_lockself r   _/var/www/vscode/kcb/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_cache.py__init__   s   zScriptCache.__init__returnNonec                 C  s6   | j  | j  W d   dS 1 sw   Y  dS )z~Remove all entries from the cache.

        Notes
        -----
        Threading: SAFE. May be called on any thread.
        N)r   r   clearr   r   r   r   r   "   s   "zScriptCache.clearscript_pathstrr   c              	   C  s   t j|}| jP | j|d}|dur|W  d   S t|}| }W d   n1 s1w   Y  t	drAt
||}t||ddddd}|| j|< |W  d   S 1 s\w   Y  dS )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   r   bytecodeffilebodyr   r   r   get_bytecode,   s,   



$zScriptCache.get_bytecodeN)r   r   )r   r   r   r   )__name__
__module____qualname____doc__r   r   r(   r   r   r   r   r      s
    

r   )
__future__r   os.pathr   r	   typingr   	streamlitr   streamlit.runtime.scriptrunnerr   streamlit.source_utilr   r   r   r   r   r   <module>   s   