File: precis.py

package info (click to toggle)
python-nbxmpp 6.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,340 kB
  • sloc: python: 19,639; makefile: 4
file content (16 lines) | stat: -rw-r--r-- 496 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
from precis_i18n import get_profile

_localpart_disallowed_chars = set("\"&'/:<>@")


def enforce_precis_username(localpart: str) -> str:
    if _localpart_disallowed_chars & set(localpart):
        raise ValueError("Input contains prohibited codepoint: %s" % localpart)

    username = get_profile("UsernameCaseMapped")
    return username.enforce(localpart)


def enforce_precis_opaque(resourcepart: str) -> str:
    opaque = get_profile("OpaqueString")
    return opaque.enforce(resourcepart)