code: def ensure_unicode(text):
      r
      if isinstance(text, six.text_type):
          return text
      elif isinstance(text, six.binary_type):
          return text.decode('utf8')
      else:  # nocover
          raise ValueError('unknown input type {!r}'.format(text))
docs: r"""
      Casts bytes into utf8 (mostly for python2 compatibility)
  
      References:
          http://stackoverflow.com/questions/12561063/extract-data-from-file
  
      Example:
          >>> from ubelt.util_str import *
          >>> import codecs  # NOQA
          >>> assert ensure_unicode('my ünicôdé strįng') == 'my ünicôdé strįng'
          >>> assert ensure_unicode('text1') == 'text1'
          >>> assert ensure_unicode('text1'.encode('utf8')) == 'text1'
          >>> assert ensure_unicode('ï»¿text1'.encode('utf8')) == 'ï»¿text1'
          >>> assert (codecs.BOM_UTF8 + 'text»¿'.encode('utf8')).decode('utf8')