
    -e;                        d Z ddlmZ ddlZ ej        e          ZddlZddlZddl	m
Z
mZmZmZ ddlmZ dZdd
ZddZddZddZddZdS )z

    )annotationsN)basenamedirnamejoinsplitext)NamedTemporaryFile)default_filenamedetect_current_filenametemp_filenameextstrreturnc                r   | dk    rt          d          t                      }|t          |           S t          |          pt	          j                    }t          |          st          |          rt          |           S t          t          |                    \  }}t          ||dz   | z             S )a   Generate a default filename with a given extension, attempting to use
    the filename of the currently running process, if possible.

    If the filename of the current process is not available (or would not be
    writable), then a temporary file with the given extension is returned.

    Args:
        ext (str) : the desired extension for the filename

    Returns:
        str

    Raises:
        RuntimeError
            If the extensions requested is ".py"

    pyz0asked for a default filename with 'py' extensionN.)RuntimeErrorr
   r   r   osgetcwd
_no_access_shares_exec_prefixr   r   r   )r   filenamebasedirname_s        -lib/python3.11/site-packages/bokeh/io/util.pyr	   r	   4   s    $ d{{MNNN&((HS!!!h.29;;G' "1':: "S!!!x))**GD!c)***    
str | Nonec                 &   ddl } d}|                                 }|t	 |j        rJ|j                            d          dk    r,|j        }|j        r|j                            d          dk    ,|j                            d          }~n# ~w xY w|S )z Attempt to return the filename of the currently running Python process

    Returns None if the filename cannot be detected.
    r   Nr   __main____file__)inspectcurrentframef_back	f_globalsget)r!   r   frames      r   r
   r
   V   s    
 NNNH  ""E	, %5?#6#6v#>#>*#L#L , %5?#6#6v#>#>*#L#L **:66HIIIIOs   A+B Bc                j    t          d| z             5 }|j        cddd           S # 1 swxY w Y   dS )zG Generate a temporary, writable filename with the given extension

    r   )suffixN)r   r   )r   fs     r   r   r   j   s     
39	-	-	- v                 s   (,,r   boolc                \    t          j        | t           j        t           j        z             S )zG Return True if the given base dir is not accessible or writeable

    )r   accessW_OKX_OK)r   s    r   r   r   w   s"     y"'BG"34444r   c                L    t           j        }|duo|                     |          S )zA Whether a give base directory is on the system exex prefix

    N)sysexec_prefix
startswith)r   prefixs     r   r   r   }   s)    
 F<'"4"4V"<"<<r   )r   r   r   r   )r   r   )r   r   r   r*   )__doc__
__future__r   logging	getLogger__name__logr   r0   os.pathr   r   r   r   tempfiler   __all__r	   r
   r   r   r    r   r   <module>r>      s    # " " " " " g!! 
			 



            ( ' ' ' ' ' +  +  +  +D   (   5 5 5 5= = = = = =r   