1 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
2 # Copyright (C) 2023 Free Software Foundation
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU Affero General Public License as published
6 # by the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU Affero General Public License for more details.
14 # You should have received a copy of the GNU Affero General Public License
15 # along with this program. If not, see <https://www.gnu.org/licenses/>.
19 from fba.helpers import blacklist
20 from fba.helpers import domain as domain_helper
22 logging.basicConfig(level=logging.INFO)
23 logger = logging.getLogger(__name__)
28 def store(domain: str, cookies: dict):
29 logger.debug("domain='%s',cookies()=%d - CALLED!", domain, len(cookies))
30 domain_helper.raise_on(domain)
32 if blacklist.is_blacklisted(domain):
33 raise ValueError(f"domain='{domain}' is blacklisted but function was invoked")
34 elif not isinstance(cookies, dict):
35 raise ValueError(f"Parameter cookies[]='{type(cookies)}' is not of type 'dict'")
37 _cookies[domain] = cookies
41 def get_all(domain: str) -> dict:
42 logger.debug("domain='%s' - CALLED!", domain)
43 domain_helper.raise_on(domain)
45 if blacklist.is_blacklisted(domain):
46 raise ValueError(f"domain='{domain}' is blacklisted but function was invoked")
47 elif domain not in _cookies:
50 logger.debug("_cookies[%s]()=%d - EXIT!", domain, len(_cookies[domain]))
51 return _cookies[domain]
53 def has(domain: str) -> bool:
54 logger.debug("domain='%s' - CALLED!", domain)
55 domain_helper.raise_on(domain)
57 if blacklist.is_blacklisted(domain):
58 raise ValueError(f"domain='{domain}' is blacklisted but function was invoked")
60 has_cookies = domain in _cookies
62 logger.debug("has_cookies='%s' - EXIT!", has_cookies)
65 def clear(domain: str):
66 logger.debug("domain='%s' - CALLED!", domain)
67 domain_helper.raise_on(domain)
69 if blacklist.is_blacklisted(domain):
70 raise ValueError(f"domain='{domain}' is blacklisted but function was invoked")
73 logger.debug("Removing cookies for domain='%s' ...", domain)