+ log.debug(u'Dispatcher.dispatch: %r is a handler, calling it with '
+ u'route=%r, kwargs=%r', handler, route, kwargs)
+ try:
+ r = handler(*route, **kwargs)
+ log.debug(u'Dispatcher.dispatch: handler returned %s', r)
+ return handler(*route, **kwargs)
+ except TypeError, e:
+ log.debug(u'Dispatcher.dispatch: type error (%r)', e)
+ m = args_re.match(unicode(e))
+ if m:
+ (quant, n_ok, n_bad) = m.groups()
+ n_ok = int(n_ok)
+ n_bad = int(n_bad)
+ n_ok -= 1
+ n_bad -= 1
+ pl = ''
+ if n_ok > 1:
+ pl = 's'
+ e = WrongArgumentsError(handler, u'takes %s %s argument%s, '
+ '%s given' % (quant, n_ok, pl, n_bad))
+ log.debug(u'Dispatcher.dispatch: wrong arguments (%r)', e)
+ raise e
+ m = kw_re.match(unicode(e))
+ if m:
+ (kw,) = m.groups()
+ e = WrongArgumentsError(handler,
+ u'got an unexpected keyword argument %s' % kw)
+ log.debug(u'Dispatcher.dispatch: wrong arguments (%r)', e)
+ raise e
+ log.debug(u'Dispatcher.dispatch: some other TypeError, re-raising')
+ raise