From 0cef6bc5d627524354c47295df7a0aa84a64539e Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Thu, 1 Nov 2018 21:05:04 -0500 Subject: remove deprecated media range support from add_view and add_route --- src/pyramid/config/predicates.py | 4 +--- src/pyramid/config/routes.py | 27 +++++++++------------------ src/pyramid/config/views.py | 21 ++++++--------------- src/pyramid/predicates.py | 8 -------- 4 files changed, 16 insertions(+), 44 deletions(-) (limited to 'src') diff --git a/src/pyramid/config/predicates.py b/src/pyramid/config/predicates.py index 8f16f74af..31e770562 100644 --- a/src/pyramid/config/predicates.py +++ b/src/pyramid/config/predicates.py @@ -197,9 +197,7 @@ class PredicateList(object): return order, preds, phash.hexdigest() -def normalize_accept_offer(offer, allow_range=False): - if allow_range and '*' in offer: - return offer.lower() +def normalize_accept_offer(offer): return str(Accept.parse_offer(offer)) diff --git a/src/pyramid/config/routes.py b/src/pyramid/config/routes.py index a14662370..f9180bd76 100644 --- a/src/pyramid/config/routes.py +++ b/src/pyramid/config/routes.py @@ -247,6 +247,10 @@ class RoutesConfiguratorMixin(object): :app:`Pyramid` 2.0. Use a list of specific media types to match more than one type. + .. versionchanged:: 2.0 + + Removed support for media ranges. + effective_principals If specified, this value should be a :term:`principal` identifier or @@ -308,24 +312,11 @@ class RoutesConfiguratorMixin(object): if accept is not None: if not is_nonstr_iter(accept): - if '*' in accept: - warnings.warn( - ( - 'Passing a media range to the "accept" argument ' - 'of Configurator.add_route is deprecated as of ' - 'Pyramid 1.10. Use a list of explicit media types.' - ), - DeprecationWarning, - stacklevel=3, - ) - # XXX switch this to False when range support is dropped - accept = [normalize_accept_offer(accept, allow_range=True)] - - else: - accept = [ - normalize_accept_offer(accept_option) - for accept_option in accept - ] + accept = [accept] + accept = [ + normalize_accept_offer(accept_option) + for accept_option in accept + ] # these are route predicates; if they do not match, the next route # in the routelist will be tried diff --git a/src/pyramid/config/views.py b/src/pyramid/config/views.py index bd1b693ba..0c4a17376 100644 --- a/src/pyramid/config/views.py +++ b/src/pyramid/config/views.py @@ -116,7 +116,7 @@ class MultiView(object): self.views[i] = (order, view, phash) return - if accept is None or '*' in accept: + if accept is None: self.views.append((order, view, phash)) self.views.sort(key=operator.itemgetter(0)) else: @@ -570,6 +570,10 @@ class ViewsConfiguratorMixin(object): :app:`Pyramid` 2.0. Use explicit media types to avoid any ambiguities in content negotiation. + .. versionchanged:: 2.0 + + Removed support for media ranges. + exception_only .. versionadded:: 1.8 @@ -838,20 +842,7 @@ class ViewsConfiguratorMixin(object): raise ConfigurationError( 'A list is not supported in the "accept" view predicate.' ) - if '*' in accept: - warnings.warn( - ( - 'Passing a media range to the "accept" argument of ' - 'Configurator.add_view is deprecated as of ' - 'Pyramid 1.10. Use explicit media types to avoid ' - 'ambiguities in content negotiation that may impact ' - 'your users.' - ), - DeprecationWarning, - stacklevel=4, - ) - # XXX when media ranges are gone, switch allow_range=False - accept = normalize_accept_offer(accept, allow_range=True) + accept = normalize_accept_offer(accept) view = self.maybe_dotted(view) context = self.maybe_dotted(context) diff --git a/src/pyramid/predicates.py b/src/pyramid/predicates.py index b95dfd9be..280f6c03c 100644 --- a/src/pyramid/predicates.py +++ b/src/pyramid/predicates.py @@ -133,15 +133,9 @@ class HeaderPredicate(object): class AcceptPredicate(object): - _is_using_deprecated_ranges = False - def __init__(self, values, config): if not is_nonstr_iter(values): values = (values,) - # deprecated media ranges were only supported in versions of the - # predicate that didn't support lists, so check it here - if len(values) == 1 and '*' in values[0]: - self._is_using_deprecated_ranges = True self.values = values def text(self): @@ -150,8 +144,6 @@ class AcceptPredicate(object): phash = text def __call__(self, context, request): - if self._is_using_deprecated_ranges: - return self.values[0] in request.accept return bool(request.accept.acceptable_offers(self.values)) -- cgit v1.2.3