[lxml-dev] should _setElementValue add type attributes?

jholg at gmx.de jholg at gmx.de
Mon Aug 27 12:53:00 CEST 2007


Hi,
I discussed this with Stefan before and I'm anxious to know if this is the way to go (maybe as switchable behaviour), removing the need for a beast like the discussed PT() factory, as well as making type behaviour arguably more "straightforward", at the cost of auto-adding py:pytype attributes:

# _setElementValue implementation that auto-adds type(RVAL).__name__ as
# py:pytype
cdef _setElementValue(_Element element, value):
    if value is None:
        cetree.setAttributeValue(
            element, XML_SCHEMA_INSTANCE_NIL_ATTR, "true")
    elif isinstance(value, _Element):
        _replaceElement(element, value)
    else:
        cetree.delAttributeFromNsName(
            element._c_node, _XML_SCHEMA_INSTANCE_NS, "nil")
        if not python._isString(value):
            pytype_name = type(value).__name__
            if isinstance(value, bool):
                value = _lower_bool(value)
            else:
                value = str(value)
        else:
            pytype_name = "str"
        cetree.setAttributeValue(element, PYTYPE_ATTRIBUTE, pytype_name)
    cetree.setNodeText(element._c_node, value)

I'm +1 for that. By making it switchable we could cater for those who don't care about the types that much but who do not want to see any non-explicitly created attributes.

Holger
-- 
Der GMX SmartSurfer hilft bis zu 70% Ihrer Onlinekosten zu sparen! 
Ideal für Modem und ISDN: http://www.gmx.net/de/go/smartsurfer


More information about the lxml-dev mailing list