From 2eb64f7a8bc7830667c3cb924bb5c13be3859b38 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Sat, 24 Jul 2010 08:32:21 +0000 Subject: Remove match_val feature: it's a pretty nuisance --- CHANGES.txt | 18 -------- docs/narr/views.rst | 27 ----------- docs/whatsnew-1.3.rst | 22 +++++---- docs/zcml/view.rst | 24 ---------- repoze/bfg/configuration.py | 61 +++---------------------- repoze/bfg/tests/test_configuration.py | 82 +--------------------------------- repoze/bfg/zcml.py | 9 +--- 7 files changed, 19 insertions(+), 224 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 47720221b..2520b8f5e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -4,15 +4,6 @@ Next release Features -------- -- New view predicate: match_val. The ``match_val`` value represents - the presence of a value in the structure added to the request named - ``matchdict`` during URL dispatch representing the match values from - the route pattern (e.g. if the route pattern has ``:foo`` in it, and - the route matches, a key will exist in the matchdict named ``foo``). - Like all other view predicates, this feature is exposed via the - ``bfg_view`` API, the Configurator ``add_view`` API, and the ZCML - ``view`` directive. - - New argument to ``repoze.bfg.configuration.Configurator.add_route`` and the ``route`` ZCML directive: ``traverse``. If you would like to cause the ``context`` to be something other than the ``root`` @@ -60,15 +51,6 @@ Features Documentation ------------- -- API documentation for the ``add_view`` method of the configurator - changed to include ``match_val``. - -- ZCML documentation for ``view`` ZCML directive changed to include - ``match_val``. - -- The ``Views`` narrative chapter now contains a description of the - ``match_val`` predicate. - - The ``Hybrid`` narrative chapter now contains a description of the ``traverse`` route argument. diff --git a/docs/narr/views.rst b/docs/narr/views.rst index 9b7d6b2dd..eebaa63de 100644 --- a/docs/narr/views.rst +++ b/docs/narr/views.rst @@ -1358,33 +1358,6 @@ Predicate Arguments taken into consideration when deciding whether or not to invoke the associated view callable. -``match_val`` - - This value represents :term:`URL dispatch` ``request.matchdict`` - name or a matchdict name/value pair. ``request.matchdict`` is a - dictionary representing the match values from the route pattern - (e.g. if the route pattern has ``:foo`` in it, and the route - matches, a key will exist in the matchdict named ``foo``). - - If ``match_val`` is specified, it must be the name of a key presumed - to be present in the ``matchdict`` or a ``key:regex`` pair. - - If ``match_val`` is specified without a colon in it - (e.g. ``action``), the predicate will return true if the - ``matchdict`` has a key which exists with any value. - - When the ``match_val`` contains a ``:`` (colon), it will be split at - the first colon; the left hand of that split will considered a key - and the right hand a regular expression. For example, in - ``action:\w+\.html``, the key part is ``action``, the regex part is - ``\w+\.html``. The resulting predicate will only be true if the - matchdict contains a key that matches the key part *and* the - matchdict value is matched by the regex part. - - If ``match_val`` is not specified, the composition, presence or - absence of values in the matchdict is not taken into consideration - when deciding whether or not to invoke the associated view callable. - ``custom_predicates`` If ``custom_predicates`` is specified, it must be a sequence of references to custom predicate callables. Use custom predicates diff --git a/docs/whatsnew-1.3.rst b/docs/whatsnew-1.3.rst index f55ac88a6..48fe8f4f0 100644 --- a/docs/whatsnew-1.3.rst +++ b/docs/whatsnew-1.3.rst @@ -158,18 +158,6 @@ Minor Feature Additions media package-internal and served by the development webserver during development. -- A new :ref:`view predicate` was added named ``match_val``. The - ``match_val`` value represents the presence of a value in the - structure added to the request named ``matchdict`` during :term:`URL - dispatch` representing the match values from the route pattern - (e.g. if the route pattern has ``:foo`` in it, and the route - matches, a key will exist in the matchdict named ``foo``). Like all - other view predicates, this feature is exposed via the - :class:`repoze.bfg.view.bfg_view` API, the - :class:`repoze.bfg.configuration.Configurator.add_view` API, and the - ZCML :ref:`view_directive` directive. See the documentation for - those APIs for more inforamtion. - - New argument to :class:`repoze.bfg.configuration.Configurator.add_route` and the ZCML ``route`` directive: ``traverse``. If you would like to cause @@ -182,6 +170,13 @@ Minor Feature Additions :class:`repoze.bfg.configuration.Configurator.add_route` for more information (the ``traverse`` argument). +- A new method of the ``Configurator`` exists: + ``set_request_factory``. If used, this method will set the factory + used by the :mod:`repoze.bfg` router to create all request objects. + The ``Configurator`` constructor also takes an additional argument: + ``request_factory``. If used, this argument will set the factory + used by the :mod:`repoze.bfg` router to create all request objects. + Backwards Incompatibilities --------------------------- @@ -248,6 +243,9 @@ Documentation Enhancements changed to demonstrate authorization via a group rather than via a direct username. +- The :ref:`hooks_chapter` chapter now contains a section about + changing the request factory. + Licensing Changes ----------------- diff --git a/docs/zcml/view.rst b/docs/zcml/view.rst index 9fe63738b..d33a9a9a5 100644 --- a/docs/zcml/view.rst +++ b/docs/zcml/view.rst @@ -224,30 +224,6 @@ Predicate Attributes .. note:: This feature is new as of :mod:`repoze.bfg` 1.1. -``match_val`` - - The ``match_val`` value represents the presence of a value in the - :term:`URL dispatch` structure added to the request named - ``matchdict``. ``matchdict`` represents the match values from the - route pattern (e.g. if the route pattern has ``:foo`` in it, and the - route matches, a key will exist in the matchdict named ``foo``). If - the value does not contain a colon, the entire value will be - considered to be the name of a matchdict key (e.g. ``action``). If - the value does contain a ``:`` (colon), it will be considered a - name/value pair (e.g. ``action:generate.html`` or - ``action:\w+.html``). The right hand side following the colon - should be a regular expression. - - If the value does not contain a colon, the key specified by the name - must be present in the URL dispatch matchdict for this predicate to - be true; the value of the key is ignored. If the value does contain - a colon, the name implied by the right hand must be present in the - matchdict *and* the regular expression specified on the right hand - side of the colon must match the value for the name in the matchdict - for this predicate to be true. - - .. note:: This feature is new as of :mod:`repoze.bfg` 1.3. - ``custom_predicates`` This value should be a sequence of references to custom predicate callables (e.g. ``dotted.name.one dotted.name.two``, if used in diff --git a/repoze/bfg/configuration.py b/repoze/bfg/configuration.py index ca5809cca..443da9d61 100644 --- a/repoze/bfg/configuration.py +++ b/repoze/bfg/configuration.py @@ -544,8 +544,8 @@ class Configurator(object): 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, match_val=None, - custom_predicates=(), context=None, _info=u''): + header=None, path_info=None, custom_predicates=(), + context=None, _info=u''): """ Add a :term:`view configuration` to the current configuration state. Arguments to ``add_view`` are broken down below into *predicate* arguments and *non-predicate* @@ -765,32 +765,6 @@ class Configurator(object): ``True``. - match_val - - The ``match_val`` value represents the presence of a value - in the :term:`URL dispatch` structure added to the request - named ``matchdict``. ``matchdict`` represents the match - values from the route pattern (e.g. if the route pattern has - ``:foo`` in it, and the route matches, a key will exist in - the matchdict named ``foo``). If the value does not contain - a colon, the entire value will be considered to be the name - of a matchdict key (e.g. ``action``). If the value does - contain a ``:`` (colon), it will be considered a name/value - pair (e.g. ``action:generate.html`` or ``action:\w+.html``). - The right hand side following the colon should be a regular - expression. - - If the value does not contain a colon, the key specified by - the name must be present in the URL dispatch matchdict for - this predicate to be true; the value of the key is ignored. - If the value does contain a colon, the name implied by the - right hand must be present in the matchdict *and* the - regular expression specified on the right hand side of the - colon must match the value for the name in the matchdict for - this predicate to be true. - - .. note:: This feature is new as of :mod:`repoze.bfg` 1.3. - custom_predicates This value should be a sequence of references to custom @@ -841,7 +815,7 @@ class Configurator(object): request_method=request_method, request_param=request_param, containment=containment, attr=attr, renderer=renderer, wrapper=wrapper, xhr=xhr, accept=accept, - header=header, path_info=path_info, match_val=match_val, + header=header, path_info=path_info, custom_predicates=(), context=context, _info=u'' ) view_info = deferred_views.setdefault(route_name, []) @@ -852,7 +826,7 @@ class Configurator(object): request_method=request_method, path_info=path_info, request_param=request_param, header=header, accept=accept, containment=containment, request_type=request_type, - view_match_val=match_val, custom=custom_predicates) + custom=custom_predicates) derived_view = self._derive_view(view, permission, predicates, attr, renderer, wrapper, name, accept, order, @@ -1052,6 +1026,8 @@ class Configurator(object): ignored when attached to a route that has a ``*traverse`` remainder marker in its path. + .. note:: This feature is new as of :mod:`repoze.bfg` 1.3. + Predicate Arguments path @@ -1759,7 +1735,7 @@ class Configurator(object): def _make_predicates(xhr=None, request_method=None, path_info=None, request_param=None, header=None, accept=None, containment=None, request_type=None, - view_match_val=None, traverse=None, custom=()): + traverse=None, custom=()): # PREDICATES # ---------- @@ -1887,29 +1863,6 @@ def _make_predicates(xhr=None, request_method=None, path_info=None, predicates.append(request_type_predicate) h.update('request_type:%r' % id(request_type)) - if view_match_val is not None: - match_name = view_match_val - match_val = None - if ':' in match_name: - match_name, match_val = match_name.split(':', 1) - try: - match_val = re.compile(match_val) - except re.error, why: - raise ConfigurationError(why[0]) - def view_match_val_predicate(context, request): - matchdict = getattr(request, 'matchdict', None) - if matchdict is None: - return False - if match_val is None: - return match_name in matchdict - val = matchdict.get(match_name) - if val is None: - return False - return match_val.match(val) is not None - weights.append(1 << 9) - predicates.append(view_match_val_predicate) - h.update('view_match_val:%r=%r' % (match_name, match_val)) - if traverse is not None: # ``traverse`` can only be used as a *route* "predicate"; it # adds 'traverse' to the matchdict if it's specified in the diff --git a/repoze/bfg/tests/test_configuration.py b/repoze/bfg/tests/test_configuration.py index 02fbc7a06..25c5544b6 100644 --- a/repoze/bfg/tests/test_configuration.py +++ b/repoze/bfg/tests/test_configuration.py @@ -1414,68 +1414,6 @@ class ConfiguratorTests(unittest.TestCase): request.path_info = '/' self._assertNotFound(wrapper, None, request) - def test_add_view_with_match_val_badregex(self): - from repoze.bfg.exceptions import ConfigurationError - view = lambda *arg: 'OK' - config = self._makeOne() - self.assertRaises(ConfigurationError, - config.add_view, view=view, match_val='action:a\\') - - def test_add_view_with_match_val_no_matchdict(self): - from repoze.bfg.exceptions import NotFound - view = lambda *arg: 'OK' - config = self._makeOne() - config.add_view(view=view, match_val='action') - wrapper = self._getViewCallable(config) - request = self._makeRequest(config) - self.assertRaises(NotFound, wrapper, None, request) - - def test_add_view_with_match_val_noval_match(self): - view = lambda *arg: 'OK' - config = self._makeOne() - config.add_view(view=view, match_val='action') - wrapper = self._getViewCallable(config) - request = self._makeRequest(config) - request.matchdict = {'action':'whatever'} - self.assertEqual(wrapper(None, request), 'OK') - - def test_add_view_with_match_val_noval_nomatch(self): - view = lambda *arg: 'OK' - config = self._makeOne() - config.add_view(view=view, match_val='action') - wrapper = self._getViewCallable(config) - request = self._makeRequest(config) - request.matchdict = {'notaction':'whatever'} - self._assertNotFound(wrapper, None, request) - - def test_add_view_with_match_val_val_match(self): - view = lambda *arg: 'OK' - config = self._makeOne() - config.add_view(view=view, match_val='action:\d') - wrapper = self._getViewCallable(config) - request = self._makeRequest(config) - request.matchdict = {'action':'1'} - self.assertEqual(wrapper(None, request), 'OK') - - def test_add_view_with_match_val_val_nomatch(self): - view = lambda *arg: 'OK' - config = self._makeOne() - config.add_view(view=view, match_val=r'action:\d') - wrapper = self._getViewCallable(config) - request = self._makeRequest(config) - request.matchdict = {'action':'abc'} - self._assertNotFound(wrapper, None, request) - - def test_add_view_with_match_val_val_missing(self): - from repoze.bfg.exceptions import NotFound - view = lambda *arg: 'OK' - config = self._makeOne() - config.add_view(view=view, match_val=r'action:\d') - wrapper = self._getViewCallable(config) - request = self._makeRequest(config) - request.matchdict = {'notaction':'1'} - self.assertRaises(NotFound, wrapper, None, request) - def test_add_view_with_custom_predicates_match(self): view = lambda *arg: 'OK' config = self._makeOne() @@ -3001,7 +2939,6 @@ class Test__make_predicates(unittest.TestCase): accept='accept', containment='containment', request_type='request_type', - view_match_val='view_match_val', custom=('a',) ) order2, _, _ = self._callFUT( @@ -3013,7 +2950,6 @@ class Test__make_predicates(unittest.TestCase): accept='accept', containment='containment', request_type='request_type', - view_match_val='view_match_val', custom=('a',) ) order3, _, _ = self._callFUT( @@ -3025,8 +2961,7 @@ class Test__make_predicates(unittest.TestCase): accept='accept', containment='containment', request_type='request_type', - view_match_val='view_match_val', - ) + ) order4, _, _ = self._callFUT( xhr='xhr', request_method='request_method', @@ -3035,7 +2970,6 @@ class Test__make_predicates(unittest.TestCase): header='header', accept='accept', containment='containment', - request_type='request_type', ) order5, _, _ = self._callFUT( xhr='xhr', @@ -3044,7 +2978,6 @@ class Test__make_predicates(unittest.TestCase): request_param='param', header='header', accept='accept', - containment='containment', ) order6, _, _ = self._callFUT( xhr='xhr', @@ -3052,34 +2985,26 @@ class Test__make_predicates(unittest.TestCase): path_info='path_info', request_param='param', header='header', - accept='accept', ) order7, _, _ = self._callFUT( xhr='xhr', request_method='request_method', path_info='path_info', request_param='param', - header='header', ) order8, _, _ = self._callFUT( xhr='xhr', request_method='request_method', path_info='path_info', - request_param='param', ) order9, _, _ = self._callFUT( xhr='xhr', request_method='request_method', - path_info='path_info', ) order10, _, _ = self._callFUT( xhr='xhr', - request_method='request_method', ) order11, _, _ = self._callFUT( - xhr='xhr', - ) - order12, _, _ = self._callFUT( ) self.assertEqual(order1, order2) self.failUnless(order3 > order2) @@ -3091,7 +3016,6 @@ class Test__make_predicates(unittest.TestCase): self.failUnless(order9 > order8) self.failUnless(order10 > order9) self.failUnless(order11 > order10) - self.failUnless(order12 > order11) def test_ordering_importance_of_predicates(self): order1, _, _ = self._callFUT( @@ -3119,9 +3043,6 @@ class Test__make_predicates(unittest.TestCase): request_type='request_type', ) order9, _, _ = self._callFUT( - view_match_val='view_match_val', - ) - order10, _, _ = self._callFUT( custom=('a',), ) self.failUnless(order1 > order2) @@ -3132,7 +3053,6 @@ class Test__make_predicates(unittest.TestCase): self.failUnless(order6 > order7) self.failUnless(order7 > order8) self.failUnless(order8 > order9) - self.failUnless(order9 > order10) def test_ordering_importance_and_number(self): order1, _, _ = self._callFUT( diff --git a/repoze/bfg/zcml.py b/repoze/bfg/zcml.py index b350d5ea7..820dc9442 100644 --- a/repoze/bfg/zcml.py +++ b/repoze/bfg/zcml.py @@ -141,11 +141,6 @@ class IViewDirective(Interface): description=(u'Accepts a regular expression.'), required = False) - match_val = TextLine( - title=u'Matchdict name/value pair in the form "name="', - description=u'Regular expression matching for matchdict values', - required = False) - custom_predicates = Tokens( title=u"One or more custom dotted names to custom predicate callables", description=(u"A list of dotted name references to callables that " @@ -173,7 +168,6 @@ def view( accept=None, header=None, path_info=None, - match_val=None, traverse=None, custom_predicates=(), context=None, @@ -206,8 +200,7 @@ def view( request_method=request_method, request_param=request_param, containment=containment, attr=attr, renderer=renderer, wrapper=wrapper, xhr=xhr, accept=accept, header=header, - path_info=path_info, match_val=match_val, - custom_predicates=custom_predicates, + path_info=path_info, custom_predicates=custom_predicates, _info=_context.info) discriminator = ['view', context, name, request_type, IView, containment, -- cgit v1.2.3