diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-08-20 20:41:28 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-08-20 20:41:28 +0100 |
| commit | 9c326a3db4c0bf50210fb7a4b8e9817d5d88e296 (patch) | |
| tree | 62edfd648a63a5945d75ffa4318ba9640c4cc206 /mammoth | |
| parent | 1c14ed25d75caf3228a92d8f7292bf0bf040653b (diff) | |
Raise error if external image cannot be found
Diffstat (limited to 'mammoth')
| -rw-r--r-- | mammoth/docx/files.py | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/mammoth/docx/files.py b/mammoth/docx/files.py index 7fe3a2c..ce557f6 100644 --- a/mammoth/docx/files.py +++ b/mammoth/docx/files.py @@ -22,7 +22,10 @@ class Files(object): if _is_absolute(uri): return contextlib.closing(urlopen(uri)) elif self._base is not None: - return open(os.path.join(self._base, uri), "rb") + path = os.path.join(self._base, uri) + if not os.path.exists(path): + raise InvalidFileReferenceError("could not find external image '{0}' from document directory '{1}'".format(uri, self._base)) + return open(path, "rb") else: raise InvalidFileReferenceError("could not find external image '{0}', fileobj has no name".format(uri)) |
