MCPcopy Index your code
hub / github.com/mongodb/mongo-python-driver / _CaseInsensitiveDictionary

Class _CaseInsensitiveDictionary

pymongo/common.py:979–1064  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

977
978
979class _CaseInsensitiveDictionary(MutableMapping[str, Any]):
980 def __init__(self, *args: Any, **kwargs: Any):
981 self.__casedkeys: dict[str, Any] = {}
982 self.__data: dict[str, Any] = {}
983 self.update(dict(*args, **kwargs))
984
985 def __contains__(self, key: str) -> bool: # type: ignore[override]
986 return key.lower() in self.__data
987
988 def __len__(self) -> int:
989 return len(self.__data)
990
991 def __iter__(self) -> Iterator[str]:
992 return (key for key in self.__casedkeys)
993
994 def __repr__(self) -> str:
995 return str({self.__casedkeys[k]: self.__data[k] for k in self})
996
997 def __setitem__(self, key: str, value: Any) -> None:
998 lc_key = key.lower()
999 self.__casedkeys[lc_key] = key
1000 self.__data[lc_key] = value
1001
1002 def __getitem__(self, key: str) -> Any:
1003 return self.__data[key.lower()]
1004
1005 def __delitem__(self, key: str) -> None:
1006 lc_key = key.lower()
1007 del self.__casedkeys[lc_key]
1008 del self.__data[lc_key]
1009
1010 def __eq__(self, other: Any) -> bool:
1011 if not isinstance(other, abc.Mapping):
1012 return NotImplemented
1013 if len(self) != len(other):
1014 return False
1015 for key in other: # noqa: SIM110
1016 if self[key] != other[key]:
1017 return False
1018
1019 return True
1020
1021 def get(self, key: str, default: Optional[Any] = None) -> Any:
1022 return self.__data.get(key.lower(), default)
1023
1024 def pop(self, key: str, *args: Any, **kwargs: Any) -> Any:
1025 lc_key = key.lower()
1026 self.__casedkeys.pop(lc_key, None)
1027 return self.__data.pop(lc_key, *args, **kwargs)
1028
1029 def popitem(self) -> tuple[str, Any]:
1030 lc_key, cased_key = self.__casedkeys.popitem()
1031 value = self.__data.pop(lc_key)
1032 return cased_key, value
1033
1034 def clear(self) -> None:
1035 self.__casedkeys.clear()
1036 self.__data.clear()

Callers 7

run_scenarioFunction · 0.90
_parse_optionsFunction · 0.90
_parse_kms_tls_optionsFunction · 0.90
_validate_uriFunction · 0.90
_parse_srvFunction · 0.90
_parse_srvFunction · 0.90
get_validated_optionsFunction · 0.85

Calls

no outgoing calls

Tested by 1

run_scenarioFunction · 0.72