colour.utilities.CaseInsensitiveMapping

class colour.utilities.CaseInsensitiveMapping(data=None, **kwargs)[source]

Bases: collections.abc.MutableMapping

Implements a case-insensitive mutable mapping / dict object.

Allows values retrieving from keys while ignoring the key case. The keys are expected to be unicode or string-like objects supporting the str.lower() method.

Parameters
  • data (dict) – dict of data to store into the mapping at initialisation.

  • **kwargs (dict, optional) – Key / Value pairs to store into the mapping at initialisation.

Attributes

Methods

Warning

The keys are expected to be unicode or string-like objects.

References

[]

Examples

>>> methods = CaseInsensitiveMapping({'McCamy': 1, 'Hernandez': 2})
>>> methods['mccamy']
1
__init__(data=None, **kwargs)[source]
property data

Getter property for the data.

Returns

Data.

Return type

dict

__setitem__(item, value)[source]

Sets given item with given value.

The item is stored as lower in the mapping while the original name and its value are stored together as the value in a tuple:

{“item.lower()”: (“item”, value)}

Parameters
__getitem__(item)[source]

Returns the value of given item.

The item value is retrieved using its lower name in the mapping.

Parameters

item (unicode) – Item name.

Returns

Item value.

Return type

object

__delitem__(item)[source]

Deletes the item with given name.

The item is deleted from the mapping using its lower name.

Parameters

item (unicode) – Item name.

__contains__(item)[source]

Returns if the mapping contains given item.

Parameters

item (unicode) – Item name.

Returns

Is item in mapping.

Return type

bool

__iter__()[source]

Iterates over the items names in the mapping.

The item names returned are the original input ones.

Returns

Item names.

Return type

generator

__len__()[source]

Returns the items count.

Returns

Items count.

Return type

int

__eq__(item)[source]

Returns the equality with given object.

Parameters

item – Object item.

Returns

Equality.

Return type

bool

__ne__(item)[source]

Returns the inequality with given object.

Parameters

item – Object item.

Returns

Inequality.

Return type

bool

__repr__()

Returns an ellipsis string representation of the case-insensitive mutable mapping for documentation purposes.

Returns

Ellipsis string representation.

Return type

unicode

copy()[source]

Returns a copy of the mapping.

Returns

Mapping copy.

Return type

CaseInsensitiveMapping

Notes

lower_items()[source]

Iterates over the lower items names.

Returns

Lower item names.

Return type

generator

__hash__ = None
__weakref__

list of weak references to the object (if defined)