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.
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
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.
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
'groupby': do_groupby,
'safe': do_mark_safe,
'xmlattr': do_xmlattr,
- 'urlescape': do_urlescape
+ 'urlencode': do_urlencode
}
tmpl = env.from_string('{{ "<div>foo</div>" }}')
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"
return Markup(u'\n'.join(u'<p>%s</p>' % 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.