def to_text_string(obj, encoding=None):
 if PY2:
  if (encoding is None):
   return unicode(obj)
  else:
   return unicode(obj, encoding)
 elif (encoding is None):
  return str(obj)
 elif isinstance(obj, str):
  return obj
 else:
  return str(obj, encoding)

def to_text_string ( obj , encoding = None ) : if PY2 : if ( encoding is None ) : return unicode ( obj ) else : return unicode ( obj , encoding ) elif ( encoding is None ) : return str ( obj ) elif isinstance ( obj , str ) : return obj else : return str ( obj , encoding )
convert obj to text string .