Mercurial > libervia-backend
diff libervia/backend/tools/common/regex.py @ 4270:0d7bb4df2343
Reformatted code base using black.
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 19 Jun 2024 18:44:57 +0200 |
parents | 4b842c1fb686 |
children | 6baea959dc33 |
line wrap: on
line diff
--- a/libervia/backend/tools/common/regex.py Tue Jun 18 12:06:45 2024 +0200 +++ b/libervia/backend/tools/common/regex.py Wed Jun 19 18:44:57 2024 +0200 @@ -26,8 +26,8 @@ path_escape_rev = {re.escape(v): k for k, v in path_escape.items()} path_escape = {re.escape(k): v for k, v in path_escape.items()} # thanks to Martijn Pieters (https://stackoverflow.com/a/14693789) -RE_ANSI_REMOVE = re.compile(r'\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])') -RE_TEXT_URL = re.compile(r'[^a-zA-Z0-9,_]+') +RE_ANSI_REMOVE = re.compile(r"\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])") +RE_TEXT_URL = re.compile(r"[^a-zA-Z0-9,_]+") TEXT_MAX_LEN = 60 # min lenght is currently deactivated TEXT_WORD_MIN_LENGHT = 0 @@ -84,12 +84,12 @@ """Convert text to url-friendly one""" # we change special chars to ascii one, # trick found at https://stackoverflow.com/a/3194567 - text = unicodedata.normalize('NFD', text).encode('ascii', 'ignore').decode('utf-8') - text = RE_TEXT_URL.sub(' ', text).lower() - text = '-'.join([t for t in text.split() if t and len(t)>=TEXT_WORD_MIN_LENGHT]) + text = unicodedata.normalize("NFD", text).encode("ascii", "ignore").decode("utf-8") + text = RE_TEXT_URL.sub(" ", text).lower() + text = "-".join([t for t in text.split() if t and len(t) >= TEXT_WORD_MIN_LENGHT]) while len(text) > TEXT_MAX_LEN: - if '-' in text: - text = text.rsplit('-', 1)[0] + if "-" in text: + text = text.rsplit("-", 1)[0] else: text = text[:TEXT_MAX_LEN] return text