<commit_before>"""
byceps.util.framework.flash
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Flash message utilities

A custom wrapper, `FlashMessage`, is used to bundle additional properties
with a text message.

`FlashMessage` objects are then returned by `get_flashed_messages()` and
handled accordingly in the `_notifications` partial template.

Thus, use the `flash_*` functions provided by this module to flash
messages, but not `flask.flash` directly.

:Copyright: 2006-2020 <NAME>
:License: Revised BSD (see `LICENSE` file for details)
"""

from dataclasses import dataclass
from typing import Optional

from flask import flash


@dataclass(frozen=True)
class FlashMessage:
    text: str
    text_is_safe: bool
    category: Optional[str]
    icon: Optional[str]


def flash_error(message, icon=None, text_is_safe=False):
    """Flash a message indicating an error."""
    return _flash(
        message, category='danger', icon=icon, text_is_safe=text_is_safe
    )


def flash_notice(message, icon=None, text_is_safe=False):
    """Flash a generally informational message."""
    return _flash(
        message, category='info', icon=icon, text_is_safe=text_is_safe
    )


def flash_success(message, icon=None, text_is_safe=False):
    """Flash a message describing a successful action."""
    return _flash(
        message, category='success', icon=icon, text_is_safe=text_is_safe
    )


def _flash(message, category=None, icon=None, text_is_safe=False):
    flash_message = FlashMessage(message, text_is_safe, category, icon)

    return flash(flash_message)
<commit_msg>Return nothing as `flask.flash` does not return value<commit_after>"""
byceps.util.framework.flash
~~~~~~~~~~~~~~~~~~~~~~~~~~~

Flash message utilities

A custom wrapper, `FlashMessage`, is used to bundle additional properties
with a text message.

`FlashMessage` objects are then returned by `get_flashed_messages()` and
handled accordingly in the `_notifications` partial template.

Thus, use the `flash_*` functions provided by this module to flash
messages, but not `flask.flash` directly.

:Copyright: 2006-2020 <NAME>
:License: Revised BSD (see `LICENSE` file for details)
"""

from dataclasses import dataclass
from typing import Optional

from flask import flash


@dataclass(frozen=True)
class FlashMessage:
    text: str
    text_is_safe: bool
    category: Optional[str]
    icon: Optional[str]


def flash_error(message, icon=None, text_is_safe=False):
    """Flash a message indicating an error."""
    _flash(message, category='danger', icon=icon, text_is_safe=text_is_safe)


def flash_notice(message, icon=None, text_is_safe=False):
    """Flash a generally informational message."""
    _flash(message, category='info', icon=icon, text_is_safe=text_is_safe)


def flash_success(message, icon=None, text_is_safe=False):
    """Flash a message describing a successful action."""
    _flash(message, category='success', icon=icon, text_is_safe=text_is_safe)


def _flash(message, category=None, icon=None, text_is_safe=False):
    flash_message = FlashMessage(message, text_is_safe, category, icon)
    flash(flash_message)

{'fraction_non_alphanumeric': 0.1136144190537496, 'fraction_numerical': 0.005149662053427744, 'mean_word_length': 5.368852459016393, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1856733', 'n_tokens_mistral': 964, 'n_tokens_neox': 904, 'n_words': 288}