Merge "utils: remove use of assert"

This commit is contained in:
Jenkins 2016-11-29 22:14:22 +00:00 committed by Gerrit Code Review
commit f1389f3179
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):