Skip to content
This repository has been archived by the owner on Dec 12, 2017. It is now read-only.

Commit

Permalink
Add missing file
Browse files Browse the repository at this point in the history
  • Loading branch information
desbma committed Dec 12, 2015
1 parent ddba62b commit dd1f54f
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions canalplus/mkstemp_ctx.py
@@ -0,0 +1,21 @@
import contextlib
import os
import tempfile


@contextlib.contextmanager
def mkstemp(*args, **kwargs):
"""
Context manager similar to tempfile.NamedTemporaryFile except the file is not deleted on close, and only the filepath
is returned
.. warnings:: Unlike tempfile.mkstemp, this is not secure
"""
fd, filename = tempfile.mkstemp(*args, **kwargs)
os.close(fd)
try:
yield filename
finally:
try:
os.remove(filename)
except FileNotFoundError:
pass

0 comments on commit dd1f54f

Please sign in to comment.