def warning_record_to_str(warning_message):
warn_msg = warning_message.message<EOL>unicode_warning = False<EOL>if compat._PY2 and any(isinstance(m, compat.UNICODE_TYPES) for m in warn_msg.args):<EOL><INDENT>new_args = []<EOL>for m in warn_msg.args:<EOL><INDENT>new_args.append(<EOL>compat.ascii_escaped(m) if isinstance(m, compat.UNICODE_TYPES) else m<EOL>)<EOL><DEDENT>unicode_warning = list(warn_msg.args) != new_args<EOL>warn_msg.args = new_args<EOL><DEDENT>msg = warnings.formatwarning(<EOL>warn_msg,<EOL>warning_message.category,<EOL>warning_message.filename,<EOL>warning_message.lineno,<EOL>warning_message.line,<EOL>)<EOL>if unicode_warning:<EOL><INDENT>warnings.warn(<EOL>"<STR_LIT>"<EOL>"<STR_LIT>".format(compat.safe_str(msg)),<EOL>UnicodeWarning,<EOL>)<EOL><DEDENT>return msg<EOL>
Convert a warnings.WarningMessage to a string.

    This takes lot of unicode shenaningans into account for Python 2.
    When Python 2 support is dropped this function can be greatly simplified.