summaryrefslogtreecommitdiff
path: root/contexts.py
blob: 968c9be00996558dbe9553a1ad99ac5973eadd38 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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)