aboutsummaryrefslogtreecommitdiff
path: root/mammoth
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-09-06 18:08:58 +0100
committerMichael Williamson <mike@zwobble.org>2015-09-06 18:08:58 +0100
commit256806a3dd10ccdfb1295181d09af7655c05fa29 (patch)
tree682532ac1eaf1718c03430e5b61e20dfe6b03d7d /mammoth
parentcff7a81ce9c49971ca94fc8fe74430338e563836 (diff)
Capture errors on trying to open file URIs
Diffstat (limited to 'mammoth')
-rw-r--r--mammoth/docx/files.py20
1 files changed, 10 insertions, 10 deletions
diff --git a/mammoth/docx/files.py b/mammoth/docx/files.py
index bde488d..dc5146e 100644
--- a/mammoth/docx/files.py
+++ b/mammoth/docx/files.py
@@ -19,17 +19,17 @@ class Files(object):
pass
def open(self, uri):
- if _is_absolute(uri):
- return contextlib.closing(urlopen(uri))
- elif self._base is not None:
- try:
+ try:
+ if _is_absolute(uri):
+ return contextlib.closing(urlopen(uri))
+ elif self._base is not None:
return open(os.path.join(self._base, uri), "rb")
- except IOError as error:
- message = "could not open external image '{0}' from document directory '{1}'\n{2}".format(
- uri, self._base, str(error))
- raise InvalidFileReferenceError(message)
- else:
- raise InvalidFileReferenceError("could not find external image '{0}', fileobj has no name".format(uri))
+ else:
+ raise InvalidFileReferenceError("could not find external image '{0}', fileobj has no name".format(uri))
+ except IOError as error:
+ message = "could not open external image: '{0}' (document directory: '{1}')\n{2}".format(
+ uri, self._base, str(error))
+ raise InvalidFileReferenceError(message)
def _is_absolute(url):