def backslashreplace_while_decoding(decoding_error):
    """Replacement for the backslashreplace error handler on Python <3.5."""
    if not isinstance(decoding_error, UnicodeDecodeError):
        raise TypeError(
            'backslashreplace_while_decoding error handler can only be used for decoding'
            )
    repl = '\\' + hex(decoding_error.object[decoding_error.start])[1:]
    return repl, decoding_error.end
