ó
Ð4¹[c           @   sL   d  d l  Z  d  d l Z e  j d „  ƒ Z e  j e d „ ƒ Z d „  Z d S(   iÿÿÿÿNc         c   sZ   t  j j ƒ  } t  j j ƒ  t  j j |  ƒ z	 d VWd t  j j ƒ  t  j j | ƒ Xd S(   s²   Completely replace the environment variables with the specified dict.
    
    Use as a context manager::
    
        with temporary_env({'PATH': my_path}):
            ...
    N(   t   ost   environt   copyt   cleart   update(   t   newenvt   orig_env(    (    s+   lib/python2.7/site-packages/testpath/env.pyt   temporary_env   s    		c         c   s¨   d „  } | r! t  j j ƒ  } n< i  } x3 |  j ƒ  D]% \ } } t  j j | d ƒ | | <q4 W| |  ƒ z	 d VWd | r™ t  j j ƒ  t  j j | ƒ n
 | | ƒ Xd S(   s™  Temporarily modify environment variables.
    
    Specify the changes as a dictionary mapping names to new values, using
    None as the value for names that should be deleted.
    
    Example use::
    
        with modified_env({'SHELL': 'bash', 'PYTHONPATH': None}):
            ...
    
    When the context exits, there are two possible ways to restore the
    environment. If *snapshot* is True, the default, it will reset the whole
    environment to its state when the context was entered. If *snapshot* is
    False, it will restore only the specific variables it modified, leaving
    any changes made to other environment variables in the context.
    c         S   sP   xI |  j  ƒ  D]; \ } } | d  k r; t j j | d  ƒ q | t j | <q Wd  S(   N(   t   itemst   NoneR    R   t   pop(   t   changest   kt   v(    (    s+   lib/python2.7/site-packages/testpath/env.pyt
   update_del(   s    N(   R    R   R   R   t   getR	   R   R   (   R   t   snapshotR   t   saved_variablesR   R   (    (    s+   lib/python2.7/site-packages/testpath/env.pyt   modified_env   s    	
	c             s"   t  j j ƒ  ‰  ‡  f d †  }  |  S(   s…  Snapshot the current environment, return a function to restore that.

    This is intended to produce cleanup functions for tests. For example,
    using the :class:`unittest.TestCase` API::

        def setUp(self):
            self.addCleanup(testpath.make_env_restorer())

    Any changes a test makes to the environment variables will be wiped out
    before the next test is run.
    c              s!   t  j j ƒ  t  j j ˆ  ƒ d  S(   N(   R    R   R   R   (    (   R   (    s+   lib/python2.7/site-packages/testpath/env.pyt   restoreO   s    (   R    R   R   (   R   (    (   R   s+   lib/python2.7/site-packages/testpath/env.pyt   make_env_restorerA   s    (   t
   contextlibR    t   contextmanagerR   t   TrueR   R   (    (    (    s+   lib/python2.7/site-packages/testpath/env.pyt   <module>   s
   *