From f9e169de5b83a487263c8970872f222401d66765 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Tue, 23 Jan 2018 21:32:52 +0000 Subject: Use word/document.xml as fallback --- mammoth/docx/__init__.py | 7 ++++--- tests/docx/docx_tests.py | 2 +- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/mammoth/docx/__init__.py b/mammoth/docx/__init__.py index c4c6877..326c85b 100644 --- a/mammoth/docx/__init__.py +++ b/mammoth/docx/__init__.py @@ -70,10 +70,11 @@ def _read_document(zip_file, body_readers, notes, comments): def _find_document_filename(zip_file, relationships): - targets = ["word/document.xml"] + [ + office_document_type = "http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" + targets = [ target.lstrip("/") - for target in relationships.find_targets_by_type("http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument") - ] + for target in relationships.find_targets_by_type(office_document_type) + ] + ["word/document.xml"] valid_targets = list(filter(lambda target: zip_file.exists(target), targets)) if len(valid_targets) == 0: return None diff --git a/tests/docx/docx_tests.py b/tests/docx/docx_tests.py index 9f2af01..8bd5b36 100644 --- a/tests/docx/docx_tests.py +++ b/tests/docx/docx_tests.py @@ -30,7 +30,7 @@ _relationship_namespaces = { @istest -def when_document_xml_is_not_present_then_document_is_found_using_file_relationships(): +def main_document_is_found_using_package_relationships(): fileobj = _create_zip({ "word/document2.xml": textwrap.dedent("""\ -- cgit v1.2.3