Chris McDonough
2012-11-11 267dbd261862c3d1e06ec49aad36e4bbae384eca
- Be more tolerant of potential error conditions in ``match_param`` and
``physical_path`` predicate implementations; instead of raising an exception,
return False.
3 files modified
25 ■■■■■ changed files
CHANGES.txt 4 ●●●● patch | view | raw | blame | history
pyramid/config/predicates.py 9 ●●●● patch | view | raw | blame | history
pyramid/tests/test_config/test_predicates.py 12 ●●●●● patch | view | raw | blame | history
CHANGES.txt
@@ -52,6 +52,10 @@
  attribute of the request.  It no longer fails in this case.  See
  https://github.com/Pylons/pyramid/issues/700
- Be more tolerant of potential error conditions in ``match_param`` and
  ``physical_path`` predicate implementations; instead of raising an exception,
  return False.
Deprecations
------------
pyramid/config/predicates.py
@@ -17,6 +17,8 @@
from .util import as_sorted_tuple
_marker = object()
class XHRPredicate(object):
    def __init__(self, val, config):
        self.val = bool(val)
@@ -174,6 +176,9 @@
    phash = text
    def __call__(self, context, request):
        if not request.matchdict:
            # might be None
            return False
        for k, v in self.reqs:
            if request.matchdict.get(k) != v:
                return False
@@ -266,7 +271,9 @@
    phash = text
    def __call__(self, context, request):
        return resource_path_tuple(context) == self.val
        if getattr(context, '__name__', _marker) is not _marker:
            return resource_path_tuple(context) == self.val
        return False
class EffectivePrincipalsPredicate(object):
    def __init__(self, val, config):
pyramid/tests/test_config/test_predicates.py
@@ -187,6 +187,13 @@
        result = inst(None, request)
        self.assertFalse(result)
    def test___call___matchdict_is_None(self):
        inst = self._makeOne('abc=1')
        request = Dummy()
        request.matchdict = None
        result = inst(None, request)
        self.assertFalse(result)
    def test_text(self):
        inst = self._makeOne(('def=  1', 'abc =2'))
        self.assertEqual(inst.text(), 'match_param abc=2,def=1')
@@ -436,6 +443,11 @@
        context.__parent__ = root
        self.assertFalse(inst(context, None))
    def test_it_call_context_has_no_name(self):
        inst = self._makeOne('/', None)
        context = Dummy()
        self.assertFalse(inst(context, None))
class Test_EffectivePrincipalsPredicate(unittest.TestCase):
    def setUp(self):
        self.config = testing.setUp()