@contextlib.contextmanager<EOL>def temp_cwd(name='<STR_LIT>', quiet=False, path=None):
saved_dir = os.getcwd()<EOL>is_temporary = False<EOL>if path is None:<EOL><INDENT>path = name<EOL>try:<EOL><INDENT>os.mkdir(name)<EOL>is_temporary = True<EOL><DEDENT>except OSError:<EOL><INDENT>if not quiet:<EOL><INDENT>raise<EOL><DEDENT>warnings.warn('<STR_LIT>' + name,<EOL>RuntimeWarning, stacklevel=<NUM_LIT:3>)<EOL><DEDENT><DEDENT>try:<EOL><INDENT>os.chdir(path)<EOL><DEDENT>except OSError:<EOL><INDENT>if not quiet:<EOL><INDENT>raise<EOL><DEDENT>warnings.warn('<STR_LIT>' + name,<EOL>RuntimeWarning, stacklevel=<NUM_LIT:3>)<EOL><DEDENT>try:<EOL><INDENT>yield os.getcwd()<EOL><DEDENT>finally:<EOL><INDENT>os.chdir(saved_dir)<EOL>if is_temporary:<EOL><INDENT>rmtree(name)<EOL><DEDENT><DEDENT>
Context manager that temporarily changes the CWD.

An existing path may be provided as *path*, in which case this
function makes no changes to the file system.

Otherwise, the new CWD is created in the current directory and it's
named *name*. If *quiet* is False (default) and it's not possible to
create or change the CWD, an error is raised.  If it's True, only a
warning is raised and the original CWD is used.