MCPcopy Create free account
hub / github.com/scanny/python-pptx / element_defs

Function element_defs

lab/parse_xsd/parse_xsd.py:339–375  ·  view source on GitHub ↗
(tags)

Source from the content-addressed store, hash-verified

337
338
339def element_defs(tags):
340 def _padding(type, element):
341 return ' ' * (type.max_tagname_len - len(element.name))
342
343 s = ''
344 for tag in tags:
345 element = tg.elements[tag]
346 # no def needed for built-in types
347 if element.typename in ('xsd:string'):
348 continue
349 try:
350 type = tg.types[element.typename]
351 except KeyError:
352 continue
353
354 # e.g. blipFill = ElementDef('p:blipFill', 'CT_BlipFillProperties')
355 s += ("\n%s = ElementDef('%s', '%s')\n" %
356 (element.name, element.tag, element.typename))
357
358 # e.g. blipFill.add_child('a:blip', cardinality='?')
359 for child in type.elements:
360 s += ("%s.add_child('%s'%s, cardinality='%s')\n" %
361 (element.name, child.tag, _padding(type, child),
362 child.cardinality))
363
364 # e.g. ext.add_attribute('x', required=True, default="0")
365 for a in type.required_attributes:
366 default = a.default if a.default else ''
367 s += ("%s.add_attribute('%s', required=True, default='%s')\n" %
368 (element.name, a.name, default))
369
370 # e.g. xfrm.add_attributes('rot', 'flipH', 'flipV')
371 if type.optional_attributes:
372 params = "', '".join([a.name for a in type.optional_attributes])
373 s += "%s.add_attributes('%s')\n" % (element.name, params)
374
375 return s
376
377
378# ============================================================================

Callers 1

parse_xsd.pyFile · 0.85

Calls 1

_paddingFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…