def process_sort_params(sort_keys, sort_dirs, default_keys=None, default_dir='asc'):
 if (default_keys is None):
  default_keys = ['created_at', 'id']
 if (sort_dirs and len(sort_dirs)):
  default_dir_value = sort_dirs[0]
 else:
  default_dir_value = default_dir
 if sort_keys:
  result_keys = list(sort_keys)
 else:
  result_keys = []
 if sort_dirs:
  result_dirs = []
  for sort_dir in sort_dirs:
   if (sort_dir not in ('asc', 'desc')):
    msg = _("Unknown sort direction, must be 'desc' or 'asc'.")
    raise exception.InvalidInput(reason=msg)
   result_dirs.append(sort_dir)
 else:
  result_dirs = [default_dir_value for _sort_key in result_keys]
 while (len(result_dirs) < len(result_keys)):
  result_dirs.append(default_dir_value)
 if (len(result_dirs) > len(result_keys)):
  msg = _('Sort direction array size exceeds sort key array size.')
  raise exception.InvalidInput(reason=msg)
 for key in default_keys:
  if (key not in result_keys):
   result_keys.append(key)
   result_dirs.append(default_dir_value)
 return (result_keys, result_dirs)

def process_sort_params ( sort_keys , sort_dirs , default_keys = None , default_dir = 'asc' ) : if ( default_keys is None ) : default_keys = [ 'created_at' , 'id' ] if ( sort_dirs and len ( sort_dirs ) ) : default_dir_value = sort_dirs [ 0 ] else : default_dir_value = default_dir if sort_keys : result_keys = list ( sort_keys ) else : result_keys = [ ] if sort_dirs : result_dirs = [ ] for sort_dir in sort_dirs : if ( sort_dir not in ( 'asc' , 'desc' ) ) : msg = _ ( "Unknown sort direction, must be 'desc' or 'asc'." ) raise exception . InvalidInput ( reason = msg ) result_dirs . append ( sort_dir ) else : result_dirs = [ default_dir_value for _sort_key in result_keys ] while ( len ( result_dirs ) < len ( result_keys ) ) : result_dirs . append ( default_dir_value ) if ( len ( result_dirs ) > len ( result_keys ) ) : msg = _ ( 'Sort direction array size exceeds sort key array size.' ) raise exception . InvalidInput ( reason = msg ) for key in default_keys : if ( key not in result_keys ) : result_keys . append ( key ) result_dirs . append ( default_dir_value ) return ( result_keys , result_dirs )
process the sort parameters to include default keys .