def core_properties(self): element = parse_xml( b'<?xml version=\'1.0\' encoding=\'UTF-8\' standalone=\'yes\'?>' b'\n<cp:coreProperties xmlns:cp="http://schemas.openxmlformats.o' b'rg/package/2006/metadata/core-properties" xmlns:dc="http://pur' b'l.org/dc/elements/1.1/" xmlns:dcmitype="http://purl.org/dc/dcm' b'itype/" xmlns:dcterms="http://purl.org/dc/terms/" xmlns:xsi="h' b'ttp://www.w3.org/2001/XMLSchema-instance">\n' b' <cp:contentStatus>DRAFT</cp:contentStatus>\n' b' <dc:creator>python-docx</dc:creator>\n' b' <dcterms:created xsi:type="dcterms:W3CDTF">2012-11-17T11:07:' b'40-05:30</dcterms:created>\n' b' <dc:description/>\n' b' <dc:identifier>GXS 10.2.1ab</dc:identifier>\n' b' <dc:language>US-EN</dc:language>\n' b' <cp:lastPrinted>2014-06-04T04:28:00Z</cp:lastPrinted>\n' b' <cp:keywords>foo bar baz</cp:keywords>\n' b' <cp:lastModifiedBy>Steve Canny</cp:lastModifiedBy>\n' b' <cp:revision>4</cp:revision>\n' b' <dc:subject>Spam</dc:subject>\n' b' <dc:title>Word Document</dc:title>\n' b' <cp:version>1.2.88</cp:version>\n' b'</cp:coreProperties>\n' ) return CoreProperties(element)
def new(cls): """ Return a new ``<cp:coreProperties>`` element """ xml = cls._coreProperties_tmpl coreProperties = parse_xml(xml) return coreProperties
def add_column_fixture(self): snippets = snippet_seq('add-row-col') tbl = parse_xml(snippets[0]) table = Table(tbl, None) width = Inches(1.5) expected_xml = snippets[2] return table, width, expected_xml
def default(cls, package): """ Return a newly created styles part, containing a default set of elements. """ element = parse_xml(read_default_xml("styles.xml")) return cls.new(package, element)
def default(cls, package): """ Return a newly created styles part, containing a default set of elements. """ partname = PackURI('/word/footnotes.xml') content_type = CT.WML_FOOTNOTES element = parse_xml(cls._default_xml()) return cls(partname, content_type, element, package)
def new(cls, pic_id, filename, rId, cx, cy): """ Return a new ``<pic:pic>`` element populated with the minimal contents required to define a viable picture element, based on the values passed as parameters. """ pic = parse_xml(cls._pic_xml()) pic.nvPicPr.cNvPr.id = pic_id pic.nvPicPr.cNvPr.name = filename pic.blipFill.blip.embed = rId pic.spPr.cx = cx pic.spPr.cy = cy return pic
def new(cls, cx, cy, shape_id, pic): """ Return a new ``<wp:inline>`` element populated with the values passed as parameters. """ inline = parse_xml(cls._inline_xml()) inline.extent.cx = cx inline.extent.cy = cy inline.docPr.id = shape_id inline.docPr.name = 'Picture %d' % shape_id inline.graphic.graphicData.uri = ( 'http://schemas.openxmlformats.org/drawingml/2006/picture') inline.graphic.graphicData._insert_pic(pic) return inline
def _copy_rels(src, dest): for srcrel in src.rels.values(): if srcrel.is_external: continue srcpart = srcrel.target_part if hasattr(srcpart, "_element"): element = parse_xml(srcpart._element.xml) else: element = srcpart.blob newpart = type(srcpart)(srcpart.partname, srcpart.content_type, element, destpackage) # 名前はaddだが内部では代入している dest.rels.add_relationship(srcrel.reltype, newpart, srcrel.rId, srcrel.is_external) if not srcrel.is_external: _copy_rels(srcrel.target_part, newpart)
def it_accepts_unicode_providing_there_is_no_encoding_declaration(self): non_enc_decl = '<?xml version="1.0" standalone="yes"?>' enc_decl = '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' xml_body = '<foo><bar>føøbår</bar></foo>' # unicode body by itself doesn't raise parse_xml(xml_body) # adding XML decl without encoding attr doesn't raise either xml_text = '%s\n%s' % (non_enc_decl, xml_body) parse_xml(xml_text) # but adding encoding in the declaration raises ValueError xml_text = '%s\n%s' % (enc_decl, xml_body) with pytest.raises(ValueError): parse_xml(xml_text)
def revision_set_fixture(self, request): value, str_val = request.param coreProperties = self.coreProperties(None, None) core_properties = CoreProperties(parse_xml(coreProperties)) expected_xml = self.coreProperties('cp:revision', str_val) return core_properties, value, expected_xml
def revision_get_fixture(self, request): str_val, expected_revision = request.param tagname = '' if str_val is None else 'cp:revision' coreProperties = self.coreProperties(tagname, str_val) core_properties = CoreProperties(parse_xml(coreProperties)) return core_properties, expected_revision
def date_prop_set_fixture(self, request): prop_name, tagname, value, str_val, attrs = request.param coreProperties = self.coreProperties(None, None) core_properties = CoreProperties(parse_xml(coreProperties)) expected_xml = self.coreProperties(tagname, str_val, attrs) return core_properties, prop_name, value, expected_xml
def add_row_fixture(self): snippets = snippet_seq('add-row-col') tbl = parse_xml(snippets[0]) table = Table(tbl, None) expected_xml = snippets[1] return table, expected_xml
def new(cls): """ Return a new ``<w:tc>`` element, containing an empty paragraph as the required EG_BlockLevelElt. """ return parse_xml('<w:tc %s>\n' ' <w:p/>\n' '</w:tc>' % nsdecls('w'))
def new_tbl(cls, rows, cols, width): """ Return a new `w:tbl` element having *rows* rows and *cols* columns with *width* distributed evenly between the columns. """ return parse_xml(cls._tbl_xml(rows, cols, width))
def cells_fixture(self, request): snippet_idx, cell_count, unique_count, matches = request.param tbl_xml = snippet_seq('tbl-cells')[snippet_idx] table = Table(parse_xml(tbl_xml), None) return table, cell_count, unique_count, matches
def element(cxel_str): """ Return an oxml element parsed from the XML generated from *cxel_str*. """ _xml = xml(cxel_str) return parse_xml(_xml)
def tc_raise_fixture(self, request): snippet_idx, row_idx, col_idx = request.param tbl = parse_xml(snippet_seq('tbl-cells')[snippet_idx]) tr = tbl.tr_lst[row_idx] return tr, col_idx
def _snippet_tbl(self, idx): """ Return a <w:tbl> element for snippet at *idx* in 'tbl-cells' snippet file. """ return parse_xml(snippet_seq('tbl-cells')[idx])
def new(cls, package): """Return newly created header part.""" partname = package.next_partname("/word/header%d.xml") content_type = CT.WML_HEADER element = parse_xml(cls._default_header_xml()) return cls(partname, content_type, element, package)
def it_accepts_bytes_and_assumes_utf8_encoding(self, xml_bytes): parse_xml(xml_bytes)
def load(cls, partname, content_type, blob, package): element = parse_xml(blob) return cls(partname, content_type, element, package)
def it_determines_class_used_for_elements_with_matching_tagname( self, xml_text): register_element_cls('a:foo', CustElmCls) foo = parse_xml(xml_text) assert type(foo) is CustElmCls assert type(foo.find(qn('a:bar'))) is etree._Element
def it_uses_registered_element_classes(self, xml_bytes): register_element_cls('a:foo', CustElmCls) element = parse_xml(xml_bytes) assert isinstance(element, CustElmCls)
def element(self): return parse_xml('<foø><bår>text</bår></foø>')
def _new_color(self): """ Override metaclass method to set `w:color/@val` to RGB black on create. """ return parse_xml('<w:color %s w:val="000000"/>' % nsdecls('w'))