code: def str_or_unicode(text):
      
      encoding = sys.stdout.encoding
      if sys.version_info > (3, 0):
          return text.encode(encoding).decode(encoding)
      return text.encode(encoding)
docs: handle python 3 unicode and python 2.7 byte strings