Beispiel #1
0
 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
Beispiel #2
0
    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'])
Beispiel #3
0
 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'})
Beispiel #4
0
 def testName(self):
     route = Route(_pass, '/foo')
     self.assertEquals(_pass.__name__, route.__name__)
Beispiel #5
0
 def testRepr(self):
     route = Route(_pass, '/foo')
     self.assertEquals(repr(route), u'Route(_pass, /foo)')
Beispiel #6
0
 def testInit(self):
     route = Route(_pass, '/foo')
     self.assertEquals(route.handler, _pass)
     self.assertEquals(route.path, '/foo')