def __bytes__(self): try: return self._value.encode(self.encoding) except UnicodeEncodeError: exc = sys.exc_info()[1] raise error.PyAsn1UnicodeEncodeError( "Can't encode string '%s' with codec " "%s" % (self._value, self.encoding), exc)
def __str__(self): try: # `str` is Py2 text representation return self._value.encode(self.encoding) except UnicodeEncodeError: exc = sys.exc_info()[1] raise error.PyAsn1UnicodeEncodeError( "Can't encode string '%s' with codec " "%s" % (self._value, self.encoding), exc)