code: def ustr(obj):
      
      if sys.version_info[0] == 2:
          # If we are getting a string, then do an explicit decode
          # else, just call the unicode method of the object
          if type(obj) in [str, basestring]:  # pragma: no cover # noqa
              return unicode(obj, DEFAULT_ENCODING)  # pragma: no cover # noqa
          else:
              return unicode(obj)  # pragma: no cover # noqa
      else:
          if type(obj) in [bytes]:
              return obj.decode(DEFAULT_ENCODING)
          else:
              return str(obj)
docs: Python 2 and 3 utility method that converts an obj to unicode in python 2 and to a str object in python 3