"""
import re
import math
+import urllib
from random import choice
from operator import itemgetter
from itertools import imap, groupby
value = value.__html__()
return escape(unicode(value))
+def do_urlescape(value):
+ """Escape for use in URLs."""
+ return urllib.quote(value.encode('utf8'))
@evalcontextfilter
def do_replace(eval_ctx, s, old, new, count=None):
'round': do_round,
'groupby': do_groupby,
'safe': do_mark_safe,
- 'xmlattr': do_xmlattr
+ 'xmlattr': do_xmlattr,
+ 'urlescape': do_urlescape,
+ 'urle': do_urlescape,
+ 'urlencode': do_urlescape,
+ 'urlquote': do_urlescape
}
assert tmpl.render() == '<div>foo</div>'
tmpl = env.from_string('{{ "<div>foo</div>" }}')
assert tmpl.render() == '<div>foo</div>'
-
+
+ def test_urlescape(self):
+ env = Environment(autoescape=True)
+ tmpl = env.from_string('{{ "Hello, world!"|urle }}')
+ assert tmpl.render() == 'Hello%2C%20world%21'
def suite():
suite = unittest.TestSuite()