aboutsummaryrefslogtreecommitdiff
path: root/mammoth/docx/files.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2015-08-20 20:34:34 +0100
committerMichael Williamson <mike@zwobble.org>2015-08-20 20:35:14 +0100
commit1c14ed25d75caf3228a92d8f7292bf0bf040653b (patch)
treeaa36f672e71baebf7b870a8be609d1990dd450e3 /mammoth/docx/files.py
parent06ac97ac681accc691affdfafec97ded54faba23 (diff)
Fix: cannot read file objects with name attribute
Diffstat (limited to 'mammoth/docx/files.py')
-rw-r--r--mammoth/docx/files.py12
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