summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bangert <ben@groovie.org>2013-11-20 13:32:48 -0800
committerBen Bangert <ben@groovie.org>2013-11-20 13:32:48 -0800
commit0495657db81fbbe4090c0268a903506569656d06 (patch)
tree44f6117328d4c8913d7e9b9e61be9db9e7677650
parent1f82563b14861a018ccc598d643c3d6b9045fdc2 (diff)
parent1500bccdaea597b163da66acbc4eb04484d86ffa (diff)
downloadroutes-0495657db81fbbe4090c0268a903506569656d06.tar.gz
Merge pull request #14 from blamarvt/overflow-fix
Allow for a large number of URL matches
-rw-r--r--routes/mapper.py17
-rw-r--r--tests/test_functional/test_utils.py6
2 files changed, 19 insertions, 4 deletions
diff --git a/routes/mapper.py b/routes/mapper.py
index ecabe89..69984be 100644
--- a/routes/mapper.py
+++ b/routes/mapper.py
@@ -596,7 +596,10 @@ class Mapper(SubMapperParent):
# Save the master regexp
regexp = '|'.join(['(?:%s)' % x for x in regexps])
self._master_reg = regexp
- self._master_regexp = re.compile(regexp)
+ try:
+ self._master_regexp = re.compile(regexp)
+ except OverflowError:
+ self._master_regexp = None
self._created_regs = True
def _match(self, url, environ):
@@ -633,9 +636,15 @@ class Mapper(SubMapperParent):
domain_match = self.domain_match
debug = self.debug
- # Check to see if its a valid url against the main regexp
- # Done for faster invalid URL elimination
- valid_url = re.match(self._master_regexp, url)
+ if self._master_regexp is not None:
+ # Check to see if its a valid url against the main regexp
+ # Done for faster invalid URL elimination
+ valid_url = re.match(self._master_regexp, url)
+ else:
+ # Regex is None due to OverflowError caused by too many routes.
+ # This will allow larger projects to work but might increase time
+ # spent invalidating URLs in the loop below.
+ valid_url = True
if not valid_url:
return (None, None, matchlog)
diff --git a/tests/test_functional/test_utils.py b/tests/test_functional/test_utils.py
index dfb1b90..e952baf 100644
--- a/tests/test_functional/test_utils.py
+++ b/tests/test_functional/test_utils.py
@@ -158,6 +158,12 @@ class TestUtils(unittest.TestCase):
eq_('/post/index/4', url.current(controller='post'))
eq_('http://www.example.com:8080/blog/view/4', url.current(qualified=True))
+ def test_route_overflow(self):
+ m = self.con.mapper
+ m.create_regs(["x"*50000])
+ m.connect('route-overflow', "x"*50000)
+ url = URLGenerator(m, {})
+ eq_("/%s" % ("x"*50000), url('route-overflow'))
def test_with_route_names(self):
m = self.con.mapper