def to_text_string(obj, encoding=None):
if PY2:<EOL><INDENT>if encoding is None:<EOL><INDENT>return unicode(obj)<EOL><DEDENT>else:<EOL><INDENT>return unicode(obj, encoding)<EOL><DEDENT><DEDENT>else:<EOL><INDENT>if encoding is None:<EOL><INDENT>return str(obj)<EOL><DEDENT>elif isinstance(obj, str):<EOL><INDENT>return obj<EOL><DEDENT>else:<EOL><INDENT>return str(obj, encoding)<EOL><DEDENT><DEDENT>
Convert `obj` to (unicode) text string