Skip to content

Commit

Permalink
Normalize to styleguide
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuhiko committed Jan 7, 2012
1 parent c299ff1 commit f2feb7e
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions jinja2/filters.py
Expand Up @@ -70,23 +70,25 @@ def do_forceescape(value):
value = value.__html__()
return escape(unicode(value))


def do_urlescape(value):
"""Escape strings for use in URLs (uses UTF-8 encoding)."""
def utf8(o):
return unicode(o).encode('utf8')

if isinstance(value, basestring):
return urllib.quote(utf8(value))

if hasattr(value, 'items'):
# convert dictionaries to list of 2-tuples
value = value.items()

if hasattr(value, 'next'):
# convert generators to list
value = list(value)

return urllib.urlencode([(utf8(k), utf8(v)) for (k, v) in value])

return urllib.urlencode((utf8(k), utf8(v)) for (k, v) in value)


@evalcontextfilter
def do_replace(eval_ctx, s, old, new, count=None):
Expand Down

0 comments on commit f2feb7e

Please sign in to comment.