diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-07-20 18:57:46 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-07-20 18:58:15 +0100 |
| commit | 61cf58387f239633bf1b81f4e8252459152d2598 (patch) | |
| tree | 99aaf0469c35a330a973618dc5f7cb176cb14e18 /mammoth/docx/files.py | |
| parent | 3d20b52a4105d48e319493adf2481cdb5985f72d (diff) | |
Support linked images
Diffstat (limited to 'mammoth/docx/files.py')
| -rw-r--r-- | mammoth/docx/files.py | 25 |
1 files changed, 25 insertions, 0 deletions
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 != "" |
