routing: stop printing warning if the user passes a wrong URL

When a _lookup method accepts N + *remainder arguments but the number of
path components (separated by /) is < N, a TypeError is raised when calling the
object and Pecan prints a RuntimeWarning that is log. Unfortunately this just
fills up the log with no interesting information for the developer as this is
just a standard 404 error.
This commit is contained in:
Julien Danjou 2017-01-20 21:09:51 +01:00
parent 3673bae6f3
commit 2b8e8816ad
2 changed files with 8 additions and 10 deletions

View File

@ -1,3 +1,4 @@
import logging
import re
import warnings
from inspect import getmembers, ismethod
@ -12,6 +13,8 @@ __all__ = ['lookup_controller', 'find_object', 'route']
__observed_controllers__ = set()
__custom_routes__ = {}
logger = logging.getLogger(__name__)
def route(*args):
"""
@ -177,11 +180,8 @@ def handle_lookup_traversal(obj, args):
cross_boundary(prev_obj, obj)
return result
except TypeError as te:
msg = 'Got exception calling lookup(): %s (%s)'
warnings.warn(
msg % (te, te.args),
RuntimeWarning
)
logger.debug('Got exception calling lookup(): %s (%s)',
te, te.args)
def find_object(obj, remainder, notfound_handlers, request):

View File

@ -339,11 +339,9 @@ class TestLookups(PecanTestCase):
def _lookup(self, someID):
return 'Bad arg spec' # pragma: nocover
with warnings.catch_warnings():
warnings.simplefilter("ignore")
app = TestApp(Pecan(RootController()))
r = app.get('/foo/bar', expect_errors=True)
assert r.status_int == 404
app = TestApp(Pecan(RootController()))
r = app.get('/foo/bar', expect_errors=True)
assert r.status_int == 404
class TestCanonicalLookups(PecanTestCase):