diff options
| author | Michael Williamson <mike@zwobble.org> | 2013-12-17 20:17:17 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2013-12-17 20:17:17 +0000 |
| commit | faae8466ac51b22a9b836103ce6e5c039dfc7eea (patch) | |
| tree | d746a9cf81abefc626c651756367c97dbbeb77bf /mammoth/docx/document_xml.py | |
| parent | a2d5ef8d5590bfb7d7b038d7753b8d8b2b013ecd (diff) | |
Add --output-dir option
Diffstat (limited to 'mammoth/docx/document_xml.py')
| -rw-r--r-- | mammoth/docx/document_xml.py | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/mammoth/docx/document_xml.py b/mammoth/docx/document_xml.py index fad4f87..14d36a6 100644 --- a/mammoth/docx/document_xml.py +++ b/mammoth/docx/document_xml.py @@ -1,4 +1,5 @@ import os +import contextlib from .. import documents from .. import results @@ -138,7 +139,11 @@ def _create_reader(numbering, content_types, relationships, docx_file): content_type = content_types.find_content_type(image_path) def open_image(): - return docx_file.open(image_path) + image_file = docx_file.open(image_path) + if hasattr(image_file, "__exit__"): + return image_file + else: + return contextlib.closing(image_file) image = documents.image(alt_text=alt_text, content_type=content_type, open=open_image) return results.success(image) |
