Slightly faster utf8 function

This commit is contained in:
Ben Darnell 2011-05-14 16:58:23 -07:00
parent eb1e5f08cb
commit 7f17ee1b35
1 changed files with 5 additions and 6 deletions

View File

@ -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