def METHOD_NAME(a, b):
    x = cmp(type_index.index(a.tag), type_index.index(b.tag))
    if x != 0: return x
    if a.tag == 'class' and b.tag == 'class':
        a_bases = _get_bases(a, recurse=True)
        b_bases = _get_bases(b, recurse=True)
        x = cmp(len(a_bases), len(b_bases))
        if x != 0: return x
        if a.attrib['id'] in b_bases: return -1
        if b.attrib['id'] in a_bases: return 1
    return cmp(a.attrib['id'].count('.'), b.attrib['id'].count('.'))