Permalink
Browse files

Minor speed tweaks.

  • Loading branch information...
Chris McDonough
Chris McDonough committed Sep 20, 2009
1 parent 9912472 commit f646fe5800d1129ae79944956e125f51611350b1
Showing with 13 additions and 20 deletions.
  1. +8 −12 repoze/bfg/tests/test_urldispatch.py
  2. +5 −8 repoze/bfg/urldispatch.py
@@ -10,34 +10,30 @@ def _makeOne(self, *arg):
return self._getTargetClass()(*arg)
def test_ctor(self):
+ import types
route = self._makeOne(':path', 'name', 'factory')
self.assertEqual(route.path, ':path')
self.assertEqual(route.name, 'name')
self.assertEqual(route.factory, 'factory')
- self.failUnless(route.generator)
- self.failUnless(route.matcher)
+ self.failUnless(route.generate.__class__ is types.FunctionType)
+ self.failUnless(route.match.__class__ is types.FunctionType)
def test_ctor_defaults(self):
+ import types
route = self._makeOne(':path')
self.assertEqual(route.path, ':path')
self.assertEqual(route.name, None)
self.assertEqual(route.factory, None)
- self.failUnless(route.generator)
- self.failUnless(route.matcher)
+ self.failUnless(route.generate.__class__ is types.FunctionType)
+ self.failUnless(route.match.__class__ is types.FunctionType)
def test_match(self):
- def matcher(path):
- return 123
route = self._makeOne(':path')
- route.matcher = matcher
- self.assertEqual(route.match('whatever'), 123)
+ self.assertEqual(route.match('/whatever'), {'path':'whatever'})
def test_generate(self):
- def generator(path):
- return 123
route = self._makeOne(':path')
- route.generator = generator
- self.assertEqual(route.generate({}), 123)
+ self.assertEqual(route.generate({'path':'abc'}), '/abc')
class RoutesRootFactoryTests(unittest.TestCase):
def setUp(self):
View
@@ -10,16 +10,10 @@
class Route(object):
def __init__(self, path, name=None, factory=None):
self.path = path
- self.matcher, self.generator = _compile_route(path)
+ self.match, self.generate = _compile_route(path)
self.name = name
self.factory = factory
- def match(self, path):
- return self.matcher(path)
-
- def generate(self, kw):
- return self.generator(kw)
-
class RoutesRootFactory(object):
def __init__(self, default_root_factory):
self.default_root_factory = default_root_factory
@@ -42,7 +36,10 @@ def generate(self, name, kw):
return self.routes[name].generate(kw)
def __call__(self, environ):
- path = environ.get('PATH_INFO', '/')
+ try:
+ path = environ['PATH_INFO']
+ except KeyError:
+ path = '/'
for route in self.routelist:
match = route.match(path)
if match is not None:

0 comments on commit f646fe5

Please sign in to comment.