#NEWLINE# def safe_repr( obj , clip = None ) : #NEWLINE# #INDENT# "\n    Convert object to string representation, yielding the same result a `repr`\n    but catches all exceptions and returns 'N/A' instead of raising the\n    exception. Strings may be truncated by providing `clip`.\n\n    >>> safe_repr(42)\n    '42'\n    >>> safe_repr('Clipped text', clip=8)\n    'Clip..xt'\n    >>> safe_repr([1,2,3,4], clip=8)\n    '[1,2..4]'\n    " #NEWLINE# try : #NEWLINE# #INDENT# s = repr ( obj ) #NEWLINE# if ( ( not s ) or ( len ( s ) <= clip ) ) : #NEWLINE# #INDENT# return s #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# return ( ( s [ : ( clip - 4 ) ] + '..' ) + s [ ( - 2 ) : ] ) #NEWLINE# #UNINDENT# #UNINDENT# except : #NEWLINE# #INDENT# return 'N/A'