def _generate_comparator(cls, field_names):
        """
        Construct a comparator function based on the field names. The comparator
        returns the first non-zero comparison value.

        Inputs:
            field_names (iterable of strings): The field names to sort on.

        Returns:
            A comparator function.
        """
        # Ensure that field names is a list and not a tuple.
        field_names = list(field_names)

        # For fields that start with a '-', reverse the ordering of the
        # comparison.
        reverses = [1] * len(field_names)
        for i, field_name in enumerate(field_names):
            if field_name[0] == '-':
                reverses[i] = -1
                field_names[i] = field_name[1:]

        field_names = [f.replace(LOOKUP_SEP, '.') for f in field_names]

        def comparator(i1, i2):
            # Get a tuple of values for comparison.
            v1 = attrgetter(*field_names)(i1)
            v2 = attrgetter(*field_names)(i2)

            # If there's only one arg supplied, attrgetter returns a single
            # item, directly return the result in this case.
            if len(field_names) == 1:
                return cls._cmp(v1, v2) * reverses[0]

            # Compare each field for the two items, reversing if necessary.
            order = multiply_iterables(list(map(cls._cmp, v1, v2)), reverses)

            try:
                # The first non-zero element.
                return next(dropwhile(__not__, order))
            except StopIteration:
                # Everything was equivalent.
                return 0

        return comparator
def _generate_comparator ( cls , field_names ) : field_names = list ( field_names ) reverses = [ 1 ] * len ( field_names ) for i , field_name in enumerate ( field_names ) : if field_name [ 0 ] == '-' : reverses [ i ] = - 1 field_names [ i ] = field_name [ 1 : ] field_names = [ f . replace ( LOOKUP_SEP , '.' ) for f in field_names ] def comparator ( i1 , i2 ) : v1 = attrgetter ( * field_names ) ( i1 ) v2 = attrgetter ( * field_names ) ( i2 ) if len ( field_names ) == 1 : return cls . _cmp ( v1 , v2 ) * reverses [ 0 ] order = multiply_iterables ( list ( map ( cls . _cmp , v1 , v2 ) ) , reverses ) try : return next ( dropwhile ( __not__ , order ) ) except StopIteration : return 0 return comparator
Construct a comparator function based on the field names. The comparator
        returns the first non-zero comparison value.

        Inputs:
            field_names (iterable of strings): The field names to sort on.

        Returns:
            A comparator function.