def it_can_generate_rels_file_xml(self): expected_xml = ( "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n" '<Relationships xmlns="http://schemas.openxmlformats.org/package' '/2006/relationships"/>'.encode("utf-8") ) assert CT_Relationships.new().xml == expected_xml
def it_can_construct_a_new_relationships_element(self): rels = CT_Relationships.new() expected_xml = ( '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n' '<Relationships xmlns="http://schemas.openxmlformats.org/package' '/2006/relationships"/>') assert rels.xml.decode('utf-8') == expected_xml
def it_can_generate_rels_file_xml(self): expected_xml = ( '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n' '<Relationships xmlns="http://schemas.openxmlformats.org/package' '/2006/relationships"/>'.encode('utf-8') ) assert CT_Relationships.new().xml == expected_xml
def it_can_construct_a_new_relationships_element(self): rels = CT_Relationships.new() expected_xml = ( "<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\n" '<Relationships xmlns="http://schemas.openxmlformats.org/package' '/2006/relationships"/>' ) assert rels.xml.decode("utf-8") == expected_xml
def it_can_construct_a_new_relationships_element(self): rels = CT_Relationships.new() expected_xml = ( '<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>\n' '<Relationships xmlns="http://schemas.openxmlformats.org/package' '/2006/relationships"/>' ) assert rels.xml == expected_xml
def it_can_construct_a_new_relationships_element(self): rels = CT_Relationships.new() actual_xml = oxml_tostring(rels, encoding='unicode', pretty_print=True) expected_xml = ( '<Relationships xmlns="http://schemas.openxmlformats.org/package' '/2006/relationships"/>\n' ) assert actual_xml == expected_xml
def xml(self): """ Serialize this relationship collection into XML suitable for storage as a .rels file in an OPC package. """ rels_elm = CT_Relationships.new() for rel in self.values(): rels_elm.add_rel(rel.rId, rel.reltype, rel.target_ref, rel.is_external) return rels_elm.xml
def _xml_rels_for(self, partname): """Return CT_Relationships object formed by parsing rels XML for `partname`. A CT_Relationships object is returned in all cases. A part that has no relationships receives an "empty" CT_Relationships object, i.e. containing no `CT_Relationship` objects. """ rels_xml = self._package_reader.rels_xml_for(partname) return CT_Relationships.new() if rels_xml is None else parse_xml( rels_xml)
def it_can_build_rels_element_incrementally(self): # setup ------------------------ rels = CT_Relationships.new() # exercise --------------------- rels.add_rel("rId1", "http://reltype1", "docProps/core.xml") rels.add_rel("rId2", "http://linktype", "http://some/link", True) rels.add_rel("rId3", "http://reltype2", "../slides/slide1.xml") # verify ----------------------- expected_rels_xml = a_Relationships().xml actual_xml = oxml_tostring(rels, encoding="unicode", pretty_print=True) assert actual_xml == expected_rels_xml
def xml(self): """bytes XML serialization of this relationship collection. This value is suitable for storage as a .rels file in an OPC package. Includes a `<?xml` header with encoding as UTF-8. """ rels_elm = CT_Relationships.new() for rel in self: rels_elm.add_rel(rel.rId, rel.reltype, rel.target_ref, rel.is_external) return rels_elm.xml
def it_can_build_rels_element_incrementally(self): # setup ------------------------ rels = CT_Relationships.new() # exercise --------------------- rels.add_rel('rId1', 'http://reltype1', 'docProps/core.xml') rels.add_rel('rId2', 'http://linktype', 'http://some/link', True) rels.add_rel('rId3', 'http://reltype2', '../slides/slide1.xml') # verify ----------------------- expected_rels_xml = a_Relationships().xml actual_xml = oxml_tostring(rels, encoding='unicode', pretty_print=True) assert actual_xml == expected_rels_xml