diff options
author | bbangert <none@none> | 2006-03-17 13:09:20 -0800 |
---|---|---|
committer | bbangert <none@none> | 2006-03-17 13:09:20 -0800 |
commit | a8665d74dc7684929d823edadb1d5c6e04b18f80 (patch) | |
tree | 0f19fcebe70af7e38fb1dd0b22e076141632083f | |
parent | f59225bc817ff42269ded72163cdd6cbd0cf3a6a (diff) | |
download | routes-a8665d74dc7684929d823edadb1d5c6e04b18f80.tar.gz |
[svn] Added mapper support for append_slash which is used to determine if a slash will be appended during URL generation.
--HG--
branch : trunk
-rw-r--r-- | routes/base.py | 1 | ||||
-rw-r--r-- | routes/util.py | 2 | ||||
-rw-r--r-- | tests/test_utils.py | 16 |
3 files changed, 19 insertions, 0 deletions
diff --git a/routes/base.py b/routes/base.py index 7d8834f..814a99e 100644 --- a/routes/base.py +++ b/routes/base.py @@ -444,6 +444,7 @@ class Mapper(object): self._regprefix = None self._routenames = {} self.debug = False + self.append_slash = False if register: config = request_config() config.mapper = self diff --git a/routes/util.py b/routes/util.py index 6f81ec2..2cb80be 100644 --- a/routes/util.py +++ b/routes/util.py @@ -115,6 +115,8 @@ def url_for(*args, **kargs): else: newargs = _screenargs(kargs) url = config.mapper.generate(**newargs) + if config.mapper.append_slash and not url.endswith('/'): + url += '/' if anchor: url += '#' + _url_quote(anchor) if host or protocol: if not host: host = config.host diff --git a/tests/test_utils.py b/tests/test_utils.py index c1fcbab..e514015 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -176,6 +176,22 @@ class TestUtils(unittest.TestCase): self.assertEqual('http://www.google.com/search?q=routes', url_for('http://www.google.com/search', q='routes')) self.assertEqual('/delicious.jpg', url_for('/delicious.jpg')) self.assertEqual('/delicious/search?v=routes', url_for('/delicious/search', v='routes')) + + def test_append_slash(self): + m = self.con.mapper + self.con.mapper_dict = {} + m.append_slash = True + self.con.environ = dict(SCRIPT_NAME='', SERVER_NAME='example.com') + m.connect(':controller/:action/:id') + m.connect('home', 'http://www.groovie.org/', _static=True) + m.connect('space', '/nasa/images', _static=True) + m.create_regs(['content', 'blog']) + + self.assertEqual('http://www.google.com/search', url_for('http://www.google.com/search')) + self.assertEqual('http://www.google.com/search?q=routes', url_for('http://www.google.com/search', q='routes')) + self.assertEqual('/delicious.jpg', url_for('/delicious.jpg')) + self.assertEqual('/delicious/search?v=routes', url_for('/delicious/search', v='routes')) + self.assertEqual('/content/list/', url_for(controller='/content', action='list')) def test_no_named_path_with_script(self): m = self.con.mapper |