diff options
Diffstat (limited to 'mammoth/docx/files.py')
| -rw-r--r-- | mammoth/docx/files.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/mammoth/docx/files.py b/mammoth/docx/files.py index d919de9..7fe3a2c 100644 --- a/mammoth/docx/files.py +++ b/mammoth/docx/files.py @@ -14,12 +14,22 @@ class Files(object): def __init__(self, base): self._base = base + def verify(self, uri): + with self.open(uri): + pass + def open(self, uri): if _is_absolute(uri): return contextlib.closing(urlopen(uri)) - else: + elif self._base is not None: return open(os.path.join(self._base, uri), "rb") + else: + raise InvalidFileReferenceError("could not find external image '{0}', fileobj has no name".format(uri)) def _is_absolute(url): return urlparse(url).scheme != "" + + +class InvalidFileReferenceError(ValueError): + pass |
