#NEWLINE# def _safe_str( s , errors = 'replace' , file = None ) : #NEWLINE# #INDENT# if isinstance ( s , str ) : #NEWLINE# #INDENT# return s #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# return str ( s ) #NEWLINE# #UNINDENT# except Exception as exc : #NEWLINE# #INDENT# return '<Unrepresentable {0!r}: {1!r} {2!r}>' . format ( type ( s ) , exc , '\n' . join ( traceback . format_stack ( ) ) )