summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBen Bangert <ben@groovie.org>2010-02-28 14:37:05 -0800
committerBen Bangert <ben@groovie.org>2010-02-28 14:37:05 -0800
commit544fb83fe3cc4df3e5295b71b205c611c4c1dd5a (patch)
treef632da5852876527ffb419b1714250ef93713f41
parent75c770d5c7f7bf1ff93b006dd663dd78cd87a14b (diff)
downloadroutes-544fb83fe3cc4df3e5295b71b205c611c4c1dd5a.tar.gz
* Fix url.current() not returning current args when explicit is True.
* Return explicit to being default to True. --HG-- branch : trunk
-rw-r--r--CHANGELOG1
-rw-r--r--routes/mapper.py2
-rw-r--r--routes/util.py10
-rw-r--r--tests/test_functional/test_explicit_use.py11
4 files changed, 19 insertions, 5 deletions
diff --git a/CHANGELOG b/CHANGELOG
index 5cd8090..fd1140d 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -3,6 +3,7 @@ Routes Changelog
Release 1.12 (**tip**)
======================
+* Fix url.current() not returning current args when explicit is True.
* Added explicit way to directly use the Mapper to match with environ.
* Fix bug with improper len placement for submapper.
* Adding regular expression builder for entire regexp for faster rejection
diff --git a/routes/mapper.py b/routes/mapper.py
index d37a011..65ed7a0 100644
--- a/routes/mapper.py
+++ b/routes/mapper.py
@@ -293,7 +293,7 @@ class Mapper(SubMapperParent):
"""
def __init__(self, controller_scan=controller_scan, directory=None,
- always_scan=False, register=True, explicit=False):
+ always_scan=False, register=True, explicit=True):
"""Create a new Mapper instance
All keyword arguments are optional.
diff --git a/routes/util.py b/routes/util.py
index f56e9ab..71bdf1d 100644
--- a/routes/util.py
+++ b/routes/util.py
@@ -23,7 +23,7 @@ class GenerationException(RoutesException):
"""Tossed during URL generation exceptions"""
-def _screenargs(kargs, mapper, environ):
+def _screenargs(kargs, mapper, environ, force_explicit=False):
"""
Private function that takes a dict, and screens it against the current
request dict to determine what the dict should look like that is used.
@@ -35,9 +35,9 @@ def _screenargs(kargs, mapper, environ):
if isinstance(val, unicode):
kargs[key] = val.encode(encoding)
- if mapper.explicit and mapper.sub_domains:
+ if mapper.explicit and mapper.sub_domains and not force_explicit:
return _subdomain_check(kargs, mapper, environ)
- elif mapper.explicit:
+ elif mapper.explicit and not force_explicit:
return kargs
controller_name = kargs.get('controller')
@@ -53,6 +53,8 @@ def _screenargs(kargs, mapper, environ):
route_args = environ.get('wsgiorg.routing_args')
if route_args:
memory_kargs = route_args[1].copy()
+ else:
+ memory_kargs = {}
# Remove keys from memory and kargs if kargs has them as None
for key in [key for key in kargs.keys() if kargs[key] is None]:
@@ -372,7 +374,7 @@ class URLGenerator(object):
newargs = _subdomain_check(newargs, self.mapper,
self.environ)
elif use_current:
- newargs = _screenargs(kargs, self.mapper, self.environ)
+ newargs = _screenargs(kargs, self.mapper, self.environ, force_explicit=True)
elif 'sub_domain' in kargs:
newargs = _subdomain_check(kargs, self.mapper, self.environ)
else:
diff --git a/tests/test_functional/test_explicit_use.py b/tests/test_functional/test_explicit_use.py
index 539d54f..359b6b0 100644
--- a/tests/test_functional/test_explicit_use.py
+++ b/tests/test_functional/test_explicit_use.py
@@ -71,3 +71,14 @@ class TestUtils(unittest.TestCase):
url = URLGenerator(m, {})
eq_('/here?q=fred&q=here%20now', url('/here', q=[u'fred', 'here now']))
+
+ def test_current(self):
+ m = Mapper()
+ m.explicit = True
+ m.connect('/hi/{fred}')
+
+ environ = {'HTTP_HOST': 'localhost.com', 'PATH_INFO': '/hi/smith'}
+ match = m.routematch(environ=environ)[0]
+ environ['wsgiorg.routing_args'] = (None, match)
+ url = URLGenerator(m, environ)
+ eq_('/hi/smith', url.current())