def offer_sort_key(value): """ (type_weight, params_weight) type_weight: - index of specific ``type/subtype`` in order list - ``max_weight * 2`` if no match is found params_weight: - index of specific ``type/subtype;params`` in order list - ``max_weight`` if not found - ``max_weight + 1`` if no params at all """ parsed = Accept.parse_offer(value) type_w = find_order_index( parsed.type + '/' + parsed.subtype, max_weight ) if parsed.params: param_w = find_order_index(value, max_weight) else: param_w = max_weight + 1 return (type_w, param_w)
def offer_sort_key(value): """ (type_weight, params_weight) type_weight: - index of specific ``type/subtype`` in order list - ``max_weight * 2`` if no match is found params_weight: - index of specific ``type/subtype;params`` in order list - ``max_weight`` if not found - ``max_weight + 1`` if no params at all """ parsed = Accept.parse_offer(value) type_w = find_order_index(parsed.type + '/' + parsed.subtype, max_weight) if parsed.params: param_w = find_order_index(value, max_weight) else: param_w = max_weight + 1 return (type_w, param_w)
def normalize_accept_offer(offer): return str(Accept.parse_offer(offer))
def normalize_accept_offer(offer, allow_range=False): if allow_range and '*' in offer: return offer.lower() return str(Accept.parse_offer(offer))