diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-09-06 18:08:58 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-09-06 18:08:58 +0100 |
| commit | 256806a3dd10ccdfb1295181d09af7655c05fa29 (patch) | |
| tree | 682532ac1eaf1718c03430e5b61e20dfe6b03d7d /mammoth | |
| parent | cff7a81ce9c49971ca94fc8fe74430338e563836 (diff) | |
Capture errors on trying to open file URIs
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/docx/files.py | 20 |
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): |
