<s> '''<STR_LIT>''' <EOL> from __future__ import division , print_function , absolute_import <EOL> import os <EOL> from contextlib import contextmanager <EOL> from shutil import rmtree <EOL> from tempfile import mkdtemp <EOL> @ contextmanager <EOL> def tempdir ( ) : <EOL> """<STR_LIT>""" <EOL> d = mkdtemp ( ) <EOL> yield d <EOL> rmtree ( d ) <EOL> @ contextmanager <EOL> def in_tempdir ( ) : <EOL> '''<STR_LIT>''' <EOL> pwd = os . getcwd ( ) <EOL> d = mkdtemp ( ) <EOL> os . chdir ( d ) <EOL> yield d <EOL> os . chdir ( pwd ) <EOL> rmtree ( d ) <EOL> @ contextmanager <EOL> def in_dir ( dir = None ) : <EOL> """<STR_LIT>""" <EOL> cwd = os . getcwd ( ) <EOL> if dir is None : <EOL> yield cwd <EOL> return <EOL> os . chdir ( dir ) <EOL> yield dir <EOL> os . chdir ( cwd ) </s>
