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 domain as domain_helper
21 logging.basicConfig(level=logging.INFO)
22 logger = logging.getLogger(__name__)
27 def store(domain: str, cookies: dict):
28 logger.debug("domain='%s',cookies()=%d - CALLED!", domain, len(cookies))
29 domain_helper.raise_on(domain)
30 if not isinstance(cookies, dict):
31 raise ValueError(f"Parameter cookies[]='{type(cookies)}' is not of type 'dict'")
33 _cookies[domain] = cookies
37 def get_all(domain: str) -> dict:
38 logger.debug("domain='%s' - CALLED!", domain)
39 domain_helper.raise_on(domain)
41 if domain not in _cookies:
44 logger.debug("_cookies[%s]()=%d - EXIT!", domain, len(_cookies[domain]))
45 return _cookies[domain]
47 def has(domain: str) -> bool:
48 logger.debug("domain='%s' - CALLED!", domain)
49 domain_helper.raise_on(domain)
51 has_cookies = domain in _cookies
53 logger.debug("has_cookies='%s' - EXIT!", has_cookies)
56 def clear(domain: str):
57 logger.debug("domain='%s' - CALLED!", domain)
58 domain_helper.raise_on(domain)
61 logger.debug("Removing cookies for domain='%s' ...", domain)