(value)
return repr(value)
Safely convert object to text
Safely convert object to text
Safely convert object to text
def as_text(value):
    """Safely convert object to text"""
    if isinstance(value, str):
        return value
    if isinstance(value, bytes):
        return value.decode("utf8", errors="backslashreplace")
    if isinstance(value, BaseException):
        lines = format_exception_only(type(value), value)
        return "\n".join(x.rstrip("\n") for x in lines)
    return repr(value)
def as_text ( value ) : if isinstance ( value , str ) : return value if isinstance ( value , bytes ) : return value . decode ( "utf8" , errors = "backslashreplace" ) if isinstance ( value , BaseException ) : lines = format_exception_only ( type ( value ) , value ) return "\n" . join ( x . rstrip ( "\n" ) for x in lines ) return repr ( value )