def safe_repr(obj, short=False):
try:<EOL><INDENT>result = repr(obj)<EOL><DEDENT>except Exception:<EOL><INDENT>result = object.__repr__(obj)<EOL><DEDENT>if not short or len(result) < pkg_resources._MAX_LENGTH:<EOL><INDENT>return result<EOL><DEDENT>return result[:pkg_resources._MAX_LENGTH] + '<STR_LIT>'<EOL>
copied from Python2.7