def _read_content_types_xml(fileobj): with open_zip(fileobj, "r") as zip_file: return xml.parse_xml( io.StringIO(zip_file.read_str("[Content_Types].xml")), [("ct", "http://schemas.openxmlformats.org/package/2006/content-types")], )
def _read_relationships_xml(fileobj): with open_zip(fileobj, "r") as zip_file: return xml.parse_xml( io.StringIO(zip_file.read_str("word/_rels/document.xml.rels")), [("r", "http://schemas.openxmlformats.org/package/2006/relationships")], )
def can_overwrite_existing_style_map(): fileobj = _normal_docx() write_style_map(fileobj, "p => h1") write_style_map(fileobj, "p => h2") with open_zip(fileobj, "r") as zip_file: assert_equal("p => h2", read_style_map(fileobj)) _assert_no_duplicates(zip_file._zip_file.namelist()) assert_equal(expected_relationships_xml, _read_relationships_xml(fileobj)) assert_equal(expected_content_types_xml, _read_content_types_xml(fileobj))
def _find_part_paths(self, fileobj): return docx._find_part_paths(zips.open_zip(fileobj, "r"))
def embedded_style_map_is_written_to_separate_file(): fileobj = _normal_docx() write_style_map(fileobj, "p => h1") with open_zip(fileobj, "r") as zip_file: assert_equal("p => h1", zip_file.read_str("mammoth/style-map"))
def writing_style_map_preserves_unrelated_files(): fileobj = _normal_docx() write_style_map(fileobj, "p => h1") with open_zip(fileobj, "r") as zip_file: assert_equal("placeholder", zip_file.read_str("placeholder"))