nodes: 0, module; 1, function_definition; 2, function_name:_sort; 3, parameters; 4, block; 5, identifier:self; 6, identifier:session_groups; 7, expression_statement; 8, comment:# Sort by session_group name so we have a deterministic order.; 9, expression_statement; 10, comment:# Sort by lexicographical order of the _request.col_params whose order; 11, comment:# is not ORDER_UNSPECIFIED. The first such column is the primary sorting; 12, comment:# key, the second is the secondary sorting key, etc. To achieve that we; 13, comment:# need to iterate on these columns in reverse order (thus the primary key; 14, comment:# is the key used in the last sort).; 15, for_statement; 16, comment:"""Sorts 'session_groups' in place according to _request.col_params."""; 17, call; 18, pattern_list; 19, call; 20, block; 21, attribute; 22, argument_list; 23, identifier:col_param; 24, identifier:extractor; 25, identifier:reversed; 26, argument_list; 27, if_statement; 28, if_statement; 29, identifier:session_groups; 30, identifier:sort; 31, keyword_argument; 32, call; 33, comparison_operator:col_param.order == api_pb2.ORDER_UNSPECIFIED; 34, block; 35, comparison_operator:col_param.order == api_pb2.ORDER_ASC; 36, block; 37, elif_clause; 38, else_clause; 39, identifier:key; 40, call; 41, identifier:list; 42, argument_list; 43, attribute; 44, attribute; 45, continue_statement; 46, attribute; 47, attribute; 48, expression_statement; 49, comparison_operator:col_param.order == api_pb2.ORDER_DESC; 50, block; 51, block; 52, attribute; 53, argument_list; 54, call; 55, identifier:col_param; 56, identifier:order; 57, identifier:api_pb2; 58, identifier:ORDER_UNSPECIFIED; 59, identifier:col_param; 60, identifier:order; 61, identifier:api_pb2; 62, identifier:ORDER_ASC; 63, call; 64, attribute; 65, attribute; 66, expression_statement; 67, raise_statement; 68, identifier:operator; 69, identifier:attrgetter; 70, string; 71, identifier:zip; 72, argument_list; 73, attribute; 74, argument_list; 75, identifier:col_param; 76, identifier:order; 77, identifier:api_pb2; 78, identifier:ORDER_DESC; 79, call; 80, call; 81, string_content:name; 82, attribute; 83, attribute; 84, identifier:session_groups; 85, identifier:sort; 86, keyword_argument; 87, attribute; 88, argument_list; 89, attribute; 90, argument_list; 91, attribute; 92, identifier:col_params; 93, identifier:self; 94, identifier:_extractors; 95, identifier:key; 96, call; 97, identifier:session_groups; 98, identifier:sort; 99, keyword_argument; 100, keyword_argument; 101, identifier:error; 102, identifier:HParamsError; 103, binary_operator:'Unknown col_param.order given: %s' %
                                   col_param; 104, identifier:self; 105, identifier:_request; 106, identifier:_create_key_func; 107, argument_list; 108, identifier:key; 109, call; 110, identifier:reverse; 111, True; 112, string; 113, identifier:col_param; 114, identifier:extractor; 115, keyword_argument; 116, identifier:_create_key_func; 117, argument_list; 118, string_content:Unknown col_param.order given: %s; 119, identifier:none_is_largest; 120, not_operator; 121, identifier:extractor; 122, keyword_argument; 123, attribute; 124, identifier:none_is_largest; 125, attribute; 126, identifier:col_param; 127, identifier:missing_values_first; 128, identifier:col_param; 129, identifier:missing_values_first
code: def _sort(self, session_groups):
      """Sorts 'session_groups' in place according to _request.col_params."""
  
      # Sort by session_group name so we have a deterministic order.
      session_groups.sort(key=operator.attrgetter('name'))
      # Sort by lexicographical order of the _request.col_params whose order
      # is not ORDER_UNSPECIFIED. The first such column is the primary sorting
      # key, the second is the secondary sorting key, etc. To achieve that we
      # need to iterate on these columns in reverse order (thus the primary key
      # is the key used in the last sort).
      for col_param, extractor in reversed(list(zip(self._request.col_params,
                                                    self._extractors))):
        if col_param.order == api_pb2.ORDER_UNSPECIFIED:
          continue
        if col_param.order == api_pb2.ORDER_ASC:
          session_groups.sort(
              key=_create_key_func(
                  extractor,
                  none_is_largest=not col_param.missing_values_first))
        elif col_param.order == api_pb2.ORDER_DESC:
          session_groups.sort(
              key=_create_key_func(
                  extractor,
                  none_is_largest=col_param.missing_values_first),
              reverse=True)
        else:
          raise error.HParamsError('Unknown col_param.order given: %s' %
                                   col_param)