colour.utilities.CaseInsensitiveMapping¶
- class colour.utilities.CaseInsensitiveMapping(data: Optional[Union[Generator, Mapping]] = None, **kwargs: Any)[source]¶
Bases:
collections.abc.MutableMapping
Implement a case-insensitive
dict
-like object.Allows values retrieving from keys while ignoring the key case. The keys are expected to be str or
str
-like objects supporting thestr.lower()
method.- Parameters
data (Optional[Union[Generator, Mapping]]) – Data to store into the case-insensitive
dict
-like object at initialisation.kwargs (Any) – Key / value pairs to store into the mapping at initialisation.
Attributes
Methods
References
[Rei]
Examples
>>> methods = CaseInsensitiveMapping({'McCamy': 1, 'Hernandez': 2}) >>> methods['mccamy'] 1
- property data: Dict¶
Getter property for the case-insensitive
dict
-like object data.- Returns
Data.
- Return type
- __repr__() str [source]¶
Return an evaluable string representation of the case-insensitive
dict
-like object.- Returns
Evaluable string representation.
- Return type
- __setitem__(item: Union[str, Any], value: Any)[source]¶
Set given item with given value in the case-insensitive
dict
-like object.- Parameters
Notes
The item is stored as lower-case while the original name and its value are stored together as the value in a tuple:
{"item.lower()": ("item", value)}
- __getitem__(item: Union[str, Any]) Any [source]¶
Return the value of given item from the case-insensitive
dict
-like object.- Parameters
item (Union[str, Any]) – Item to retrieve the value of from the case-insensitive
dict
-like object.- Returns
Item value.
- Return type
Notes
The item value is retrieved by using its lower-case variant.
- __delitem__(item: Union[str, Any])[source]¶
Delete given item from the case-insensitive
dict
-like object.Notes
The item is deleted by using its lower-case variant.
- __contains__(item: Union[str, Any]) bool [source]¶
Return whether the case-insensitive
dict
-like object contains given item.
- __iter__() Generator [source]¶
Iterate over the items of the case-insensitive
dict
-like object.- Yields
Generator – Item generator.
- Return type
Notes
The iterated items are the original items.
- __eq__(other: Any) bool [source]¶
Return whether the case-insensitive
dict
-like object is equal to given other object.
- __ne__(other: Any) bool [source]¶
Return whether the case-insensitive
dict
-like object is not equal to given other object.
- copy() colour.utilities.data_structures.CaseInsensitiveMapping [source]¶
Return a copy of the case-insensitive
dict
-like object.- Returns
Case-insensitive
dict
-like object copy.- Return type
Warning
The
CaseInsensitiveMapping
class copy returned is a copy of the object not a deepcopy!
- lower_items() Generator [source]¶
Iterate over the lower-case items of the case-insensitive
dict
-like object.- Yields
Generator – Item generator.
- Return type
Notes
The iterated items are the lower-case items.
- __hash__ = None¶
- __weakref__¶
list of weak references to the object (if defined)