def xmlAttrName2PyAttrName(key):
    """Converts the XML attribute name *key* to an appropriate Python attribute
    identifier. If the *key* is `class` then it is translated into `class_`.
    If a namespace is defined (to be recognized on {...}, then replace that by
    prefix `'ns_'`. If an HTML5 attribute *data-xxxx* is used, then
    change that to *data_xxxx*."""
    if key == 'class':
        key = 'cssClass'
    elif key == 'id':
        key = 'cssId'
    elif key.startswith('{'):
        key = 'ns_' + key.split('}')[-1]
    elif '-' in key:
        # In case of new HTML5 data-xxxx attributes.
        key = key.replace('-', '_')
    return key