def bool_func_from_raiser(
    raiser_func,
    *,
    expected_exceptions=None,
    exceptions_to_reraise=(KeyboardInterrupt, SystemExit),
    reporting_func=return_untouched,
    new_message="",
    message_formatter=return_untouched,
    include_exception_name=True
):
    """Return a boolean function from exception raising one.

    Usage
    =====

    Used when you have a function which raises exceptions
    under certain conditions and want to replace it with a
    boolean function.

    The replacement function works in such manner that if
    an expected exception is thrown, it is caught and the
    execution proceeds normally until None is returned and,
    if no exception is raise, True is returned.

    Parameters
    ==========

    raiser_func (callable)
        raises exceptions under certain conditions; might
        have an 'expected_exceptions' attribute containing
        an exception class or tuple thereof.

    expected_exceptions (None, exception or tuple thereof)
        exception(s) to be supressed. If it is None, we
        try to retrieve this value from the attribute with
        the same name from the received raiser function.
        If such attribute doesn't exist, we use Exception.

    exceptions_to_reraise (exception or tuple thereof)
        indicate exception(s) you don't want to catch, but
        let them "bubble up"; we recommend to use the
        default value (both the KeyboardInterrupt and
        SystemExit exceptions).

    reporting_func (callable)
        used to report supressed exceptions; must accept
        a single argument which is the exception message
        from the supressed exception; default behaviour
        does nothing (besides returning the string
        untouched); we recommend using a logging function;

    new_message (string)
        if provided (not an empty string), it completely
        replaces the exception message from the exception
        caught.

    message_formatter (callable)
        must accept a single argument which is the message
        from the caught exception in order to format it to
        the user liking; it is used only if the new_message
        argument is an empty empty string; if you want to
        provide it, we recommend using the 'format' method
        of a custom string of your choice, otherwise the
        default value makes it so the received message is
        returned as-is.

    include_exception_name (boolean)
        indicates whether the message from the exception
        caught must include '[exception class name]: ' at
        the beginning or not, before being passed to the
        message_formatter callable, when it is used.
    """
    ### if no expected exception(s) are specified, check
    ### the function 'expected_exceptions' attribute;
    ### use Exception if the attribute doesn't exist

    if expected_exceptions is None:

        expected_exceptions = getattr(raiser_func, "expected_exceptions", Exception)

    ### define function

    def didnt_raise_expected(*args, **kwargs):
        """Return whether expected exception wasn't raised.

        When an exception is thrown, that is, an exception
        marked as expected, it is caught and reported, then
        the function proceeds to the end returning None.

        Otherwise, if no exception is thrown, we return True.
        """
        ### try executing the function with the received
        ### arguments
        try:
            raiser_func(*args, **kwargs)

        ### if an exception marked to be reraise is raised,
        ### reraise it as expected

        except exceptions_to_reraise as err:
            raise err

        ### if an exception marked as expected is raised,
        ### it is caught and the exception message is passed
        ### reported;

        except expected_exceptions as err:

            ### first of all define the exception message to
            ### be reported

            ## if a new message was given, use it
            if new_message:
                msg = new_message

            ## otherwise assemble a message from the
            ## message of the exception caught, whether
            ## preformated or not

            else:

                ## grab exception message

                raw_msg = (
                    ## preformat exception message
                    "{}: {}".format(err.__class__.__name__, str(err))
                    if include_exception_name
                    ## or use it as-is
                    else str(err)
                )

                ## then pass it through the custom
                ## formatter
                msg = message_formatter(raw_msg)

            ### then pass the message to the reporting
            ### function
            reporting_func(msg)

        ### if no exception is raised, though, we just
        ### return True
        else:
            return True

    ### return defined function
    return didnt_raise_expected
Return a boolean function from exception raising one.

    Usage
    =====

    Used when you have a function which raises exceptions
    under certain conditions and want to replace it with a
    boolean function.

    The replacement function works in such manner that if
    an expected exception is thrown, it is caught and the
    execution proceeds normally until None is returned and,
    if no exception is raise, True is returned.

    Parameters
    ==========

    raiser_func (callable)
        raises exceptions under certain conditions; might
        have an 'expected_exceptions' attribute containing
        an exception class or tuple thereof.

    expected_exceptions (None, exception or tuple thereof)
        exception(s) to be supressed. If it is None, we
        try to retrieve this value from the attribute with
        the same name from the received raiser function.
        If such attribute doesn't exist, we use Exception.

    exceptions_to_reraise (exception or tuple thereof)
        indicate exception(s) you don't want to catch, but
        let them "bubble up"; we recommend to use the
        default value (both the KeyboardInterrupt and
        SystemExit exceptions).

    reporting_func (callable)
        used to report supressed exceptions; must accept
        a single argument which is the exception message
        from the supressed exception; default behaviour
        does nothing (besides returning the string
        untouched); we recommend using a logging function;

    new_message (string)
        if provided (not an empty string), it completely
        replaces the exception message from the exception
        caught.

    message_formatter (callable)
        must accept a single argument which is the message
        from the caught exception in order to format it to
        the user liking; it is used only if the new_message
        argument is an empty empty string; if you want to
        provide it, we recommend using the 'format' method
        of a custom string of your choice, otherwise the
        default value makes it so the received message is
        returned as-is.

    include_exception_name (boolean)
        indicates whether the message from the exception
        caught must include '[exception class name]: ' at
        the beginning or not, before being passed to the
        message_formatter callable, when it is used.
    
nodezator/ourstdlibs/exceptionutils.py