diff options
author | Sylvain Thenault <sylvain.thenault@logilab.fr> | 2008-12-01 11:21:48 +0100 |
---|---|---|
committer | Sylvain Thenault <sylvain.thenault@logilab.fr> | 2008-12-01 11:21:48 +0100 |
commit | c7681e5cb0e59e9b5403037f90a2a94ae70f4e64 (patch) | |
tree | c738607ed88c75a9bdf4496c43a4b61ed368bfe0 /contexts.py | |
parent | c8521987eddacb2c40f28c7404df1e7182d160e6 (diff) | |
download | logilab-common-c7681e5cb0e59e9b5403037f90a2a94ae70f4e64.tar.gz |
new module for context managers, keeping py <2.4 syntax compat for distribution
Diffstat (limited to 'contexts.py')
-rw-r--r-- | contexts.py | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/contexts.py b/contexts.py new file mode 100644 index 0000000..968c9be --- /dev/null +++ b/contexts.py @@ -0,0 +1,20 @@ +try: + from contextlib import contextmanager +except ImportError: + # py < 2.5 + pass +else: + + import tempfile + import shutil + + def tempdir(): + try: + path = tempfile.mkdtemp() + yield path + finally: + shutil.rmtree(path) + + # keep py < 2.4 syntax compat to avoid distribution pb + tempdir = contextmanager(tempdir) + |