code: def _safe_unicode(o):
      
      def clean(s):
          return u''.join([c if c in ASCII_PRINTABLE else '?' for c in s])
      if USING_PYTHON2:
          try:
              return unicode(o)
          except:
              try:
                  s = str(o)
                  try:
                      return s.decode("utf-8")
                  except:
                      return clean(s[:2048]) + u" [Raw error message: " + unicode(s.encode("hex"), 'utf-8') + u"]"
              except:
                  return u"(Unable to decode Python exception message)"
      else:
          return str(o)
docs: Returns an equivalent unicode object, trying harder to avoid
      dependencies on the Python default encoding.