summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2018-09-03 21:20:38 -0500
committerMichael Merickel <michael@merickel.org>2018-09-03 21:20:38 -0500
commit2497d05c17016ee5dc7cb5900399a28f1845c8cc (patch)
tree67e7d7787872838113ad0949075e74e098cdd8c8
parented6ddcb8c7badca425093d85e23791f942dd9a34 (diff)
downloadpyramid-2497d05c17016ee5dc7cb5900399a28f1845c8cc.tar.gz
pyramid-2497d05c17016ee5dc7cb5900399a28f1845c8cc.tar.bz2
pyramid-2497d05c17016ee5dc7cb5900399a28f1845c8cc.zip
support multiple types in the route predicate
-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):