From faae8466ac51b22a9b836103ce6e5c039dfc7eea Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 17 Dec 2013 20:17:17 +0000 Subject: Add --output-dir option --- mammoth/docx/document_xml.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'mammoth/docx/document_xml.py') 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) -- cgit v1.2.3