'</p:pic>' % (nsdecls('a', 'p', 'r'), '%d', '%s', '%s', '%s', '%d', '%d', '%d', '%d') ) @staticmethod def new_pic(id_, name, desc, rId, left, top, width, height): """ Return a new ``<p:pic>`` element tree configured with the supplied parameters. """ xml = CT_Picture._pic_tmpl % (id_, name, desc, rId, left, top, width, height) pic = parse_xml_bytes(xml) objectify.deannotate(pic, cleanup_namespaces=True) return pic @property def spPr(self): """ The required <a:spPr> child element, raises if not present. """ spPr = self.find(qn('p:spPr')) if spPr is None: # TODO: this should be ValidationError, not ValueError raise ValueError("pic element missing required spPr child") return spPr register_custom_element_class('p:pic', CT_Picture)
def it_determines_cust_elm_class_constructed_for_specified_tag( self, xml_bytes): register_custom_element_class('a:foo', CustElmCls) foo = objectify.fromstring(xml_bytes, oxml_parser) assert type(foo) is CustElmCls assert type(foo.bar) is objectify.StringElement
""" xml = CT_GraphicalObjectFrame._graphicFrame_tmpl % ( id_, name, left, top, width, height) graphicFrame = parse_xml_bytes(xml) objectify.deannotate(graphicFrame, cleanup_namespaces=True) return graphicFrame @staticmethod def new_table(id_, name, rows, cols, left, top, width, height): """ Return a ``<p:graphicFrame>`` element tree populated with a table element. """ graphicFrame = CT_GraphicalObjectFrame.new_graphicFrame( id_, name, left, top, width, height) # set type of contained graphic to table graphicData = graphicFrame[qn('a:graphic')].graphicData graphicData.set('uri', CT_GraphicalObjectFrame.DATATYPE_TABLE) # add tbl element tree tbl = CT_Table.new_tbl(rows, cols, width, height) graphicData.append(tbl) objectify.deannotate(graphicFrame, cleanup_namespaces=True) return graphicFrame register_custom_element_class('p:graphicFrame', CT_GraphicalObjectFrame)
# yyyy e.g. '2003' # yyyy-mm e.g. '2003-12' # yyyy-mm-dd e.g. '2003-12-31' # UTC timezone e.g. '2003-12-31T10:14:55Z' # numeric timezone e.g. '2003-12-31T10:14:55-08:00' templates = ( '%Y-%m-%dT%H:%M:%S', '%Y-%m-%d', '%Y-%m', '%Y', ) # strptime isn't smart enough to parse literal timezone offsets like # '-07:30', so we have to do it ourselves parseable_part = w3cdtf_str[:19] offset_str = w3cdtf_str[19:] dt = None for tmpl in templates: try: dt = datetime.strptime(parseable_part, tmpl) except ValueError: continue if dt is None: tmpl = "could not parse W3CDTF datetime string '%s'" raise ValueError(tmpl % w3cdtf_str) if len(offset_str) == 6: return cls._offset_dt(dt, offset_str) return dt register_custom_element_class('cp:coreProperties', CT_CoreProperties)
def it_determines_cust_elm_class_constructed_for_specified_tag(self, xml_bytes): register_custom_element_class("a:foo", CustElmCls) foo = objectify.fromstring(xml_bytes, oxml_parser) assert type(foo) is CustElmCls assert type(foo.bar) is objectify.StringElement