def decorator(func): """ See the pyroutes.route-docstring """ if path in __request__handlers__: raise ValueError("Tried to redefine handler for %s with %s" % \ (path, func)) route_instance = Route(func, path, *args, **kwargs) __request__handlers__[path] = route_instance return route_instance
def testExtractUrlParams(self): route = Route(_pass, '/foo') env = {'PATH_INFO': '/foo/foo/faz'} def test(req, bar, baz): pass self.assertEquals(route.extract_url_params(env), ['foo', 'faz']) route_instance = Route(_pass, '/') env = {'PATH_INFO': '/foo/foo'} self.assertEquals(route_instance.extract_url_params(env), ['foo', 'foo']) route_instance = Route(_pass, '/xim') env = {'PATH_INFO': '/xim/foo/bar'} self.assertEquals(route.extract_url_params(env), ['foo', 'bar'])
def testExtractUrlParams(self): route = Route(_pass, '/foo') env = {'PATH_INFO': '/foo/foo/faz'} def test(req, bar, baz): pass self.assertEquals(route.extract_url_params(test, env), {'bar': 'foo', 'baz': 'faz'})
def testName(self): route = Route(_pass, '/foo') self.assertEquals(_pass.__name__, route.__name__)
def testRepr(self): route = Route(_pass, '/foo') self.assertEquals(repr(route), u'Route(_pass, /foo)')
def testInit(self): route = Route(_pass, '/foo') self.assertEquals(route.handler, _pass) self.assertEquals(route.path, '/foo')