#NEWLINE# def _safe_str( s , errors = 'replace' , file = None ) : #NEWLINE# #INDENT# encoding = default_encoding ( file ) #NEWLINE# try : #NEWLINE# #INDENT# if isinstance ( s , unicode ) : #NEWLINE# #INDENT# return s . encode ( encoding , errors ) #NEWLINE# #UNINDENT# return unicode ( s , encoding , errors ) #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 ( ) ) )