utils: remove use of assert
When code is optimized, the assertion will be removed. Change-Id: I3d313ef637646ca10b721acd3bf91795ed2a3293
This commit is contained in:
parent
6f9cafae8e
commit
6ff6a3147a
13
ooi/utils.py
13
ooi/utils.py
|
@ -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):
|
||||
|
|
Loading…
Reference in New Issue