Skip to content

Commit

Permalink
Slightly faster utf8 function
Browse files Browse the repository at this point in the history
  • Loading branch information
bdarnell committed May 14, 2011
1 parent eb1e5f0 commit 7f17ee1
Showing 1 changed file with 5 additions and 6 deletions.
11 changes: 5 additions & 6 deletions tornado/escape.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,13 +92,12 @@ def url_unescape(value):
return _unicode(urllib.unquote_plus(value))


_UTF8_TYPES = (bytes, type(None))
def utf8(value):
if value is None:
return None
if isinstance(value, unicode):
return value.encode("utf-8")
assert isinstance(value, bytes)
return value
if isinstance(value, _UTF8_TYPES):
return value
assert isinstance(value, unicode)
return value.encode("utf-8")


# I originally used the regex from
Expand Down

0 comments on commit 7f17ee1

Please sign in to comment.