From 9c326a3db4c0bf50210fb7a4b8e9817d5d88e296 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Thu, 20 Aug 2015 20:41:28 +0100 Subject: Raise error if external image cannot be found --- mammoth/docx/files.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'mammoth') 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)) -- cgit v1.2.3