utils: remove use of assert

When code is optimized, the assertion will be removed.

Change-Id: I3d313ef637646ca10b721acd3bf91795ed2a3293
This commit is contained in:
Alvaro Lopez Garcia 2016-11-21 14:49:37 +01:00
parent 6f9cafae8e
commit 6ff6a3147a
1 changed files with 8 additions and 5 deletions

View File

@ -22,14 +22,17 @@ import six.moves.urllib.parse as urlparse
def utf8(value):
"""Try to turn a string into utf-8 if possible.
Code is modified from the utf8 function in
The original code was copied from the utf8 function in
http://github.com/facebook/tornado/blob/master/tornado/escape.py
"""
if isinstance(value, six.text_type):
return value.encode('utf-8')
assert isinstance(value, str)
return value
if value is None or isinstance(value, six.binary_type):
return value
if not isinstance(value, six.text_type):
value = six.text_type(value)
return value.encode('utf-8')
def join_url(base, parts):