From b8fc93e83a646adbe83781feccc1d106310a79f2 Mon Sep 17 00:00:00 2001 From: Chris McDonough Date: Thu, 17 Feb 2011 01:54:04 -0500 Subject: Undo the inner squiggly regex fix introduced in commit #9595236 because the regex breaks on Jython. See https://github.com/Pylons/pyramid/issues/#issue/123 --- CHANGES.txt | 13 ------------- pyramid/tests/test_urldispatch.py | 26 ++++++++++++++------------ pyramid/urldispatch.py | 21 +++++++++++++++------ 3 files changed, 29 insertions(+), 31 deletions(-) diff --git a/CHANGES.txt b/CHANGES.txt index 9a78dcbee..be295a51d 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -1,19 +1,6 @@ Next release ============ -Bug Fixes ---------- - -- URL pattern markers used in URL dispatch are permitted to specify a custom - regex. For example, the pattern ``/{foo:\d+}`` means to match ``/12345`` - (foo==12345 in the match dictionary) but not ``/abc``. However, custom - regexes in a pattern marker which used squiggly brackets did not work. For - example, ``/{foo:\d{4}}`` would fail to match ``/1234`` and - ``/{foo:\d{1,2}}`` would fail to match ``/1`` or ``/11``. One level of - inner squiggly brackets is now recognized so that the prior two patterns - given as examples now work. See also - https://github.com/Pylons/pyramid/issues/#issue/123. - Features -------- diff --git a/pyramid/tests/test_urldispatch.py b/pyramid/tests/test_urldispatch.py index eca4603a3..82ecd2b79 100644 --- a/pyramid/tests/test_urldispatch.py +++ b/pyramid/tests/test_urldispatch.py @@ -271,18 +271,20 @@ class TestCompileRoute(unittest.TestCase): self.assertEqual(generator({'baz':1, 'buz':2, 'bar': 'html'}), '/foo/1/biz/2.html') - def test_custom_regex_with_embedded_squigglies(self): - matcher, generator = self._callFUT('/{buz:\d{4}}') - self.assertEqual(matcher('/2001'), {'buz':'2001'}) - self.assertEqual(matcher('/200'), None) - self.assertEqual(generator({'buz':2001}), '/2001') - - def test_custom_regex_with_embedded_squigglies2(self): - matcher, generator = self._callFUT('/{buz:\d{3,4}}') - self.assertEqual(matcher('/2001'), {'buz':'2001'}) - self.assertEqual(matcher('/200'), {'buz':'200'}) - self.assertEqual(matcher('/20'), None) - self.assertEqual(generator({'buz':2001}), '/2001') + # XXX reenable after torturous_route_re replacement is found for + # Jython + ## def test_custom_regex_with_embedded_squigglies(self): + ## matcher, generator = self._callFUT('/{buz:\d{4}}') + ## self.assertEqual(matcher('/2001'), {'buz':'2001'}) + ## self.assertEqual(matcher('/200'), None) + ## self.assertEqual(generator({'buz':2001}), '/2001') + + ## def test_custom_regex_with_embedded_squigglies2(self): + ## matcher, generator = self._callFUT('/{buz:\d{3,4}}') + ## self.assertEqual(matcher('/2001'), {'buz':'2001'}) + ## self.assertEqual(matcher('/200'), {'buz':'200'}) + ## self.assertEqual(matcher('/20'), None) + ## self.assertEqual(generator({'buz':2001}), '/2001') class TestCompileRouteMatchFunctional(unittest.TestCase): def matches(self, pattern, path, expected): diff --git a/pyramid/urldispatch.py b/pyramid/urldispatch.py index d6566629d..c4c72362e 100644 --- a/pyramid/urldispatch.py +++ b/pyramid/urldispatch.py @@ -76,12 +76,21 @@ class RoutesMapper(object): # stolen from bobo and modified old_route_re = re.compile(r'(\:[a-zA-Z]\w*)') star_in_brackets = re.compile(r'\{[^\}]*\*\w*[^\}]*\}') -# The torturous nature of the regex named ``route_re`` below is due to the -# fact that we need to support at least one level of "inner" squigglies -# inside the expr of a {name:expr} pattern. This regex used to be just -# (\{[a-zA-Z][^\}]*\}) but that choked when supplied with e.g. {foo:\d{4}}. -# Thanks to Zart for the regex help. -route_re = re.compile(r'(\{[a-zA-Z](?:\{[^\}]*\}|[^\{\}]*)*\})') + +# The regex named ``torturous_route_re`` below allows us to support at least +# one level of "inner" squigglies inside the expr of a {name:expr} pattern; +# for example, {foo:\d{4}}. Thanks to Zart for the regex help. +# ``torturous_route_re`` is meant to be a replacement for the regex named +# ``route_re`` (which is just (\{[a-zA-Z][^\}]*\})) because ``route_re`` +# chokes when it encounters inner squigglies. However +# http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507 means that the +# torturous regex doesn't work on Jython (recursion error), so we've disabled +# it in favor of ``route_re`` for now. If somebody can make something that +# will work on Jython but also match inner squigglies, it'd be useful. + +# torturous_route_re = re.compile(r'(\{[a-zA-Z](?:\{[^\}]*\}|[^\{\}]*)*\})') + +route_re = re.compile(r'(\{[a-zA-Z][^\}]*\})') def update_pattern(matchobj): name = matchobj.group(0) -- cgit v1.2.3