diff options
| author | 2018-03-14 02:56:04 +0100 | |
|---|---|---|
| committer | 2018-03-14 20:23:00 -0400 | |
| commit | 23ac25c0b388b5ffebf66154b12a3950b89b977a (patch) | |
| tree | 27ae214e393e6be2efc225d02ffc93135aaa2eb5 /minidinstall/SafeWriteFile.py | |
| parent | 9883708468224628f9e0e577162fb5345fe20eb4 (diff) | |
Port to Python 3
Diffstat (limited to 'minidinstall/SafeWriteFile.py')
| -rwxr-xr-x | minidinstall/SafeWriteFile.py | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/minidinstall/SafeWriteFile.py b/minidinstall/SafeWriteFile.py index 1777d36..591c4f0 100755 --- a/minidinstall/SafeWriteFile.py +++ b/minidinstall/SafeWriteFile.py @@ -21,9 +21,7 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -from types import StringType from shutil import copy2 -from string import find from os import rename class ObjectNotAllowed(Exception): @@ -37,14 +35,14 @@ class InvalidMode(Exception): class SafeWriteFile: def __init__(self, newname, realname, mode="w", bufsize=-1): - if type(newname)!=StringType: + if not isinstance(newname, str): raise ObjectNotAllowed(newname) - if type(realname)!=StringType: + if not isinstance(realname, str): raise ObjectNotAllowed(realname) - if find(mode, "r")>=0: + if "r" in mode: raise InvalidMode(mode) - if find(mode, "a")>=0 or find(mode, "+") >= 0: + if "a" in mode or "+" in mode: copy2(realname, newname) self.fobj=open(newname, mode, bufsize) self.newname=newname |
