'Helper function used by the various find/search functions to return
object representations in order.'

def __sort(self, data, sort_field=None):

    sort_fields = ['name']
    sort_rev = False
    if (sort_field is not None):
        if sort_field.startswith('!'):
            sort_field = sort_field[1:]
            sort_rev = True
        sort_fields.insert(0, sort_field)
    sortdata = [(x.sort_key(sort_fields), x) for x in data]
    if sort_rev:
        sortdata.sort((lambda a, b: cmp(b, a)))
    else:
        sortdata.sort()
    return [x for (key, x) in sortdata]
