diff options
author | Devan Franchini <twitch153@gentoo.org> | 2014-06-12 17:17:02 -0400 |
---|---|---|
committer | Devan Franchini <twitch153@gentoo.org> | 2014-06-14 20:36:41 -0400 |
commit | b47238ef6ef407c7c07a94b885b7243a089c797f (patch) | |
tree | 7209618637f240494551b15bba63f8fcfd0037d6 /layman/dbbase.py | |
parent | mercurial.py: Adds module branch support (diff) | |
download | layman-b47238ef6ef407c7c07a94b885b7243a089c797f.tar.gz layman-b47238ef6ef407c7c07a94b885b7243a089c797f.tar.bz2 layman-b47238ef6ef407c7c07a94b885b7243a089c797f.zip |
Implements the "with" syntax to open files
Diffstat (limited to 'layman/dbbase.py')
-rw-r--r-- | layman/dbbase.py | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/layman/dbbase.py b/layman/dbbase.py index 92d5cf9..e17e8f3 100644 --- a/layman/dbbase.py +++ b/layman/dbbase.py @@ -131,8 +131,8 @@ class DbBase(object): '''Read the overlay definition file.''' try: - df = fileopen(path, 'r') - document = df.read() + with fileopen(path, 'r') as df: + document = df.read() except Exception as error: if not self.ignore_init_read_errors: @@ -235,9 +235,9 @@ class DbBase(object): indent(tree) tree = ET.ElementTree(tree) try: - f = fileopen(path, 'w') - tree.write(f, encoding=_UNICODE) - f.close() + with fileopen(path, 'w') as f: + tree.write(f, encoding=_UNICODE) + except Exception as error: raise Exception('Failed to write to local overlays file: ' + path + '\nError was:\n' + str(error)) |