# -*- coding: utf-8 -*- """ A simple implementation of a key case-insensitive dictionary. .. Developers involved: * Ivan Herman * Sergio Fernández * Carlos Tejo Alonso * Alexey Zakhlestin Organizations involved: * `World Wide Web Consortium `_ * `Foundation CTIC `_ :license: `W3C® Software notice and license `_ """ from typing import Dict, Mapping, TypeVar _V = TypeVar("_V") class KeyCaseInsensitiveDict(Dict[str, _V]): """ A simple implementation of a key case-insensitive dictionary """ def __init__(self, d: Mapping[str, _V]={}) -> None: """ :param dict d: The source dictionary. """ for k, v in d.items(): self[k] = v def __setitem__(self, key: str, value: _V) -> None: if hasattr(key, "lower"): key = key.lower() dict.__setitem__(self, key, value) def __getitem__(self, key: str) -> _V: if hasattr(key, "lower"): key = key.lower() return dict.__getitem__(self, key) def __delitem__(self, key: str) -> None: if hasattr(key, "lower"): key = key.lower() dict.__delitem__(self, key)