From: Armin Ronacher Date: Sat, 7 Jan 2012 16:47:56 +0000 (+0100) Subject: Renamed urlescape to urlencode X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5145401fe5f9995a32757f34359623b87048ab8b;p=jinja2.git Renamed urlescape to urlencode --- diff --git a/CHANGES b/CHANGES index 8838a21..a48208a 100644 --- a/CHANGES +++ b/CHANGES @@ -10,7 +10,7 @@ Version 2.7 advertised. - Fixed filesizeformat. - Added a non-silent option for babel extraction. -- Added `urlescape` filter that automatically quotes values for +- Added `urlencode` filter that automatically quotes values for URL safe usage with utf-8 as only supported encoding. If applications want to change this encoding they can override the filter. diff --git a/jinja2/filters.py b/jinja2/filters.py index bbe5a8c..8dd6ff0 100644 --- a/jinja2/filters.py +++ b/jinja2/filters.py @@ -14,7 +14,7 @@ from random import choice from operator import itemgetter from itertools import imap, groupby from jinja2.utils import Markup, escape, pformat, urlize, soft_unicode, \ - unicode_urlescape + unicode_urlencode from jinja2.runtime import Undefined from jinja2.exceptions import FilterArgumentError @@ -71,7 +71,7 @@ def do_forceescape(value): return escape(unicode(value)) -def do_urlescape(value): +def do_urlencode(value): """Escape strings for use in URLs (uses UTF-8 encoding). It accepts both dictionaries and regular strings as well as pairwise iterables. @@ -86,9 +86,9 @@ def do_urlescape(value): except TypeError: pass if itemiter is None: - return unicode_urlescape(value) - return u'&'.join(unicode_urlescape(k) + '=' + - unicode_urlescape(v) for k, v in itemiter) + return unicode_urlencode(value) + return u'&'.join(unicode_urlencode(k) + '=' + + unicode_urlencode(v) for k, v in itemiter) @evalcontextfilter @@ -819,5 +819,5 @@ FILTERS = { 'groupby': do_groupby, 'safe': do_mark_safe, 'xmlattr': do_xmlattr, - 'urlescape': do_urlescape + 'urlencode': do_urlencode } diff --git a/jinja2/testsuite/filters.py b/jinja2/testsuite/filters.py index 15451e5..94bc02a 100644 --- a/jinja2/testsuite/filters.py +++ b/jinja2/testsuite/filters.py @@ -367,11 +367,11 @@ class FilterTestCase(JinjaTestCase): tmpl = env.from_string('{{ "
foo
" }}') assert tmpl.render() == '<div>foo</div>' - def test_urlescape(self): + def test_urlencode(self): env = Environment(autoescape=True) - tmpl = env.from_string('{{ "Hello, world!"|urlescape }}') + tmpl = env.from_string('{{ "Hello, world!"|urlencode }}') assert tmpl.render() == 'Hello%2C%20world%21' - tmpl = env.from_string('{{ o|urlescape }}') + tmpl = env.from_string('{{ o|urlencode }}') assert tmpl.render(o=u"Hello, world\u203d") == "Hello%2C%20world%E2%80%BD" assert tmpl.render(o=(("f", 1),)) == "f=1" assert tmpl.render(o=(('f', 1), ("z", 2))) == "f=1&z=2" diff --git a/jinja2/utils.py b/jinja2/utils.py index 1554a14..1e0bb81 100644 --- a/jinja2/utils.py +++ b/jinja2/utils.py @@ -353,7 +353,7 @@ def generate_lorem_ipsum(n=5, html=True, min=20, max=100): return Markup(u'\n'.join(u'

%s

' % escape(x) for x in result)) -def unicode_urlescape(obj, charset='utf-8'): +def unicode_urlencode(obj, charset='utf-8'): """URL escapes a single bytestring or unicode string with the given charset if applicable to URL safe quoting under all rules that need to be considered under all supported Python versions.