mirror of
https://github.com/GSA/notifications-admin.git
synced 2026-07-10 11:24:10 -04:00
This changeset copies everything in notifications_utils to turn into a local project module. It includes dependency changes to account for this adjustment and the notifications_utils tests. It also fixes all of the import statements. Signed-off-by: Carlo Costino <carlo.costino@gsa.gov>
26 lines
674 B
Python
26 lines
674 B
Python
import re
|
|
import unicodedata
|
|
|
|
|
|
def make_string_safe(string, whitespace):
|
|
# strips accents, diacritics etc
|
|
string = "".join(
|
|
c
|
|
for c in unicodedata.normalize("NFD", string)
|
|
if unicodedata.category(c) != "Mn"
|
|
)
|
|
string = "".join(
|
|
word.lower() if word.isalnum() or word == whitespace else ""
|
|
for word in re.sub(r"\s+", whitespace, string.strip())
|
|
)
|
|
string = re.sub(r"\.{2,}", ".", string)
|
|
return string.strip(".")
|
|
|
|
|
|
def make_string_safe_for_email_local_part(string):
|
|
return make_string_safe(string, whitespace=".")
|
|
|
|
|
|
def make_string_safe_for_id(string):
|
|
return make_string_safe(string, whitespace="-")
|