code: def validate_sort_fields(sort_fields):
      
      # Allow descending order per field by prefixing with '-'
      descending = set()
      def sort_order_filter(name):
          "Helper to remove flag and memoize sort order"
          if name.startswith('-'):
              name = name[1:]
              descending.add(name)
          return name
  
      # Split and validate field list
      sort_fields = validate_field_list(sort_fields, name_filter=sort_order_filter)
      log.debug("Sorting order is: %s" % ", ".join([('-' if i in descending else '') + i
          for i in sort_fields]))
  
      # No descending fields?
      if not descending:
          return operator.attrgetter(*tuple(sort_fields))
  
      # Need to provide complex key
      class Key(object):
          "Complex sort order key"
          def __init__(self, obj, *args):
              "Remember object to be compared"
              self.obj = obj
          def __lt__(self, other):
              "Compare to other key"
              for field in sort_fields:
                  lhs, rhs = getattr(self.obj, field), getattr(other.obj, field)
                  if lhs == rhs:
                      continue
                  return rhs < lhs if field in descending else lhs < rhs
              return False
  
      return Key
docs: Make sure the fields in the given list exist, and return sorting key.
  
          If field names are prefixed with '-', sort order is reversed for that field (descending).