]> git.mxchange.org Git - fba.git/blob - fba/helpers/cookies.py
70f45cc2a1fdafd67875ce2ef2f1b0e88f2505af
[fba.git] / fba / helpers / cookies.py
1 # Fedi API Block - An aggregator for fetching blocking data from fediverse nodes
2 # Copyright (C) 2023 Free Software Foundation
3 #
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.
8 #
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.
13 #
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/>.
16
17 # Cookies stor
18 _cookies = {}
19
20 def store (domain: str, cookies: dict):
21     # DEBUG: print(f"DEBUG: domain='{domain}',cookies()={len(cookies)} - CALLED!")
22     if not isinstance(domain, str):
23         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
24     elif domain == "":
25         raise ValueError("Parameter 'domain' is empty")
26     elif not isinstance(cookies, dict):
27         raise ValueError(f"Parameter cookies[]='{type(cookies)}' is not 'dict'")
28
29     _cookies[domain] = cookies
30
31     # DEBUG: print(f"DEBUG: EXIT!")
32
33 def get_all(domain: str) -> dict:
34     # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
35     if not isinstance(domain, str):
36         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
37     elif domain == "":
38         raise ValueError("Parameter 'domain' is empty")
39     elif not domain in _cookies:
40         raise Exception(f"domain='{domain}' has no cookies stored, maybe invoke store() first?")
41
42     # DEBUG: print(f"DEBUG: _cookies[{domain}]()={len(_cookies[domain])} - EXIT!")
43     return _cookies[domain]