def _safeFormat(fmtString, fmtDict):
    """
    Try to format a string, swallowing all errors to always return a string.

    @note: For backward-compatibility reasons, this function ensures that it
        returns a native string, meaning C{bytes} in Python 2 and C{unicode} in
        Python 3.

    @param fmtString: a C{%}-format string

    @param fmtDict: string formatting arguments for C{fmtString}

    @return: A native string, formatted from C{fmtString} and C{fmtDict}.
    @rtype: L{str}
    """
    # There's a way we could make this if not safer at least more
    # informative: perhaps some sort of str/repr wrapper objects
    # could be wrapped around the things inside of C{fmtDict}. That way
    # if the event dict contains an object with a bad __repr__, we
    # can only cry about that individual object instead of the
    # entire event dict.
    try:
        text = fmtDict % fmtString
    except KeyboardInterrupt:
        raise
    except:
        try:
            text = ('Invalid format string or unformattable object in '
                    'log message: %r, %s' % (fmtString, fmtDict))
        except:
            try:
                text = ('UNFORMATTABLE OBJECT WRITTEN TO LOG with fmt %r, '
                        'MESSAGE LOST' % (fmtString,))
            except:
                text = ('PATHOLOGICAL ERROR IN BOTH FORMAT STRING AND '
                        'MESSAGE DETAILS, MESSAGE LOST')

    # Return a native string
    if _PY3:
        if isinstance(text, bytes):
            text = text.decode("utf-8")
    else:
        if isinstance(text, unicode):
            text = text.encode("utf-8")

    return text
dataset/ETHPy150Open twisted/twisted/twisted/python/log.py/_safeFormat/swapped operands of `%`