summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSylvain Thenault <sylvain.thenault@logilab.fr>2008-12-01 11:21:48 +0100
committerSylvain Thenault <sylvain.thenault@logilab.fr>2008-12-01 11:21:48 +0100
commitc7681e5cb0e59e9b5403037f90a2a94ae70f4e64 (patch)
treec738607ed88c75a9bdf4496c43a4b61ed368bfe0
parentc8521987eddacb2c40f28c7404df1e7182d160e6 (diff)
downloadlogilab-common-c7681e5cb0e59e9b5403037f90a2a94ae70f4e64.tar.gz
new module for context managers, keeping py <2.4 syntax compat for distribution
-rw-r--r--contexts.py20
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)
+