From e6253c47450b956050c655c95566d5bd15ead1ac Mon Sep 17 00:00:00 2001 From: bbangert Date: Tue, 31 Oct 2006 10:04:45 -0800 Subject: [svn] * Added _absolute keyword option route connect to ignore SCRIPT_NAME settings. Suggested by Ian Bicking. --HG-- branch : trunk --- CHANGELOG | 3 ++- routes/base.py | 4 +++- tests/test_functional/test_generation.py | 13 +++++++++++++ 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index e3439b7..d792a06 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,7 +2,8 @@ Routes Changelog ======================== -- 1.5.3 (**svn**) - +* Added _absolute keyword option route connect to ignore SCRIPT_NAME settings. + Suggested by Ian Bicking. -- 1.5.2 (Oct. 16th, 2006) * Fixed qualified keyword to keep host port names when used, unless a host diff --git a/routes/base.py b/routes/base.py index 300f99a..9a8512e 100644 --- a/routes/base.py +++ b/routes/base.py @@ -54,6 +54,7 @@ class Route(object): # Don't bother forming stuff we don't need if its a static route self.static = kargs.get('_static', False) self.filter = kargs.pop('_filter', None) + self.absolute = kargs.pop('_absolute', False) # Pull out route conditions self.conditions = kargs.pop('conditions', None) @@ -783,7 +784,8 @@ class Mapper(object): if path: if self.prefix: path = self.prefix + path - if self.environ and self.environ.get('SCRIPT_NAME', '') != '': + if self.environ and self.environ.get('SCRIPT_NAME', '') != '' \ + and not route.absolute: path = self.environ['SCRIPT_NAME'] + path if self.urlcache is not None: self.urlcache[str(kargs)] = path diff --git a/tests/test_functional/test_generation.py b/tests/test_functional/test_generation.py index 64f7326..7ba07ce 100644 --- a/tests/test_functional/test_generation.py +++ b/tests/test_functional/test_generation.py @@ -453,6 +453,19 @@ class TestGeneration(unittest.TestCase): assert '/blog/content' == m.generate(controller='content') assert '/blog/content' == m.generate(controller='content') assert '/blog/admin/comments' == m.generate(controller='admin/comments') + + def test_url_with_environ_and_absolute(self): + m = Mapper() + m.environ = dict(SCRIPT_NAME='/blog') + m.connect('image', 'image/:name', _absolute=True) + m.connect(':controller/:action/:id') + m.create_regs(['content','blog','admin/comments']) + + assert '/blog/content/view' == m.generate(controller='content', action='view') + assert '/blog/content' == m.generate(controller='content') + assert '/blog/content' == m.generate(controller='content') + assert '/blog/admin/comments' == m.generate(controller='admin/comments') + assert '/image/topnav.jpg' == url_for('image', name='topnav.jpg') def test_route_with_odd_leftovers(self): m = Mapper() -- cgit v1.2.1