From c7681e5cb0e59e9b5403037f90a2a94ae70f4e64 Mon Sep 17 00:00:00 2001 From: Sylvain Thenault Date: Mon, 1 Dec 2008 11:21:48 +0100 Subject: new module for context managers, keeping py <2.4 syntax compat for distribution --- contexts.py | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 contexts.py 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) + -- cgit v1.2.1