diff options
-rw-r--r-- | routes/route.py | 10 | ||||
-rw-r--r-- | tests/test_functional/test_generation.py | 4 | ||||
-rw-r--r-- | tests/test_functional/test_recognition.py | 4 |
3 files changed, 14 insertions, 4 deletions
diff --git a/routes/route.py b/routes/route.py index 552f6b8..72009cd 100644 --- a/routes/route.py +++ b/routes/route.py @@ -174,15 +174,15 @@ class Route(object): elif collecting: collecting = False if var_type == '{': - opts = current.split(':') - if len(opts) > 1: - current = opts[0] - self.reqs[current] = opts[1] if current[0] == '.': var_type = '.' current = current[1:] else: var_type = ':' + opts = current.split(':') + if len(opts) > 1: + current = opts[0] + self.reqs[current] = opts[1] routelist.append(dict(type=var_type, name=current)) if char in self.done_chars: routelist.append(char) @@ -365,6 +365,8 @@ class Route(object): partreg = '(?P<%s>%s)' % (var, self.reqs[var]) else: partreg = '(?:%s)' % self.reqs[var] + if typ == '.': + partreg = '(?:\.%s)??' % partreg elif var == 'controller': if include_names: partreg = '(?P<%s>%s)' % (var, '|'.join(map(re.escape, clist))) diff --git a/tests/test_functional/test_generation.py b/tests/test_functional/test_generation.py index 9bff54a..6c40df1 100644 --- a/tests/test_functional/test_generation.py +++ b/tests/test_functional/test_generation.py @@ -631,9 +631,13 @@ class TestGeneration(unittest.TestCase): m = Mapper(explicit=True) m.minimization=minimization m.connect('/songs/{title}{.format}') + m.connect('/stories/{slug}{.format:pdf}') eq_('/songs/my-way', m.generate(title='my-way')) eq_('/songs/my-way.mp3', m.generate(title='my-way', format='mp3')) + eq_('/stories/frist-post', m.generate(slug='frist-post')) + eq_('/stories/frist-post.pdf', m.generate(slug='frist-post', format='pdf')) + eq_(None, m.generate(slug='frist-post', format='doc')) if __name__ == '__main__': unittest.main() diff --git a/tests/test_functional/test_recognition.py b/tests/test_functional/test_recognition.py index 9dcc861..bffe5b3 100644 --- a/tests/test_functional/test_recognition.py +++ b/tests/test_functional/test_recognition.py @@ -934,9 +934,13 @@ class TestRecognition(unittest.TestCase): m = Mapper(explicit=True) m.minimization=minimization m.connect('/songs/{title}{.format}') + m.connect('/stories/{slug:[^./]+?}{.format:pdf}') eq_({'title': 'my-way', 'format': None}, m.match('/songs/my-way')) eq_({'title': 'my-way', 'format': 'mp3'}, m.match('/songs/my-way.mp3')) + eq_({'slug': 'frist-post', 'format': None}, m.match('/stories/frist-post')) + eq_({'slug': 'frist-post', 'format': 'pdf'}, m.match('/stories/frist-post.pdf')) + eq_(None, m.match('/stories/frist-post.doc')) if __name__ == '__main__': |