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/>.
19 logging.basicConfig(level=logging.INFO)
20 logger = logging.getLogger(__name__)
22 def reason(string: str) -> str:
23 logger.debug(f"string='{string}' - CALLED!")
24 if not isinstance(string, str):
25 raise ValueError(f"Parameter string[]='{type(string)}' is not 'str'")
28 string = string.strip()
30 logger.debug(f"string='{string}' - EXIT!")
33 def domain(string: str) -> str:
34 logger.debug(f"string='{string}' - CALLED!")
35 if not isinstance(string, str):
36 raise ValueError(f"Parameter string[]='{type(string)}' is not 'str'")
38 # All lower-case and strip spaces out + last dot
39 string = string.lower().strip().rstrip(".")
40 logger.debug(f"string='{string}' - #1")
43 string = re.sub("\:\d+$", "", string)
44 logger.debug(f"string='{string}' - #2")
46 # No protocol, sometimes without the slashes
47 string = re.sub("^https?\:(\/*)", "", string)
48 logger.debug(f"string='{string}' - #3")
51 string = re.sub("\/$", "", string)
52 logger.debug(f"string='{string}' - #4")
55 string = re.sub("^\@", "", string)
56 string = string.split(":")[0]
57 logger.debug(f"string='{string}' - #4")
59 # No individual users in block lists
60 string = re.sub("(.+)\@", "", string)
61 logger.debug(f"string='{string}' - #5")
62 if string.find("/profile/"):
63 string = string.split("/profile/")[0]
64 elif string.find("/users/"):
65 string = string.split("/users/")[0]
67 logger.debug(f"string='{string}' - EXIT!")