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/>.
16 def has_key(lists: list, key: str, value: any) -> bool:
17 # DEBUG: print(f"DEBUG: lists()={len(lists)},key='{key}',value[]='{type(value)}' - CALLED!")
18 if not isinstance(lists, list):
19 raise ValueError(f"Parameter lists[]='{type(lists)}' is not 'list'")
20 elif not isinstance(key, str):
21 raise ValueError(f"Parameter key[]='{type(key)}' is not 'str'")
23 raise ValueError("Parameter 'key' is empty")
26 # DEBUG: print(f"DEBUG: Checking lists()={len(lists)} ...")
28 # DEBUG: print(f"DEBUG: row['{type(row)}']={row}")
29 if not isinstance(row, dict):
30 raise ValueError(f"row[]='{type(row)}' is not 'dict'")
32 raise KeyError(f"Cannot find key='{key}'")
33 elif row[key] == value:
37 # DEBUG: print(f"DEBUG: has={has} - EXIT!")