U
    /e                     @  s   d Z ddlmZ ddlZe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dd	d
ZddddZdddddZdddddZdddddZdS )z

    )annotationsN)basenamedirnamejoinsplitext)NamedTemporaryFile)default_filenamedetect_current_filenametemp_filenamestr)extreturnc                 C  sp   | dkrt dt }|dkr&t| S t|p4t }t|sFt|rNt| S tt	|\}}t
||d |  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_ r   1/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/io/util.pyr   4   s    r   z
str | None)r   c                  C  sT   ddl } d}|  }|dk	rPz.|jr<|jddkr<|j}q|jd}W 5 ~X |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   framer   r   r   r	   V   s    r	   c                 C  s   t d|  djS )zG Generate a temporary, writable filename with the given extension

    r   )suffix)r   r   )r   r   r   r   r
   j   s    r
   bool)r   r   c                 C  s   t | t jt jB  S )zG Return True if the given base dir is not accessible or writeable

    )r   accessW_OKX_OK)r   r   r   r   r   t   s    r   c                 C  s   t j}|dk	o| |S )zA Whether a give base directory is on the system exex prefix

    N)sysexec_prefix
startswith)r   prefixr   r   r   r   z   s    r   )__doc__
__future__r   logging	getLogger__name__logr   r(   os.pathr   r   r   r   tempfiler   __all__r   r	   r
   r   r   r   r   r   r   <module>   s   
"
