def removeDefaultAttributeValues(node, options, tainted=set()):
    u"""'tainted' keeps a set of attributes defined in parent nodes.

    For such attributes, we don't delete attributes with default values."""
    num = 0
    if node.nodeType != Node.ELEMENT_NODE:
        return 0

    # Conditionally remove all default attributes defined in 'default_attributes' (a list of 'DefaultAttribute's)
    #
    # For increased performance do not iterate the whole list for each element but run only on valid subsets
    # - 'default_attributes_universal' (attributes valid for all elements)
    # - 'default_attributes_per_element' (attributes specific to one specific element type)
    for attribute in default_attributes_universal:
        num += removeDefaultAttributeValue(node, attribute)
    if node.nodeName in default_attributes_per_element:
        for attribute in default_attributes_per_element[node.nodeName]:
            num += removeDefaultAttributeValue(node, attribute)

    # Summarily get rid of default properties
    attributes = [node.attributes.item(i).nodeName for i in range(node.attributes.length)]
    for attribute in attributes:
        if attribute not in tainted:
            if attribute in default_properties:
                if node.getAttribute(attribute) == default_properties[attribute]:
                    node.removeAttribute(attribute)
                    num += 1
                else:
                    tainted = taint(tainted, attribute)
    # Properties might also occur as styles, remove them too
    styles = _getStyle(node)
    for attribute in list(styles):
        if attribute not in tainted:
            if attribute in default_properties:
                if styles[attribute] == default_properties[attribute]:
                    del styles[attribute]
                    num += 1
                else:
                    tainted = taint(tainted, attribute)
    _setStyle(node, styles)

    # recurse for our child elements
    for child in node.childNodes:
        num += removeDefaultAttributeValues(child, options, tainted.copy())

    return num
def removeDefaultAttributeValues ( node , options , tainted = set ( ) ) : num = 0 if node . nodeType != Node . ELEMENT_NODE : return 0 for attribute in default_attributes_universal : num += removeDefaultAttributeValue ( node , attribute ) if node . nodeName in default_attributes_per_element : for attribute in default_attributes_per_element [ node . nodeName ] : num += removeDefaultAttributeValue ( node , attribute ) attributes = [ node . attributes . item ( i ) . nodeName for i in range ( node . attributes . length ) ] for attribute in attributes : if attribute not in tainted : if attribute in default_properties : if node . getAttribute ( attribute ) == default_properties [ attribute ] : node . removeAttribute ( attribute ) num += 1 else : tainted = taint ( tainted , attribute ) styles = _getStyle ( node ) for attribute in list ( styles ) : if attribute not in tainted : if attribute in default_properties : if styles [ attribute ] == default_properties [ attribute ] : del styles [ attribute ] num += 1 else : tainted = taint ( tainted , attribute ) _setStyle ( node , styles ) for child in node . childNodes : num += removeDefaultAttributeValues ( child , options , tainted . copy ( ) ) return num
u"""'tainted' keeps a set of attributes defined in parent nodes.

    For such attributes, we don't delete attributes with default values.