summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbbangert <none@none>2006-10-31 10:04:45 -0800
committerbbangert <none@none>2006-10-31 10:04:45 -0800
commite6253c47450b956050c655c95566d5bd15ead1ac (patch)
tree589c9fd9047772de107552dd98fd344fb55227f8
parent30334e7c18ca72ae2415f9fac10cc213feb2db3f (diff)
downloadroutes-e6253c47450b956050c655c95566d5bd15ead1ac.tar.gz
[svn] * Added _absolute keyword option route connect to ignore SCRIPT_NAME settings.
Suggested by Ian Bicking. --HG-- branch : trunk
-rw-r--r--CHANGELOG3
-rw-r--r--routes/base.py4
-rw-r--r--tests/test_functional/test_generation.py13
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()