diff options
| author | 2018-04-03 06:50:04 +0200 | |
|---|---|---|
| committer | 2018-04-03 06:50:04 +0200 | |
| commit | dc580be8f9ef38a1c0903820b04e1b5c7217da16 (patch) | |
| tree | 4a214d88d3e094efdb9e4ff70920537a4d33ae9b /minidinstall/SafeWriteFile.py | |
| parent | 23ac25c0b388b5ffebf66154b12a3950b89b977a (diff) | |
Various improvements in coding style.
Diffstat (limited to 'minidinstall/SafeWriteFile.py')
| -rwxr-xr-x | minidinstall/SafeWriteFile.py | 12 |
1 files changed, 5 insertions, 7 deletions
diff --git a/minidinstall/SafeWriteFile.py b/minidinstall/SafeWriteFile.py index 591c4f0..38262f2 100755 --- a/minidinstall/SafeWriteFile.py +++ b/minidinstall/SafeWriteFile.py @@ -1,11 +1,12 @@ -# SafeWriteFile.py +#!/usr/bin/python3 +# SafeWriteFile -*- mode: python; coding: utf-8 -*- # # This file is a writable file object. It writes to a specified newname, # and when closed, renames the file to the realname. If the object is # deleted, without being closed, this rename isn't done. If abort() is # called, it also disables the rename. # -# Copyright 2001 Adam Heath <doogie@debian.org> +# Copyright (c) 2001 Adam Heath <doogie@debian.org> # # This file is free software; you can redistribute it and/or modify it # under the terms of the GNU General Public License as published by @@ -27,11 +28,9 @@ from os import rename class ObjectNotAllowed(Exception): pass - class InvalidMode(Exception): pass - class SafeWriteFile: def __init__(self, newname, realname, mode="w", bufsize=-1): @@ -47,7 +46,7 @@ class SafeWriteFile: self.fobj=open(newname, mode, bufsize) self.newname=newname self.realname=realname - self.__abort=0 + self.__abort=False def close(self): self.fobj.close() @@ -55,7 +54,7 @@ class SafeWriteFile: rename(self.newname, self.realname) def abort(self): - self.__abort=1 + self.__abort=True def __del__(self): self.abort() @@ -67,7 +66,6 @@ class SafeWriteFile: except: return eval("self.fobj." + attr) - if __name__ == "__main__": import time f=SafeWriteFile("sf.new", "sf.data") |
