Example #1
0
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")],
        )
Example #2
0
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))
Example #4
0
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))
Example #5
0
 def _find_part_paths(self, fileobj):
     return docx._find_part_paths(zips.open_zip(fileobj, "r"))
Example #6
0
 def _find_part_paths(self, fileobj):
     return docx._find_part_paths(zips.open_zip(fileobj, "r"))
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 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"))
Example #11
0
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"))
Example #12
0
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"))