Skip to main content
  • Home
  • Development
  • Documentation
  • Donate
  • Operational login
  • Browse the archive

swh logo
SoftwareHeritage
Software
Heritage
Archive
Features
  • Search

  • Downloads

  • Save code now

  • Add forge now

  • Help

  • ec325a8
  • /
  • byceps
  • /
  • announce
  • /
  • helpers.py
Raw File Download

To reference or cite the objects present in the Software Heritage archive, permalinks based on SoftWare Hash IDentifiers (SWHIDs) must be used.
Select below a type of object currently browsed in order to display its associated SWHID and permalink.

  • content
  • directory
content badge
swh:1:cnt:87ef7e46a74306c9fabded6edf935badbebbb149
directory badge
swh:1:dir:0920b356d52b23e77564b5bbaf20d9cfe2a8e95b

This interface enables to generate software citations, provided that the root directory of browsed objects contains a citation.cff or codemeta.json file.
Select below a type of object currently browsed in order to generate citations for them.

  • content
  • directory
(requires biblatex-software package)
Generating citation ...
(requires biblatex-software package)
Generating citation ...
helpers.py
"""
byceps.announce.helpers
~~~~~~~~~~~~~~~~~~~~~~~

:Copyright: 2014-2025 Jochen Kupperschmidt
:License: Revised BSD (see `LICENSE` file for details)
"""

from functools import wraps

from flask_babel import force_locale, gettext

from byceps.services.core.events import EventUser
from byceps.services.webhooks.models import OutgoingWebhook
from byceps.util.l10n import get_default_locale


def matches_selectors(
    event_name: str,
    webhook: OutgoingWebhook,
    attribute_name: str,
    actual_value: str,
) -> bool:
    if event_name not in webhook.event_types:
        # This should not happen as only webhooks supporting this
        # event type should have been selected before calling an
        # event announcement handler.
        return False

    event_filter = webhook.event_filters.get(event_name)
    if event_filter is None:
        return True

    allowed_values = event_filter.get(attribute_name)
    return (allowed_values is None) or (actual_value in allowed_values)


def get_screen_name_or_fallback(user: EventUser | None) -> str:
    """Return the user's screen name or a fallback value."""
    if (user is None) or (user.screen_name is None):
        return gettext('Someone')

    return user.screen_name


def with_locale(handler):
    @wraps(handler)
    def wrapper(*args, **kwargs):
        locale = get_default_locale()
        with force_locale(locale):
            return handler(*args, **kwargs)

    return wrapper

back to top

Software Heritage — Copyright (C) 2015–2026, The Software Heritage developers. License: GNU AGPLv3+.
The source code of Software Heritage itself is available on our development forge.
The source code files archived by Software Heritage are available under their own copyright and licenses.
Terms of use: Archive access, API— Content policy— Contact— JavaScript license information— Web API