def apply(self, elem, obj):

        # Start with the text...
        if self.text is not None:
            elem.text = unicode(self.text(obj))

        # Now set up all the attributes...
        for key, value in self.attrib.items():
            try:
                elem.set(key, unicode(value(obj, True)))
            except KeyError:
                # Attribute has no value, so don't include it
                pass
Apply text and attributes to an etree.Element.
dataset/ETHPy150Open openstack/rack/rack/api/xmlutil.py/TemplateElement.apply