def get_sorts(request, attr_info):
 sort_keys = list_args(request, 'sort_key')
 sort_dirs = list_args(request, 'sort_dir')
 if (len(sort_keys) != len(sort_dirs)):
  msg = _('The number of sort_keys and sort_dirs must be same')
  raise exc.HTTPBadRequest(explanation=msg)
 valid_dirs = [constants.SORT_DIRECTION_ASC, constants.SORT_DIRECTION_DESC]
 absent_keys = [x for x in sort_keys if (x not in attr_info)]
 if absent_keys:
  msg = (_('%s is invalid attribute for sort_keys') % absent_keys)
  raise exc.HTTPBadRequest(explanation=msg)
 invalid_dirs = [x for x in sort_dirs if (x not in valid_dirs)]
 if invalid_dirs:
  msg = (_("%(invalid_dirs)s is invalid value for sort_dirs, valid value is '%(asc)s' and '%(desc)s'") % {'invalid_dirs': invalid_dirs, 'asc': constants.SORT_DIRECTION_ASC, 'desc': constants.SORT_DIRECTION_DESC})
  raise exc.HTTPBadRequest(explanation=msg)
 return list(zip(sort_keys, [(x == constants.SORT_DIRECTION_ASC) for x in sort_dirs]))

def get_sorts ( request , attr_info ) : sort_keys = list_args ( request , 'sort_key' ) sort_dirs = list_args ( request , 'sort_dir' ) if ( len ( sort_keys ) != len ( sort_dirs ) ) : msg = _ ( 'The number of sort_keys and sort_dirs must be same' ) raise exc . HTTPBadRequest ( explanation = msg ) valid_dirs = [ constants . SORT_DIRECTION_ASC , constants . SORT_DIRECTION_DESC ] absent_keys = [ x for x in sort_keys if ( x not in attr_info ) ] if absent_keys : msg = ( _ ( '%s is invalid attribute for sort_keys' ) % absent_keys ) raise exc . HTTPBadRequest ( explanation = msg ) invalid_dirs = [ x for x in sort_dirs if ( x not in valid_dirs ) ] if invalid_dirs : msg = ( _ ( "%(invalid_dirs)s is invalid value for sort_dirs, valid value is '%(asc)s' and '%(desc)s'" ) % { 'invalid_dirs' : invalid_dirs , 'asc' : constants . SORT_DIRECTION_ASC , 'desc' : constants . SORT_DIRECTION_DESC } ) raise exc . HTTPBadRequest ( explanation = msg ) return list ( zip ( sort_keys , [ ( x == constants . SORT_DIRECTION_ASC ) for x in sort_dirs ] ) )
extract sort_key and sort_dir from request .