summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGES.rst4
-rw-r--r--pyramid/config/views.py5
-rw-r--r--pyramid/predicates.py12
3 files changed, 14 insertions, 7 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index d3ffa19fc..592ab8c63 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -63,6 +63,10 @@ Features
types that prefers human-readable html/text responses over JSON.
See https://github.com/Pylons/pyramid/pull/3326
+- Support a list of media types in the ``accept`` predicate used in
+ ``pyramid.config.Configurator.add_route``.
+ See https://github.com/Pylons/pyramid/pull/3326
+
Bug Fixes
---------
diff --git a/pyramid/config/views.py b/pyramid/config/views.py
index 6ea672e4d..d6a80fe11 100644
--- a/pyramid/config/views.py
+++ b/pyramid/config/views.py
@@ -818,6 +818,11 @@ class ViewsConfiguratorMixin(object):
stacklevel=4,
)
+ if accept is not None and is_nonstr_iter(accept):
+ raise ConfigurationError(
+ 'A list is not supported in the "accept" view predicate.',
+ )
+
if accept is not None:
accept = accept.lower()
diff --git a/pyramid/predicates.py b/pyramid/predicates.py
index 4f63122aa..91fb41006 100644
--- a/pyramid/predicates.py
+++ b/pyramid/predicates.py
@@ -131,19 +131,17 @@ class HeaderPredicate(object):
class AcceptPredicate(object):
def __init__(self, val, config):
- self.val = val
- if '*' in self.val:
- raise ConfigurationError(
- '"accept" predicate only accepts specific media types',
- )
+ if not is_nonstr_iter(val):
+ val = (val,)
+ self.values = val
def text(self):
- return 'accept = %s' % (self.val,)
+ return 'accept = %s' % (self.values,)
phash = text
def __call__(self, context, request):
- return bool(request.accept.acceptable_offers([self.val]))
+ return bool(request.accept.acceptable_offers(self.values))
class ContainmentPredicate(object):
def __init__(self, val, config):