diff options
Diffstat (limited to 'engine/SCons/dblite.py')
-rw-r--r-- | engine/SCons/dblite.py | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/engine/SCons/dblite.py b/engine/SCons/dblite.py index 87a1763..14bd93d 100644 --- a/engine/SCons/dblite.py +++ b/engine/SCons/dblite.py @@ -75,7 +75,8 @@ class dblite(object): def __init__(self, file_base_name, flag, mode): assert flag in (None, "r", "w", "c", "n") - if (flag is None): flag = "r" + if flag is None: + flag = "r" base, ext = os.path.splitext(file_base_name) if ext == dblite_suffix: @@ -106,17 +107,20 @@ class dblite(object): self._chown_to = -1 # don't chown self._chgrp_to = -1 # don't chgrp - if (self._flag == "n"): - self._open(self._file_name, "wb", self._mode) + if self._flag == "n": + with self._open(self._file_name, "wb", self._mode): + pass # just make sure it exists else: try: f = self._open(self._file_name, "rb") except IOError as e: - if (self._flag != "c"): + if self._flag != "c": raise e - self._open(self._file_name, "wb", self._mode) + with self._open(self._file_name, "wb", self._mode): + pass # just make sure it exists else: p = f.read() + f.close() if len(p) > 0: try: if bytes is not str: @@ -132,7 +136,7 @@ class dblite(object): corruption_warning(self._file_name) def close(self): - if (self._needs_sync): + if self._needs_sync: self.sync() def __del__(self): |