nodes: 0, module; 1, function_definition; 2, function_name:sort; 3, parameters; 4, block; 5, identifier:self; 6, list_splat_pattern; 7, expression_statement; 8, expression_statement; 9, for_statement; 10, return_statement; 11, identifier:sort_tuples; 12, string; 13, assignment; 14, pattern_list; 15, identifier:sort_tuples; 16, block; 17, identifier:query; 18, string_content:pymongo-style sorting.  Accepts a list of tuples.
  
              :param sort_tuples: varargs of sort tuples.; 19, identifier:query; 20, identifier:self; 21, identifier:name; 22, identifier:direction; 23, expression_statement; 24, if_statement; 25, assignment; 26, comparison_operator:direction in (ASCENDING, 1); 27, block; 28, elif_clause; 29, else_clause; 30, identifier:field; 31, call; 32, identifier:direction; 33, tuple; 34, expression_statement; 35, comparison_operator:direction in (DESCENDING, -1); 36, block; 37, block; 38, identifier:resolve_name; 39, argument_list; 40, identifier:ASCENDING; 41, integer:1; 42, assignment; 43, identifier:direction; 44, tuple; 45, expression_statement; 46, raise_statement; 47, attribute; 48, identifier:name; 49, identifier:query; 50, call; 51, identifier:DESCENDING; 52, unary_operator; 53, assignment; 54, call; 55, identifier:self; 56, identifier:type; 57, attribute; 58, argument_list; 59, integer:1; 60, identifier:query; 61, call; 62, identifier:BadQueryException; 63, argument_list; 64, identifier:query; 65, identifier:ascending; 66, identifier:field; 67, attribute; 68, argument_list; 69, binary_operator:'Bad sort direction: %s' % direction; 70, identifier:query; 71, identifier:descending; 72, identifier:field; 73, string; 74, identifier:direction; 75, string_content:Bad sort direction: %s
code: def sort(self, *sort_tuples):
          ''' pymongo-style sorting.  Accepts a list of tuples.
  
              :param sort_tuples: varargs of sort tuples.
          '''
          query = self
          for name, direction in sort_tuples:
              field = resolve_name(self.type, name)
              if direction in (ASCENDING, 1):
                  query = query.ascending(field)
              elif direction in (DESCENDING, -1):
                  query = query.descending(field)
              else:
                  raise BadQueryException('Bad sort direction: %s' % direction)
          return query