ó
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
 Z
 d d l Z d d l Z d d l Z d d l Z d d l Z d Z d	 „  Z d
 e f d „  ƒ  YZ d „  Z d d „ Z d d „ Z d e f d „  ƒ  YZ e j j d ƒ Z e e ƒ d S(   uE    Provide functions for manipulating files and directories in tests.

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsNu   makedirs_ok_if_existsu   TmpDiru   with_directory_contentsu   with_temporary_fileu
   WorkingDirc         C` ss   y t  j |  ƒ Wn[ t k
 rA } | j t j k ro | ‚ qo n. t k
 rn } | j t j k ro | ‚ qo n X|  S(   u   

    (   t   ost   makedirst   IOErrort   errnot   EEXISTt   OSError(   t   patht   e(    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyt   makedirs_ok_if_exists3   s    t   TmpDirc           B` s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   u   

    c         C` s   t  j d | d t ƒ |  _ d  S(   Nt   prefixt   dir(   t   tempfilet   mkdtempt
   _LOCAL_TMPt   _dir(   t   selfR   (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyt   __init__E   s    c         C` s˜   y t  j d |  j ƒ Wnz t k
 r“ } | d  k rd t d |  j t | ƒ f d t j ƒ| ‚ q” t d |  j t | ƒ f d t j ƒ| ‚ n Xd  S(   NR
   u#   Exception cleaning up TmpDir %s: %st   fileu    Failed to clean up TmpDir %s: %s(	   t   shutilt   rmtreeR   t	   Exceptiont   Nonet   printt   strt   syst   stderr(   R   t   typet   valuet	   tracebackR   (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyt   __exit__H   s    &	&c         C` s   |  j  S(   N(   R   (   R   (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyt	   __enter__T   s    (   t   __name__t
   __module__t   __doc__R   R"   R#   (    (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyR   A   s   		c         C` s¾   t  d d ƒ © } x‰ |  j ƒ  D]{ \ } } t j j | | ƒ } | d k rY t | ƒ q t t j j | ƒ ƒ t j	 | d d ƒ  } | j
 | ƒ Wd QXq W| t j j | ƒ ƒ SWd QXd S(   u   

    R   u   test-u   wu   utf-8N(   R   t   itemsR   R
   t   joinR   R   t   dirnamet   codecst   opent   writet   realpath(   t   contentst   funcR)   t   filenamet   file_contentR
   t   f(    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyt   with_directory_contentsW   s    c         ` s&   ‡  ‡ f d †  } t  | d | ƒd S(   u   

    c         ` s;   |  j  ˆ  j d ƒ ƒ |  j ƒ  |  j ƒ  ˆ |  j ƒ d  S(   Nu   UTF-8(   R,   t   encodet   flusht   closet   name(   R2   (   R.   R/   (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyt   with_file_objectk   s    

R   N(   t   with_temporary_file(   R.   R/   R   R8   (    (   R.   R/   s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyt   with_file_contentsg   s    c         C` si   | d k r t } n  d d l } | j d | d t ƒ } z |  | ƒ Wd | j ƒ  t j | j ƒ Xd S(   u   

    i    NR   t   delete(	   R   R   R   t   NamedTemporaryFilet   FalseR6   R   t   removeR7   (   R/   R   R   R2   (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyR9   u   s    	
t
   WorkingDirc           B` s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   u   

    c         C` s   | |  _  t j ƒ  |  _ d  S(   N(   t   _newR   t   getcwdt   _old(   R   t   pwd(    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyR   ‹   s    	c         C` s   t  j |  j ƒ d  S(   N(   R   t   chdirRB   (   R   R   R    R!   (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyR"      s    c         C` s   t  j |  j ƒ |  j S(   N(   R   RD   R@   (   R   (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyR#   ’   s    (   R$   R%   R&   R   R"   R#   (    (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyR?   ‡   s   		u   ./build/tmp(   u   makedirs_ok_if_existsu   TmpDiru   with_directory_contentsu   with_temporary_fileu
   WorkingDir(   R&   t
   __future__R    R   R   R   t   loggingt	   getLoggerR$   t   logR*   R   R   R   R   R   t   __all__R   t   objectR   R3   R   R:   R9   R?   R
   t   abspathR   (    (    (    s=   lib/python2.7/site-packages/bokeh/_testing/util/filesystem.pyt   <module>	   s,   "    		