summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@agendaless.com>2009-10-29 02:49:16 +0000
committerChris McDonough <chrism@agendaless.com>2009-10-29 02:49:16 +0000
commitd8c776df0ff6a194be696c95d921caf2084194c6 (patch)
tree82b0714d5389ffe376d720033cafc16ed7e134d8
parent07cf61d25adf627c9ddc1f607266b0d61070e391 (diff)
downloadpyramid-d8c776df0ff6a194be696c95d921caf2084194c6.tar.gz
pyramid-d8c776df0ff6a194be696c95d921caf2084194c6.tar.bz2
pyramid-d8c776df0ff6a194be696c95d921caf2084194c6.zip
- An incorrect ZCML conflict would be encountered when the
``request_param`` predicate attribute was used on the ZCML ``view`` directive if any two otherwise same-predicated views had the combination of a predicate value with an ``=`` sign and one without (e.g. ``a`` vs. ``a=123``).
-rw-r--r--CHANGES.txt12
-rw-r--r--repoze/bfg/tests/test_zcml.py10
-rw-r--r--repoze/bfg/zcml.py107
3 files changed, 75 insertions, 54 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 6f4054de5..622880d82 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -1,3 +1,15 @@
+Next release
+============
+
+Bug Fixes
+---------
+
+- An incorrect ZCML conflict would be encountered when the
+ ``request_param`` predicate attribute was used on the ZCML ``view``
+ directive if any two otherwise same-predicated views had the
+ combination of a predicate value with an ``=`` sign and one without
+ (e.g. ``a`` vs. ``a=123``).
+
1.1a8 (2009-10-27)
==================
diff --git a/repoze/bfg/tests/test_zcml.py b/repoze/bfg/tests/test_zcml.py
index 49b8d8cd1..352a53e53 100644
--- a/repoze/bfg/tests/test_zcml.py
+++ b/repoze/bfg/tests/test_zcml.py
@@ -649,7 +649,7 @@ class TestViewDirective(unittest.TestCase):
request.params = {}
self.assertRaises(NotFound, wrapper, None, request)
- def test_with_request_paramoval_true(self):
+ def test_with_request_param_val_true(self):
from zope.component import getSiteManager
from zope.interface import Interface
from repoze.bfg.interfaces import IRequest
@@ -665,8 +665,8 @@ class TestViewDirective(unittest.TestCase):
actions = context.actions
self.assertEqual(len(actions), 1)
action = actions[0]
- discrim = ('view', IFoo, '', IRequest, IView, None, 'abc', None, None,
- None, False, None, None, None)
+ discrim = ('view', IFoo, '', IRequest, IView, None, 'abc=123', None,
+ None, None, False, None, None, None)
self.assertEqual(action['discriminator'], discrim)
register = action['callable']
register()
@@ -692,8 +692,8 @@ class TestViewDirective(unittest.TestCase):
actions = context.actions
self.assertEqual(len(actions), 1)
action = actions[0]
- discrim = ('view', IFoo, '', IRequest, IView, None, 'abc', None, None,
- None, False, None, None, None)
+ discrim = ('view', IFoo, '', IRequest, IView, None, 'abc=123', None,
+ None, None, False, None, None, None)
self.assertEqual(action['discriminator'], discrim)
register = action['callable']
register()
diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py
index e2ce7a030..c192fddfb 100644
--- a/repoze/bfg/zcml.py
+++ b/repoze/bfg/zcml.py
@@ -147,55 +147,9 @@ class IViewDirective(Interface):
description=(u'Accepts a regular expression.'),
required = False)
-def view(
- _context,
- permission=None,
- for_=None,
- view=None,
- name="",
- request_type=None,
- route_name=None,
- request_method=None,
- request_param=None,
- containment=None,
- attr=None,
- renderer=None,
- wrapper=None,
- xhr=False,
- accept=None,
- header=None,
- path_info=None,
- cacheable=True, # not used, here for b/w compat < 0.8
- ):
-
- if not view:
- if renderer:
- def view(context, request):
- return {}
- else:
- raise ConfigurationError('"view" attribute was not specified and '
- 'no renderer specified')
-
- sm = getSiteManager()
-
- if request_type in ('GET', 'HEAD', 'PUT', 'POST', 'DELETE'):
- # b/w compat for 1.0
- request_method = request_type
- request_type = None
-
- if request_type is None:
- if route_name is None:
- request_type = IRequest
- else:
- request_type = queryUtility(IRouteRequest, name=route_name)
- if request_type is None:
- factory = create_route_request_factory(route_name)
- request_type = implementedBy(factory)
- sm.registerUtility(factory, IRouteRequest, name=route_name)
-
- if isinstance(request_type, basestring):
- request_type = _context.resolve(request_type)
-
+def _make_predicates(xhr=None, request_method=None, path_info=None,
+ request_param=None, header=None, accept=None,
+ containment=None):
# Predicates are added to the predicate list in (presumed)
# computation expense order. All predicates associated with a
# view must evaluate true for the view to "match" a request.
@@ -289,10 +243,65 @@ def view(
# this will be == sys.maxint if no predicates
score = weight / (len(predicates) + 1)
+ return score, predicates
+
+def view(
+ _context,
+ permission=None,
+ for_=None,
+ view=None,
+ name="",
+ request_type=None,
+ route_name=None,
+ request_method=None,
+ request_param=None,
+ containment=None,
+ attr=None,
+ renderer=None,
+ wrapper=None,
+ xhr=False,
+ accept=None,
+ header=None,
+ path_info=None,
+ cacheable=True, # not used, here for b/w compat < 0.8
+ ):
+
+ if not view:
+ if renderer:
+ def view(context, request):
+ return {}
+ else:
+ raise ConfigurationError('"view" attribute was not specified and '
+ 'no renderer specified')
+
+ sm = getSiteManager()
+
+ if request_type in ('GET', 'HEAD', 'PUT', 'POST', 'DELETE'):
+ # b/w compat for 1.0
+ request_method = request_type
+ request_type = None
+
+ if request_type is None:
+ if route_name is None:
+ request_type = IRequest
+ else:
+ request_type = queryUtility(IRouteRequest, name=route_name)
+ if request_type is None:
+ factory = create_route_request_factory(route_name)
+ request_type = implementedBy(factory)
+ sm.registerUtility(factory, IRouteRequest, name=route_name)
+
+ if isinstance(request_type, basestring):
+ request_type = _context.resolve(request_type)
if renderer and '.' in renderer:
renderer = resource_spec(renderer, package_name(_context.resolve('.')))
+ score, predicates = _make_predicates(
+ xhr=xhr, request_method=request_method, path_info=path_info,
+ request_param=request_param, header=header, accept=accept,
+ containment=containment)
+
def register():
derived_view = derive_view(view, permission, predicates, attr, renderer,
wrapper, name)