summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFang-Pen Lin <bornstub@gmail.com>2017-05-22 14:40:44 -0700
committerFang-Pen Lin <bornstub@gmail.com>2017-05-22 14:40:44 -0700
commit08422ee6340cbcd225dcfc26c7c0aa3165449a58 (patch)
tree6c07189d9004d67b8bb0d822d51ea444fd336dfe
parentaafaf73655c11ca1d6645d85e1754be6996540dd (diff)
downloadpyramid-08422ee6340cbcd225dcfc26c7c0aa3165449a58.tar.gz
pyramid-08422ee6340cbcd225dcfc26c7c0aa3165449a58.tar.bz2
pyramid-08422ee6340cbcd225dcfc26c7c0aa3165449a58.zip
Fix #1603, add closest predicate name in error message
-rw-r--r--pyramid/config/util.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/pyramid/config/util.py b/pyramid/config/util.py
index 67bba9593..d09d37d94 100644
--- a/pyramid/config/util.py
+++ b/pyramid/config/util.py
@@ -1,3 +1,4 @@
+from difflib import get_close_matches
from hashlib import md5
import inspect
@@ -36,7 +37,7 @@ class not_(object):
config.add_view(
'mypackage.views.my_view',
- route_name='ok',
+ route_name='ok',
request_method=not_('POST')
)
@@ -69,7 +70,7 @@ class Notted(object):
# if the underlying predicate doesnt return a value, it's not really
# a predicate, it's just something pretending to be a predicate,
# so dont update the hash
- if val:
+ if val:
val = '!' + val
return val
@@ -90,7 +91,7 @@ class Notted(object):
# over = before
class PredicateList(object):
-
+
def __init__(self):
self.sorter = TopologicalSorter()
self.last_added = None
@@ -152,7 +153,15 @@ class PredicateList(object):
weights.append(1 << n + 1)
preds.append(pred)
if kw:
- raise ConfigurationError('Unknown predicate values: %r' % (kw,))
+ closest = []
+ names = [ name for name, _ in ordered ]
+ for name in kw:
+ closest.extend(get_close_matches(name, names, 3))
+
+ raise ConfigurationError(
+ 'Unknown predicate values: %r (did you mean %s)'
+ % (kw, ','.join(closest))
+ )
# A "order" is computed for the predicate list. An order is
# a scoring.
#