summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris McDonough <chrism@plope.com>2012-11-11 12:35:16 -0500
committerChris McDonough <chrism@plope.com>2012-11-11 12:35:16 -0500
commit267dbd261862c3d1e06ec49aad36e4bbae384eca (patch)
treea8b7cc3e47d76beec1cbda81dbddeeec16ce8e25
parent20b1a19653de95e1adfa864a4f9ef6b2522e3409 (diff)
downloadpyramid-267dbd261862c3d1e06ec49aad36e4bbae384eca.tar.gz
pyramid-267dbd261862c3d1e06ec49aad36e4bbae384eca.tar.bz2
pyramid-267dbd261862c3d1e06ec49aad36e4bbae384eca.zip
- Be more tolerant of potential error conditions in ``match_param`` and
``physical_path`` predicate implementations; instead of raising an exception, return False.
-rw-r--r--CHANGES.txt4
-rw-r--r--pyramid/config/predicates.py9
-rw-r--r--pyramid/tests/test_config/test_predicates.py12
3 files changed, 24 insertions, 1 deletions
diff --git a/CHANGES.txt b/CHANGES.txt
index 5175baa5a..b0bbd32a2 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -52,6 +52,10 @@ Bug Fixes
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
------------
diff --git a/pyramid/config/predicates.py b/pyramid/config/predicates.py
index e31425899..ded8fbfbf 100644
--- a/pyramid/config/predicates.py
+++ b/pyramid/config/predicates.py
@@ -17,6 +17,8 @@ from pyramid.security import effective_principals
from .util import as_sorted_tuple
+_marker = object()
+
class XHRPredicate(object):
def __init__(self, val, config):
self.val = bool(val)
@@ -174,6 +176,9 @@ class MatchParamPredicate(object):
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 @@ class PhysicalPathPredicate(object):
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):
diff --git a/pyramid/tests/test_config/test_predicates.py b/pyramid/tests/test_config/test_predicates.py
index 91dfb0fb6..1cd6050bf 100644
--- a/pyramid/tests/test_config/test_predicates.py
+++ b/pyramid/tests/test_config/test_predicates.py
@@ -187,6 +187,13 @@ class TestMatchParamPredicate(unittest.TestCase):
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 @@ class Test_PhysicalPathPredicate(unittest.TestCase):
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()