We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Helpful exceptions on "a named thing was not found"
[This was originally mentioned in #1601](https://github.com/Pylons/pyramid/issues/1601), but @mmerickel wanted it to be a separate issue, so here goes:

Whenever one uses an invalid kwarg name in `view_config`, or provides an invalid route name for a view, one gets an exception that just states that the given name was wrong. As this is an exceptional condition at startup time, and more so usually meaning that the whole application startup failed, it really would not matter if we used some extra cycles to make the error messages more helpful.

Especially with lots of 3rd-party stuff `include`d in the configurations, it might be really hard to remember how _exactly_ to write the name of a certain predicate, and usually this means more than 5 minutes of googling again. Thus I propose that the exception message would list close matches to these values, so that using `@view_config(method='POST')` would state `Unknown predicate values: {'method': 'POST'}; did you mean request_method`, for example I modified the [raise for invalid predicate names](https://github.com/Pylons/pyramid/blob/master/pyramid/config/util.py#L157) to

```
try:
    from difflib import get_close_matches
    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)))

except ImportError:
    pass

raise ConfigurationError('Unknown predicate values: %r' % (kw,))
```

Which produces the aforementioned message. The runtime overhead of this is 0 (excepting for a few more bytecodes loaded on startup) for successful configuration and minimal overhead in mostly fatal errors that would make the server not start anyway. The `difflib.get_close_matches` function itself has been in the Python stdlib since 2.1... refactored in a utility function, this close matching could be used for all the cases where the configurator could at configuration time list the allowed values for something.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `pyramid/config/util.py`
Content:
```
1 from hashlib import md5
2 import inspect
3 
4 from pyramid.compat import (
5     bytes_,
6     getargspec,
7     is_nonstr_iter
8     )
9 
10 from pyramid.compat import im_func
11 from pyramid.exceptions import ConfigurationError
12 from pyramid.registry import predvalseq
13 
14 from pyramid.util import (
15     TopologicalSorter,
16     action_method,
17     ActionInfo,
18     )
19 
20 action_method = action_method # support bw compat imports
21 ActionInfo = ActionInfo # support bw compat imports
22 
23 MAX_ORDER = 1 << 30
24 DEFAULT_PHASH = md5().hexdigest()
25 
26 class not_(object):
27     """
28 
29     You can invert the meaning of any predicate value by wrapping it in a call
30     to :class:`pyramid.config.not_`.
31 
32     .. code-block:: python
33        :linenos:
34 
35        from pyramid.config import not_
36 
37        config.add_view(
38            'mypackage.views.my_view',
39            route_name='ok', 
40            request_method=not_('POST')
41            )
42 
43     The above example will ensure that the view is called if the request method
44     is *not* ``POST``, at least if no other view is more specific.
45 
46     This technique of wrapping a predicate value in ``not_`` can be used
47     anywhere predicate values are accepted:
48 
49     - :meth:`pyramid.config.Configurator.add_view`
50 
51     - :meth:`pyramid.config.Configurator.add_route`
52 
53     - :meth:`pyramid.config.Configurator.add_subscriber`
54 
55     - :meth:`pyramid.view.view_config`
56 
57     - :meth:`pyramid.events.subscriber`
58 
59     .. versionadded:: 1.5
60     """
61     def __init__(self, value):
62         self.value = value
63 
64 class Notted(object):
65     def __init__(self, predicate):
66         self.predicate = predicate
67 
68     def _notted_text(self, val):
69         # if the underlying predicate doesnt return a value, it's not really
70         # a predicate, it's just something pretending to be a predicate,
71         # so dont update the hash
72         if val: 
73             val = '!' + val
74         return val
75 
76     def text(self):
77         return self._notted_text(self.predicate.text())
78 
79     def phash(self):
80         return self._notted_text(self.predicate.phash())
81 
82     def __call__(self, context, request):
83         result = self.predicate(context, request)
84         phash = self.phash()
85         if phash:
86             result = not result
87         return result
88 
89 # under = after
90 # over = before
91 
92 class PredicateList(object):
93     
94     def __init__(self):
95         self.sorter = TopologicalSorter()
96         self.last_added = None
97 
98     def add(self, name, factory, weighs_more_than=None, weighs_less_than=None):
99         # Predicates should be added to a predicate list in (presumed)
100         # computation expense order.
101         ## if weighs_more_than is None and weighs_less_than is None:
102         ##     weighs_more_than = self.last_added or FIRST
103         ##     weighs_less_than = LAST
104         self.last_added = name
105         self.sorter.add(
106             name,
107             factory,
108             after=weighs_more_than,
109             before=weighs_less_than,
110             )
111 
112     def names(self):
113         # Return the list of valid predicate names.
114         return self.sorter.names
115 
116     def make(self, config, **kw):
117         # Given a configurator and a list of keywords, a predicate list is
118         # computed.  Elsewhere in the code, we evaluate predicates using a
119         # generator expression.  All predicates associated with a view or
120         # route must evaluate true for the view or route to "match" during a
121         # request.  The fastest predicate should be evaluated first, then the
122         # next fastest, and so on, as if one returns false, the remainder of
123         # the predicates won't need to be evaluated.
124         #
125         # While we compute predicates, we also compute a predicate hash (aka
126         # phash) that can be used by a caller to identify identical predicate
127         # lists.
128         ordered = self.sorter.sorted()
129         phash = md5()
130         weights = []
131         preds = []
132         for n, (name, predicate_factory) in enumerate(ordered):
133             vals = kw.pop(name, None)
134             if vals is None: # XXX should this be a sentinel other than None?
135                 continue
136             if not isinstance(vals, predvalseq):
137                 vals = (vals,)
138             for val in vals:
139                 realval = val
140                 notted = False
141                 if isinstance(val, not_):
142                     realval = val.value
143                     notted = True
144                 pred = predicate_factory(realval, config)
145                 if notted:
146                     pred = Notted(pred)
147                 hashes = pred.phash()
148                 if not is_nonstr_iter(hashes):
149                     hashes = [hashes]
150                 for h in hashes:
151                     phash.update(bytes_(h))
152                 weights.append(1 << n + 1)
153                 preds.append(pred)
154         if kw:
155             raise ConfigurationError('Unknown predicate values: %r' % (kw,))
156         # A "order" is computed for the predicate list.  An order is
157         # a scoring.
158         #
159         # Each predicate is associated with a weight value.  The weight of a
160         # predicate symbolizes the relative potential "importance" of the
161         # predicate to all other predicates.  A larger weight indicates
162         # greater importance.
163         #
164         # All weights for a given predicate list are bitwise ORed together
165         # to create a "score"; this score is then subtracted from
166         # MAX_ORDER and divided by an integer representing the number of
167         # predicates+1 to determine the order.
168         #
169         # For views, the order represents the ordering in which a "multiview"
170         # ( a collection of views that share the same context/request/name
171         # triad but differ in other ways via predicates) will attempt to call
172         # its set of views.  Views with lower orders will be tried first.
173         # The intent is to a) ensure that views with more predicates are
174         # always evaluated before views with fewer predicates and b) to
175         # ensure a stable call ordering of views that share the same number
176         # of predicates.  Views which do not have any predicates get an order
177         # of MAX_ORDER, meaning that they will be tried very last.
178         score = 0
179         for bit in weights:
180             score = score | bit
181         order = (MAX_ORDER - score) / (len(preds) + 1)
182         return order, preds, phash.hexdigest()
183 
184 def takes_one_arg(callee, attr=None, argname=None):
185     ismethod = False
186     if attr is None:
187         attr = '__call__'
188     if inspect.isroutine(callee):
189         fn = callee
190     elif inspect.isclass(callee):
191         try:
192             fn = callee.__init__
193         except AttributeError:
194             return False
195         ismethod = hasattr(fn, '__call__')
196     else:
197         try:
198             fn = getattr(callee, attr)
199         except AttributeError:
200             return False
201 
202     try:
203         argspec = getargspec(fn)
204     except TypeError:
205         return False
206 
207     args = argspec[0]
208 
209     if hasattr(fn, im_func) or ismethod:
210         # it's an instance method (or unbound method on py2)
211         if not args:
212             return False
213         args = args[1:]
214 
215     if not args:
216         return False
217 
218     if len(args) == 1:
219         return True
220 
221     if argname:
222 
223         defaults = argspec[3]
224         if defaults is None:
225             defaults = ()
226 
227         if args[0] == argname:
228             if len(args) - len(defaults) == 1:
229                 return True
230 
231     return False
232
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/pyramid/config/util.py b/pyramid/config/util.py
--- a/pyramid/config/util.py
+++ b/pyramid/config/util.py
@@ -36,7 +36,7 @@
 
        config.add_view(
            'mypackage.views.my_view',
-           route_name='ok', 
+           route_name='ok',
            request_method=not_('POST')
            )
 
@@ -69,7 +69,7 @@
         # 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 +90,7 @@
 # over = before
 
 class PredicateList(object):
-    
+
     def __init__(self):
         self.sorter = TopologicalSorter()
         self.last_added = None
@@ -152,7 +152,16 @@
                 weights.append(1 << n + 1)
                 preds.append(pred)
         if kw:
-            raise ConfigurationError('Unknown predicate values: %r' % (kw,))
+            from difflib import get_close_matches
+            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.
         #

{"golden_diff": "diff --git a/pyramid/config/util.py b/pyramid/config/util.py\n--- a/pyramid/config/util.py\n+++ b/pyramid/config/util.py\n@@ -36,7 +36,7 @@\n \n        config.add_view(\n            'mypackage.views.my_view',\n-           route_name='ok', \n+           route_name='ok',\n            request_method=not_('POST')\n            )\n \n@@ -69,7 +69,7 @@\n         # if the underlying predicate doesnt return a value, it's not really\n         # a predicate, it's just something pretending to be a predicate,\n         # so dont update the hash\n-        if val: \n+        if val:\n             val = '!' + val\n         return val\n \n@@ -90,7 +90,7 @@\n # over = before\n \n class PredicateList(object):\n-    \n+\n     def __init__(self):\n         self.sorter = TopologicalSorter()\n         self.last_added = None\n@@ -152,7 +152,16 @@\n                 weights.append(1 << n + 1)\n                 preds.append(pred)\n         if kw:\n-            raise ConfigurationError('Unknown predicate values: %r' % (kw,))\n+            from difflib import get_close_matches\n+            closest = []\n+            names = [ name for name, _ in ordered ]\n+            for name in kw:\n+                closest.extend(get_close_matches(name, names, 3))\n+\n+            raise ConfigurationError(\n+                'Unknown predicate values: %r (did you mean %s)'\n+                % (kw, ','.join(closest))\n+            )\n         # A \"order\" is computed for the predicate list.  An order is\n         # a scoring.\n         #\n", "issue": "Helpful exceptions on \"a named thing was not found\"\n[This was originally mentioned in #1601](https://github.com/Pylons/pyramid/issues/1601), but @mmerickel wanted it to be a separate issue, so here goes:\n\nWhenever one uses an invalid kwarg name in `view_config`, or provides an invalid route name for a view, one gets an exception that just states that the given name was wrong. As this is an exceptional condition at startup time, and more so usually meaning that the whole application startup failed, it really would not matter if we used some extra cycles to make the error messages more helpful.\n\nEspecially with lots of 3rd-party stuff `include`d in the configurations, it might be really hard to remember how _exactly_ to write the name of a certain predicate, and usually this means more than 5 minutes of googling again. Thus I propose that the exception message would list close matches to these values, so that using `@view_config(method='POST')` would state `Unknown predicate values: {'method': 'POST'}; did you mean request_method`, for example I modified the [raise for invalid predicate names](https://github.com/Pylons/pyramid/blob/master/pyramid/config/util.py#L157) to\n\n```\ntry:\n    from difflib import get_close_matches\n    closest = []\n    names = [ name for name, _ in ordered ]\n    for name in kw:\n        closest.extend(get_close_matches(name, names, 3))\n\n    raise ConfigurationError(\n        'Unknown predicate values: %r (did you mean %s)'\n         % (kw, ','.join(closest)))\n\nexcept ImportError:\n    pass\n\nraise ConfigurationError('Unknown predicate values: %r' % (kw,))\n```\n\nWhich produces the aforementioned message. The runtime overhead of this is 0 (excepting for a few more bytecodes loaded on startup) for successful configuration and minimal overhead in mostly fatal errors that would make the server not start anyway. The `difflib.get_close_matches` function itself has been in the Python stdlib since 2.1... refactored in a utility function, this close matching could be used for all the cases where the configurator could at configuration time list the allowed values for something.\n\n", "before_files": [{"content": "from hashlib import md5\nimport inspect\n\nfrom pyramid.compat import (\n    bytes_,\n    getargspec,\n    is_nonstr_iter\n    )\n\nfrom pyramid.compat import im_func\nfrom pyramid.exceptions import ConfigurationError\nfrom pyramid.registry import predvalseq\n\nfrom pyramid.util import (\n    TopologicalSorter,\n    action_method,\n    ActionInfo,\n    )\n\naction_method = action_method # support bw compat imports\nActionInfo = ActionInfo # support bw compat imports\n\nMAX_ORDER = 1 << 30\nDEFAULT_PHASH = md5().hexdigest()\n\nclass not_(object):\n    \"\"\"\n\n    You can invert the meaning of any predicate value by wrapping it in a call\n    to :class:`pyramid.config.not_`.\n\n    .. code-block:: python\n       :linenos:\n\n       from pyramid.config import not_\n\n       config.add_view(\n           'mypackage.views.my_view',\n           route_name='ok', \n           request_method=not_('POST')\n           )\n\n    The above example will ensure that the view is called if the request method\n    is *not* ``POST``, at least if no other view is more specific.\n\n    This technique of wrapping a predicate value in ``not_`` can be used\n    anywhere predicate values are accepted:\n\n    - :meth:`pyramid.config.Configurator.add_view`\n\n    - :meth:`pyramid.config.Configurator.add_route`\n\n    - :meth:`pyramid.config.Configurator.add_subscriber`\n\n    - :meth:`pyramid.view.view_config`\n\n    - :meth:`pyramid.events.subscriber`\n\n    .. versionadded:: 1.5\n    \"\"\"\n    def __init__(self, value):\n        self.value = value\n\nclass Notted(object):\n    def __init__(self, predicate):\n        self.predicate = predicate\n\n    def _notted_text(self, val):\n        # if the underlying predicate doesnt return a value, it's not really\n        # a predicate, it's just something pretending to be a predicate,\n        # so dont update the hash\n        if val: \n            val = '!' + val\n        return val\n\n    def text(self):\n        return self._notted_text(self.predicate.text())\n\n    def phash(self):\n        return self._notted_text(self.predicate.phash())\n\n    def __call__(self, context, request):\n        result = self.predicate(context, request)\n        phash = self.phash()\n        if phash:\n            result = not result\n        return result\n\n# under = after\n# over = before\n\nclass PredicateList(object):\n    \n    def __init__(self):\n        self.sorter = TopologicalSorter()\n        self.last_added = None\n\n    def add(self, name, factory, weighs_more_than=None, weighs_less_than=None):\n        # Predicates should be added to a predicate list in (presumed)\n        # computation expense order.\n        ## if weighs_more_than is None and weighs_less_than is None:\n        ##     weighs_more_than = self.last_added or FIRST\n        ##     weighs_less_than = LAST\n        self.last_added = name\n        self.sorter.add(\n            name,\n            factory,\n            after=weighs_more_than,\n            before=weighs_less_than,\n            )\n\n    def names(self):\n        # Return the list of valid predicate names.\n        return self.sorter.names\n\n    def make(self, config, **kw):\n        # Given a configurator and a list of keywords, a predicate list is\n        # computed.  Elsewhere in the code, we evaluate predicates using a\n        # generator expression.  All predicates associated with a view or\n        # route must evaluate true for the view or route to \"match\" during a\n        # request.  The fastest predicate should be evaluated first, then the\n        # next fastest, and so on, as if one returns false, the remainder of\n        # the predicates won't need to be evaluated.\n        #\n        # While we compute predicates, we also compute a predicate hash (aka\n        # phash) that can be used by a caller to identify identical predicate\n        # lists.\n        ordered = self.sorter.sorted()\n        phash = md5()\n        weights = []\n        preds = []\n        for n, (name, predicate_factory) in enumerate(ordered):\n            vals = kw.pop(name, None)\n            if vals is None: # XXX should this be a sentinel other than None?\n                continue\n            if not isinstance(vals, predvalseq):\n                vals = (vals,)\n            for val in vals:\n                realval = val\n                notted = False\n                if isinstance(val, not_):\n                    realval = val.value\n                    notted = True\n                pred = predicate_factory(realval, config)\n                if notted:\n                    pred = Notted(pred)\n                hashes = pred.phash()\n                if not is_nonstr_iter(hashes):\n                    hashes = [hashes]\n                for h in hashes:\n                    phash.update(bytes_(h))\n                weights.append(1 << n + 1)\n                preds.append(pred)\n        if kw:\n            raise ConfigurationError('Unknown predicate values: %r' % (kw,))\n        # A \"order\" is computed for the predicate list.  An order is\n        # a scoring.\n        #\n        # Each predicate is associated with a weight value.  The weight of a\n        # predicate symbolizes the relative potential \"importance\" of the\n        # predicate to all other predicates.  A larger weight indicates\n        # greater importance.\n        #\n        # All weights for a given predicate list are bitwise ORed together\n        # to create a \"score\"; this score is then subtracted from\n        # MAX_ORDER and divided by an integer representing the number of\n        # predicates+1 to determine the order.\n        #\n        # For views, the order represents the ordering in which a \"multiview\"\n        # ( a collection of views that share the same context/request/name\n        # triad but differ in other ways via predicates) will attempt to call\n        # its set of views.  Views with lower orders will be tried first.\n        # The intent is to a) ensure that views with more predicates are\n        # always evaluated before views with fewer predicates and b) to\n        # ensure a stable call ordering of views that share the same number\n        # of predicates.  Views which do not have any predicates get an order\n        # of MAX_ORDER, meaning that they will be tried very last.\n        score = 0\n        for bit in weights:\n            score = score | bit\n        order = (MAX_ORDER - score) / (len(preds) + 1)\n        return order, preds, phash.hexdigest()\n\ndef takes_one_arg(callee, attr=None, argname=None):\n    ismethod = False\n    if attr is None:\n        attr = '__call__'\n    if inspect.isroutine(callee):\n        fn = callee\n    elif inspect.isclass(callee):\n        try:\n            fn = callee.__init__\n        except AttributeError:\n            return False\n        ismethod = hasattr(fn, '__call__')\n    else:\n        try:\n            fn = getattr(callee, attr)\n        except AttributeError:\n            return False\n\n    try:\n        argspec = getargspec(fn)\n    except TypeError:\n        return False\n\n    args = argspec[0]\n\n    if hasattr(fn, im_func) or ismethod:\n        # it's an instance method (or unbound method on py2)\n        if not args:\n            return False\n        args = args[1:]\n\n    if not args:\n        return False\n\n    if len(args) == 1:\n        return True\n\n    if argname:\n\n        defaults = argspec[3]\n        if defaults is None:\n            defaults = ()\n\n        if args[0] == argname:\n            if len(args) - len(defaults) == 1:\n                return True\n\n    return False\n", "path": "pyramid/config/util.py"}], "after_files": [{"content": "from hashlib import md5\nimport inspect\n\nfrom pyramid.compat import (\n    bytes_,\n    getargspec,\n    is_nonstr_iter\n    )\n\nfrom pyramid.compat import im_func\nfrom pyramid.exceptions import ConfigurationError\nfrom pyramid.registry import predvalseq\n\nfrom pyramid.util import (\n    TopologicalSorter,\n    action_method,\n    ActionInfo,\n    )\n\naction_method = action_method # support bw compat imports\nActionInfo = ActionInfo # support bw compat imports\n\nMAX_ORDER = 1 << 30\nDEFAULT_PHASH = md5().hexdigest()\n\nclass not_(object):\n    \"\"\"\n\n    You can invert the meaning of any predicate value by wrapping it in a call\n    to :class:`pyramid.config.not_`.\n\n    .. code-block:: python\n       :linenos:\n\n       from pyramid.config import not_\n\n       config.add_view(\n           'mypackage.views.my_view',\n           route_name='ok',\n           request_method=not_('POST')\n           )\n\n    The above example will ensure that the view is called if the request method\n    is *not* ``POST``, at least if no other view is more specific.\n\n    This technique of wrapping a predicate value in ``not_`` can be used\n    anywhere predicate values are accepted:\n\n    - :meth:`pyramid.config.Configurator.add_view`\n\n    - :meth:`pyramid.config.Configurator.add_route`\n\n    - :meth:`pyramid.config.Configurator.add_subscriber`\n\n    - :meth:`pyramid.view.view_config`\n\n    - :meth:`pyramid.events.subscriber`\n\n    .. versionadded:: 1.5\n    \"\"\"\n    def __init__(self, value):\n        self.value = value\n\nclass Notted(object):\n    def __init__(self, predicate):\n        self.predicate = predicate\n\n    def _notted_text(self, val):\n        # if the underlying predicate doesnt return a value, it's not really\n        # a predicate, it's just something pretending to be a predicate,\n        # so dont update the hash\n        if val:\n            val = '!' + val\n        return val\n\n    def text(self):\n        return self._notted_text(self.predicate.text())\n\n    def phash(self):\n        return self._notted_text(self.predicate.phash())\n\n    def __call__(self, context, request):\n        result = self.predicate(context, request)\n        phash = self.phash()\n        if phash:\n            result = not result\n        return result\n\n# under = after\n# over = before\n\nclass PredicateList(object):\n\n    def __init__(self):\n        self.sorter = TopologicalSorter()\n        self.last_added = None\n\n    def add(self, name, factory, weighs_more_than=None, weighs_less_than=None):\n        # Predicates should be added to a predicate list in (presumed)\n        # computation expense order.\n        ## if weighs_more_than is None and weighs_less_than is None:\n        ##     weighs_more_than = self.last_added or FIRST\n        ##     weighs_less_than = LAST\n        self.last_added = name\n        self.sorter.add(\n            name,\n            factory,\n            after=weighs_more_than,\n            before=weighs_less_than,\n            )\n\n    def names(self):\n        # Return the list of valid predicate names.\n        return self.sorter.names\n\n    def make(self, config, **kw):\n        # Given a configurator and a list of keywords, a predicate list is\n        # computed.  Elsewhere in the code, we evaluate predicates using a\n        # generator expression.  All predicates associated with a view or\n        # route must evaluate true for the view or route to \"match\" during a\n        # request.  The fastest predicate should be evaluated first, then the\n        # next fastest, and so on, as if one returns false, the remainder of\n        # the predicates won't need to be evaluated.\n        #\n        # While we compute predicates, we also compute a predicate hash (aka\n        # phash) that can be used by a caller to identify identical predicate\n        # lists.\n        ordered = self.sorter.sorted()\n        phash = md5()\n        weights = []\n        preds = []\n        for n, (name, predicate_factory) in enumerate(ordered):\n            vals = kw.pop(name, None)\n            if vals is None: # XXX should this be a sentinel other than None?\n                continue\n            if not isinstance(vals, predvalseq):\n                vals = (vals,)\n            for val in vals:\n                realval = val\n                notted = False\n                if isinstance(val, not_):\n                    realval = val.value\n                    notted = True\n                pred = predicate_factory(realval, config)\n                if notted:\n                    pred = Notted(pred)\n                hashes = pred.phash()\n                if not is_nonstr_iter(hashes):\n                    hashes = [hashes]\n                for h in hashes:\n                    phash.update(bytes_(h))\n                weights.append(1 << n + 1)\n                preds.append(pred)\n        if kw:\n            from difflib import get_close_matches\n            closest = []\n            names = [ name for name, _ in ordered ]\n            for name in kw:\n                closest.extend(get_close_matches(name, names, 3))\n\n            raise ConfigurationError(\n                'Unknown predicate values: %r (did you mean %s)'\n                % (kw, ','.join(closest))\n            )\n        # A \"order\" is computed for the predicate list.  An order is\n        # a scoring.\n        #\n        # Each predicate is associated with a weight value.  The weight of a\n        # predicate symbolizes the relative potential \"importance\" of the\n        # predicate to all other predicates.  A larger weight indicates\n        # greater importance.\n        #\n        # All weights for a given predicate list are bitwise ORed together\n        # to create a \"score\"; this score is then subtracted from\n        # MAX_ORDER and divided by an integer representing the number of\n        # predicates+1 to determine the order.\n        #\n        # For views, the order represents the ordering in which a \"multiview\"\n        # ( a collection of views that share the same context/request/name\n        # triad but differ in other ways via predicates) will attempt to call\n        # its set of views.  Views with lower orders will be tried first.\n        # The intent is to a) ensure that views with more predicates are\n        # always evaluated before views with fewer predicates and b) to\n        # ensure a stable call ordering of views that share the same number\n        # of predicates.  Views which do not have any predicates get an order\n        # of MAX_ORDER, meaning that they will be tried very last.\n        score = 0\n        for bit in weights:\n            score = score | bit\n        order = (MAX_ORDER - score) / (len(preds) + 1)\n        return order, preds, phash.hexdigest()\n\ndef takes_one_arg(callee, attr=None, argname=None):\n    ismethod = False\n    if attr is None:\n        attr = '__call__'\n    if inspect.isroutine(callee):\n        fn = callee\n    elif inspect.isclass(callee):\n        try:\n            fn = callee.__init__\n        except AttributeError:\n            return False\n        ismethod = hasattr(fn, '__call__')\n    else:\n        try:\n            fn = getattr(callee, attr)\n        except AttributeError:\n            return False\n\n    try:\n        argspec = getargspec(fn)\n    except TypeError:\n        return False\n\n    args = argspec[0]\n\n    if hasattr(fn, im_func) or ismethod:\n        # it's an instance method (or unbound method on py2)\n        if not args:\n            return False\n        args = args[1:]\n\n    if not args:\n        return False\n\n    if len(args) == 1:\n        return True\n\n    if argname:\n\n        defaults = argspec[3]\n        if defaults is None:\n            defaults = ()\n\n        if args[0] == argname:\n            if len(args) - len(defaults) == 1:\n                return True\n\n    return False\n", "path": "pyramid/config/util.py"}]}