From 822d86b40c83dd9878ca3bd56e80d1a2305875d5 Mon Sep 17 00:00:00 2001 From: Glen Walker Date: Thu, 31 Jan 2019 12:25:36 +1300 Subject: [PATCH] Restore ability to use tempfile kwargs other than dir The changes in #38 broke the ability to use prefix, suffix and bufsize arguments when creating the tempfile. This commit restores the ability. --- atomicwrites/__init__.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/atomicwrites/__init__.py b/atomicwrites/__init__.py index 768e2ae..c2132d0 100644 --- a/atomicwrites/__init__.py +++ b/atomicwrites/__init__.py @@ -165,11 +165,13 @@ def _open(self, get_fileobject): except Exception: pass - def get_fileobject(self, dir=None, **kwargs): + def get_fileobject(self, suffix="", prefix=tempfile.template, dir=None, + **kwargs): '''Return the temporary file to use.''' if dir is None: dir = os.path.normpath(os.path.dirname(self._path)) - descriptor, name = tempfile.mkstemp(dir=dir) + descriptor, name = tempfile.mkstemp(suffix=suffix, prefix=prefix, + dir=dir) # io.open() will take either the descriptor or the name, but we need # the name later for commit()/replace_atomic() and couldn't find a way # to get the filename from the descriptor.