Slightly faster utf8 function
This commit is contained in:
parent
eb1e5f08cb
commit
7f17ee1b35
|
@ -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)
|
||||
if isinstance(value, _UTF8_TYPES):
|
||||
return value
|
||||
assert isinstance(value, unicode)
|
||||
return value.encode("utf-8")
|
||||
|
||||
|
||||
# I originally used the regex from
|
||||
|
|
Loading…
Reference in New Issue