aboutsummaryrefslogtreecommitdiff
path: root/mammoth/docx/files.py
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2025-09-10 16:15:28 +0100
committerMichael Williamson <mike@zwobble.org>2025-09-10 16:15:28 +0100
commit150bf98e7ae2fd8ae874c3e756c39f01b3c01a23 (patch)
tree22844fd319ceba4c54d4e95ddb6246fd2e9b17d2 /mammoth/docx/files.py
parent603f8b83c0389be91ca90a3cb7690d7f237699d8 (diff)
Support disabling external file access
Diffstat (limited to 'mammoth/docx/files.py')
-rw-r--r--mammoth/docx/files.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/mammoth/docx/files.py b/mammoth/docx/files.py
index 61cf8d5..e26a43f 100644
--- a/mammoth/docx/files.py
+++ b/mammoth/docx/files.py
@@ -11,10 +11,16 @@ except ImportError:
class Files(object):
- def __init__(self, base):
+ def __init__(self, base, external_file_access):
self._base = base
-
+ self._external_file_access = external_file_access
+
def open(self, uri):
+ if not self._external_file_access:
+ raise ExternalFileAccessIsDisabledError(
+ "could not open external image '{0}', external file access is disabled".format(uri)
+ )
+
try:
if _is_absolute(uri):
return contextlib.closing(urlopen(uri))
@@ -34,3 +40,7 @@ def _is_absolute(url):
class InvalidFileReferenceError(ValueError):
pass
+
+
+class ExternalFileAccessIsDisabledError(InvalidFileReferenceError):
+ pass