def metadata_sorter(x, y):
    """ Sort metadata keys by priority.
    """
    if x == y:
        return 0
    if x in METADATA_SORTER_FIRST and y in METADATA_SORTER_FIRST:
        return -1 if METADATA_SORTER_FIRST.index(x) < METADATA_SORTER_FIRST.index(y) else 1
    elif x in METADATA_SORTER_FIRST:
        return -1
    elif y in METADATA_SORTER_FIRST:
        return 1
    else:
        if x.startswith('_') and y.startswith('_'):
            return cmp(x[1:], y[1:])
        elif x.startswith('_'):
            return 1
        elif y.startswith('_'):
            return -1
        else:
            return cmp(x, y)
def metadata_sorter ( x , y ) : if x == y : return 0 if x in METADATA_SORTER_FIRST and y in METADATA_SORTER_FIRST : return - 1 if METADATA_SORTER_FIRST . index ( x ) < METADATA_SORTER_FIRST . index ( y ) else 1 elif x in METADATA_SORTER_FIRST : return - 1 elif y in METADATA_SORTER_FIRST : return 1 else : if x . startswith ( '_' ) and y . startswith ( '_' ) : return cmp ( x [ 1 : ] , y [ 1 : ] ) elif x . startswith ( '_' ) : return 1 elif y . startswith ( '_' ) : return - 1 else : return cmp ( x , y )
Sort metadata keys by priority.