From 61cf58387f239633bf1b81f4e8252459152d2598 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 20 Jul 2015 18:57:46 +0100 Subject: Support linked images --- mammoth/docx/files.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 mammoth/docx/files.py (limited to 'mammoth/docx/files.py') diff --git a/mammoth/docx/files.py b/mammoth/docx/files.py new file mode 100644 index 0000000..d919de9 --- /dev/null +++ b/mammoth/docx/files.py @@ -0,0 +1,25 @@ +import os +import contextlib +try: + from urllib2 import urlopen +except ImportError: + from urllib.request import urlopen +try: + from urllib.parse import urlparse +except ImportError: + from urlparse import urlparse + + +class Files(object): + def __init__(self, base): + self._base = base + + def open(self, uri): + if _is_absolute(uri): + return contextlib.closing(urlopen(uri)) + else: + return open(os.path.join(self._base, uri), "rb") + + +def _is_absolute(url): + return urlparse(url).scheme != "" -- cgit v1.2.3