def _xml(self):
"""
Helper for xml generation. Returns separately:
- the component attributes
- the generated xml of the inner components
Component attributes start with an underscore ('_') and
do not have a False or None value. The underscore is removed.
A value of True is replaced with the attribute name.
Returns:
tuple: (attributes, components)
"""
# get the attributes for this component
# (they start with '_', others may have special meanings)
attr = []
for key, value in self.attributes.iteritems():
if key[:1] != '_':
continue
name = key[1:]
if value is True:
value = name
elif value is False or value is None:
continue
attr.append((name, value))
data = self.attributes.get('data', {})
for key, value in data.iteritems():
name = 'data-' + key
value = data[key]
attr.append((name, value))
attr.sort()
fa = ''
for name, value in attr:
fa += ' %s="%s"' % (name, xmlescape(value, True))
# get the xml for the inner components
co = join([xmlescape(component) for component in
self.components])
return (fa, co)
评论列表
文章目录