From dc580be8f9ef38a1c0903820b04e1b5c7217da16 Mon Sep 17 00:00:00 2001 From: Krytarik Raido Date: Tue, 3 Apr 2018 06:50:04 +0200 Subject: Various improvements in coding style. --- minidinstall/SafeWriteFile.py | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'minidinstall/SafeWriteFile.py') 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 +# Copyright (c) 2001 Adam Heath # # 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") -- cgit v1.2.3