1 # Copyright (C) 2023 Free Software Foundation
3 # This program is free software: you can redistribute it and/or modify
4 # it under the terms of the GNU Affero General Public License as published
5 # by the Free Software Foundation, either version 3 of the License, or
6 # (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU Affero General Public License for more details.
13 # You should have received a copy of the GNU Affero General Public License
14 # along with this program. If not, see <https://www.gnu.org/licenses/>.
18 def reason(string: str) -> str:
19 # DEBUG: print(f"DEBUG: string='{string}' - CALLED!")
20 if not isinstance(string, str):
21 raise ValueError(f"Parameter string[]='{type(string)}' is not 'str'")
24 string = string.strip()
27 string = re.sub("â", "\"", string)
29 # DEBUG: print(f"DEBUG: string='{string}' - EXIT!")
32 def domain(string: str) -> str:
33 # DEBUG: print(f"DEBUG: string='{string}' - CALLED!")
34 if not isinstance(string, str):
35 raise ValueError(f"Parameter string[]='{type(string)}' is not 'str'")
37 # All lower-case and strip spaces out + last dot
38 string = string.lower().strip().rstrip(".")
41 string = re.sub("\:\d+$", "", string)
43 # No protocol, sometimes without the slashes
44 string = re.sub("^https?\:(\/*)", "", string)
47 string = re.sub("\/$", "", string)
50 string = re.sub("^\@", "", string)
51 string = string.split(":")[0]
53 # No individual users in block lists
54 string = re.sub("(.+)\@", "", string)
55 if string.find("/profile/"):
56 string = string.split("/profile/")[0]
57 elif string.find("/users/"):
58 string = string.split("/users/")[0]
60 # DEBUG: print(f"DEBUG: string='{string}' - EXIT!")