def _format_assertmsg(obj):
<EOL>replaces = [(u"<STR_LIT:\n>", u"<STR_LIT>"), (u"<STR_LIT:%>", u"<STR_LIT>")]<EOL>if not isinstance(obj, six.string_types):<EOL><INDENT>obj = saferepr(obj)<EOL>replaces.append((u"<STR_LIT>", u"<STR_LIT>"))<EOL><DEDENT>if isinstance(obj, bytes):<EOL><INDENT>replaces = [(r1.encode(), r2.encode()) for r1, r2 in replaces]<EOL><DEDENT>for r1, r2 in replaces:<EOL><INDENT>obj = obj.replace(r1, r2)<EOL><DEDENT>return obj<EOL>
Format the custom assertion message given.

    For strings this simply replaces newlines with '\n~' so that
    util.format_explanation() will preserve them instead of escaping
    newlines.  For other objects saferepr() is used first.