Rewrite error handling in get_document_content to use a with statement

instead of finally
 - Legacy-Id: 7837
This commit is contained in:
Ole Laursen 2014-06-03 10:42:33 +00:00
parent 88cf68d43f
commit 2a1f902a67

View file

@ -211,16 +211,13 @@ def add_links_in_new_revision_events(doc, events, diff_revisions):
def get_document_content(key, filename, split=True, markup=True):
f = None
try:
f = open(filename, 'rb')
raw_content = f.read()
except IOError:
with open(filename, 'rb') as f:
raw_content = f.read()
except IOError as e:
error = "Error; cannot read ("+key+")"
return error
finally:
if f:
f.close()
if markup:
return markup_txt.markup(raw_content, split)
else: