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 the str.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
__init__(data: Optional[Union[Generator, Mapping]] = None, **kwargs: Any)[source]#
Parameters
property data: Dict#

Getter property for the case-insensitive dict-like object data.

Returns

Data.

Return type

dict

__repr__() str[source]#

Return an evaluable string representation of the case-insensitive dict-like object.

Returns

Evaluable string representation.

Return type

str

__setitem__(item: Union[str, Any], value: Any)[source]#

Set given item with given value in the case-insensitive dict-like object.

Parameters
  • item (Union[str, Any]) – Item to set in the case-insensitive dict-like object.

  • value (Any) – Value to store in the case-insensitive dict-like object.

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

object

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.

Parameters

item (Union[str, Any]) – Item to delete 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.

Parameters

item (Union[str, Any]) – Item to find whether it is in the case-insensitive dict-like object.

Returns

Whether given item is in the case-insensitive dict-like object.

Return type

bool

__iter__() Generator[source]#

Iterate over the items of the case-insensitive dict-like object.

Yields

Generator – Item generator.

Return type

Generator

Notes

  • The iterated items are the original items.

__len__() int[source]#

Return the items count.

Returns

Items count.

Return type

numpy.integer

__eq__(other: Any) bool[source]#

Return whether the case-insensitive dict-like object is equal to given other object.

Parameters

other (Any) – Object to test whether it is equal to the case-insensitive dict-like object

Returns

Whether given object is equal to the case-insensitive dict-like object.

Return type

bool

__ne__(other: Any) bool[source]#

Return whether the case-insensitive dict-like object is not equal to given other object.

Parameters

other (Any) – Object to test whether it is not equal to the case-insensitive dict-like object

Returns

Whether given object is not equal to the case-insensitive dict-like object.

Return type

bool

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

CaseInsensitiveMapping

Warning

lower_items() Generator[source]#

Iterate over the lower-case items of the case-insensitive dict-like object.

Yields

Generator – Item generator.

Return type

Generator

Notes

  • The iterated items are the lower-case items.

__hash__ = None#
__weakref__#

list of weak references to the object (if defined)