Use NamedTemporaryFile(delete=False) instead of mkstemp

This commit is contained in:
Laurent Bachelier 2013-07-27 15:42:23 +02:00
commit fd5901b00e
2 changed files with 4 additions and 8 deletions

View file

@ -18,8 +18,6 @@
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
import os
import tempfile
import logging
@ -60,10 +58,9 @@ class YamlConfig(IConfig):
def save(self):
# write in a temporary file to avoid corruption problems
fd, path = tempfile.mkstemp(dir=os.path.dirname(self.path))
with os.fdopen(fd, 'w') as f:
with tempfile.NamedTemporaryFile(dir=os.path.dirname(self.path), delete=False) as f:
yaml.dump(self.values, f, Dumper=Dumper)
os.rename(path, self.path)
os.rename(f.name, self.path)
def get(self, *args, **kwargs):
default = None