Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 # Copyright 2015 The Chromium Authors. All rights reserved. | |
|
rnephew (Wrong account)
2015/11/04 22:22:02
I like this. They have it as a context manager in
| |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 import contextlib | |
| 6 import tempfile | |
| 7 import shutil | |
| 8 | |
| 9 @contextlib.contextmanager | |
| 10 def TempDir(suffix='', prefix=''): | |
| 11 dirname = tempfile.mkdtemp(suffix=suffix, prefix=prefix) | |
| 12 try: | |
| 13 yield dirname | |
| 14 finally: | |
| 15 shutil.rmtree(dirname) | |
| OLD | NEW |