gavo.formal.util module¶
- class gavo.formal.util.CaseSemisensitiveDict(*args, **kwargs)[source]¶
Bases:
dict
A dictionary allowing case-insensitive access to its content.
This is used for DAL renderers which, unfortunately, are supposed to be case insensitive. Since case insensitivity is at least undesirable for service-specific keys, we go a semi-insenstitve approach here: First, we try literal matches, if that does not work, we try matching against an all-uppercase version.
Name clashes resulting from different names being mapped to the same normalized version are handled in some random way. Don’t do this. And don’t rely on case normalization if at all possible.
Only strings are allowed as keys here. This class is not concerned with the values. >>> d = CaseSemisensitiveDict({“a”: 1, “A”: 2, “b”: 3}) >>> d[“a”], d[“A”], d[“b”], d[“B”] (1, 2, 3, 3) >>> d[“B”] = 9; d[“b”], d[“B”] (3, 9) >>> del d[“b”]; d[“b”], d[“B”] (9, 9) >>> “B” in d, “b” in d, “u” in d (True, True, False) >>> d.pop(“a”), list(d.keys()) (1, [‘A’, ‘B’])