nodes: 0, module; 1, function_definition; 2, function_name:extract_sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:params; 7, expression_statement; 8, expression_statement; 9, expression_statement; 10, expression_statement; 11, expression_statement; 12, string; 13, assignment; 14, assignment; 15, assignment; 16, assignment; 17, string_content:Extract and build sort query from parameters; 18, identifier:sorts; 19, call; 20, identifier:sorts; 21, conditional_expression:[sorts] if isinstance(sorts, basestring) else sorts; 22, identifier:sorts; 23, list_comprehension; 24, attribute; 25, list_comprehension; 26, attribute; 27, argument_list; 28, list; 29, call; 30, identifier:sorts; 31, conditional_expression:(s[1:], 'desc')
                   if s.startswith('-') else (s, 'asc'); 32, for_in_clause; 33, identifier:self; 34, identifier:sorts; 35, dictionary; 36, for_in_clause; 37, if_clause; 38, identifier:params; 39, identifier:pop; 40, string; 41, list; 42, identifier:sorts; 43, identifier:isinstance; 44, argument_list; 45, tuple; 46, call; 47, tuple; 48, identifier:s; 49, identifier:sorts; 50, pair; 51, pattern_list; 52, identifier:sorts; 53, comparison_operator:s in self.adapter.sorts; 54, string_content:sort; 55, identifier:sorts; 56, identifier:basestring; 57, subscript; 58, string; 59, attribute; 60, argument_list; 61, identifier:s; 62, string; 63, subscript; 64, identifier:d; 65, identifier:s; 66, identifier:d; 67, identifier:s; 68, attribute; 69, identifier:s; 70, slice; 71, string_content:desc; 72, identifier:s; 73, identifier:startswith; 74, string; 75, string_content:asc; 76, attribute; 77, identifier:s; 78, attribute; 79, identifier:sorts; 80, integer:1; 81, string_content:-; 82, attribute; 83, identifier:sorts; 84, identifier:self; 85, identifier:adapter; 86, identifier:self; 87, identifier:adapter
code: def extract_sort(self, params):
          '''Extract and build sort query from parameters'''
          sorts = params.pop('sort', [])
          sorts = [sorts] if isinstance(sorts, basestring) else sorts
          sorts = [(s[1:], 'desc')
                   if s.startswith('-') else (s, 'asc')
                   for s in sorts]
          self.sorts = [
              {self.adapter.sorts[s]: d}
              for s, d in sorts if s in self.adapter.sorts
          ]