ó
mÜJ]c           @` s¼   d  Z  d d l m Z m Z m Z m Z d d l Z e j e ƒ Z	 d d l
 m Z d d l m Z m Z m Z m Z d d l m Z d Z d
 „  Z d „  Z d „  Z d „  Z d „  Z d S(   u   

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   getcwd(   t   dirnamet   basenamet   splitextt   join(   t   NamedTemporaryFileu   default_filenameu   detect_current_filenameu   temp_filenamec         C` sž   |  d k r t  d ƒ ‚ n  t ƒ  } | d k r: t |  ƒ St | ƒ pL t ƒ  } t | ƒ sg t | ƒ rq t |  ƒ St t	 | ƒ ƒ \ } } t
 | | d |  ƒ S(   uØ   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"

    u   pyu0   asked for a default filename with 'py' extensionu   .N(   t   RuntimeErrort   detect_current_filenamet   Nonet   temp_filenameR   R   t
   _no_accesst   _shares_exec_prefixR   R   R   (   t   extt   filenamet   basedirt   namet   _(    (    s,   lib/python2.7/site-packages/bokeh/io/util.pyt   default_filename2   s    	

c          C` sp   d d l  }  d } |  j ƒ  } zG x. | j rQ | j j d ƒ d k rQ | j } q$ W| j j d ƒ } Wd ~ X| S(   u‚    Attempt to return the filename of the currently running Python process

    Returns None if the filename cannot be detected.
    i    Nu   nameu   __main__u   __file__(   t   inspectR   t   currentframet   f_backt	   f_globalst   get(   R   R   t   frame(    (    s,   lib/python2.7/site-packages/bokeh/io/util.pyR   T   s    $c         C` s   t  d d |  ƒ j S(   uG    Generate a temporary, writable filename with the given extension

    t   suffixu   .(   R	   R   (   R   (    (    s,   lib/python2.7/site-packages/bokeh/io/util.pyR   g   s    c         C` s'   d d l  } | j |  | j | j Bƒ S(   uG    Return True if the given base dir is not accessible or writeable

    i    N(   t   ost   accesst   W_OKt   X_OK(   R   R   (    (    s,   lib/python2.7/site-packages/bokeh/io/util.pyR   q   s    c         C` s.   d d l  } | j } | d k	 o- |  j | ƒ S(   uA    Whether a give base directory is on the system exex prefix

    i    N(   t   syst   exec_prefixR   t
   startswith(   R   R!   t   prefix(    (    s,   lib/python2.7/site-packages/bokeh/io/util.pyR   x   s    	(   u   default_filenameu   detect_current_filenameu   temp_filename(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggert   __name__t   logR   R   t   os.pathR   R   R   R   t   tempfileR	   t   __all__R   R   R   R   R   (    (    (    s,   lib/python2.7/site-packages/bokeh/io/util.pyt   <module>	   s   ""  	"		
	