colour.utilities.CanonicalMapping#
- class colour.utilities.CanonicalMapping(data: collections.abc.Generator | collections.abc.Mapping | None = None, **kwargs: Any)[source]#
Bases:
collections.abc.MutableMapping
Implement a delimiter and case-insensitive
dict
-like object with support for slugs, i.e. SEO friendly and human-readable version of the keys but also canonical keys, i.e. slugified keys without delimiters.The item keys are expected to be
str
-like objects thus supporting thestr.lower()
method. Setting items is done by using the given keys. Retrieving or deleting an item and testing whether an item exist is done by transforming the item’s key in a sequence as follows:Original Key
Lowercase Key
Slugified Key
Canonical Key
For example, given the
McCamy 1992
key:Original Key :
McCamy 1992
Lowercase Key :
mccamy 1992
Slugified Key :
mccamy-1992
Canonical Key :
mccamy1992
- Parameters
- Return type
None
Attributes
Methods
Examples
>>> methods = CanonicalMapping({"McCamy 1992": 1, "Hernandez 1999": 2}) >>> methods["mccamy 1992"] 1 >>> methods["MCCAMY 1992"] 1 >>> methods["mccamy-1992"] 1 >>> methods["mccamy1992"] 1
- __init__(data: collections.abc.Generator | collections.abc.Mapping | None = None, **kwargs: Any) None [source]#
- Parameters
data (collections.abc.Generator | collections.abc.Mapping | None) –
kwargs (Any) –
- Return type
None
- property data: dict#
Getter property for the delimiter and case-insensitive
dict
-like object data.- Returns
Data.
- Return type
- __repr__() str [source]#
Return an evaluable string representation of the delimiter and case-insensitive
dict
-like object.- Returns
Evaluable string representation.
- Return type
- __setitem__(item: str | Any, value: Any)[source]#
Set given item with given value in the delimiter and case-insensitive
dict
-like object.
- __getitem__(item: str | Any) Any [source]#
Return the value of given item from the delimiter and case-insensitive
dict
-like object.- Parameters
item (str | Any) – Item to retrieve the value of from the delimiter and case-insensitive
dict
-like object.- Returns
Item value.
- Return type
Notes
The item value can be retrieved by using either its lower-case, slugified or canonical variant.
- __delitem__(item: str | Any)[source]#
Delete given item from the delimiter and case-insensitive
dict
-like object.- Parameters
item (str | Any) – Item to delete from the delimiter and case-insensitive
dict
-like object.
Notes
The item can be deleted by using either its lower-case, slugified or canonical variant.
- __contains__(item: str | Any) bool [source]#
Return whether the delimiter and case-insensitive
dict
-like object contains given item.- Parameters
item (str | Any) – Item to find whether it is in the delimiter and case-insensitive
dict
-like object.- Returns
Whether given item is in the delimiter and case-insensitive
dict
-like object.- Return type
Notes
The item presence can be checked by using either its lower-case, slugified or canonical variant.
- __iter__() collections.abc.Generator [source]#
Iterate over the items of the delimiter and 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 delimiter and case-insensitive
dict
-like object is equal to given other object.
- __ne__(other: Any) bool [source]#
Return whether the delimiter and case-insensitive
dict
-like object is not equal to given other object.
- copy() colour.utilities.data_structures.CanonicalMapping [source]#
Return a copy of the delimiter and case-insensitive
dict
-like object.- Returns
Case-insensitive
dict
-like object copy.- Return type
Warning
The
CanonicalMapping
class copy returned is a copy of the object not a deepcopy!
- lower_keys() collections.abc.Generator [source]#
Iterate over the lower-case keys of the delimiter and case-insensitive
dict
-like object.- Yields
Generator – Item generator.
- Return type
- lower_items() collections.abc.Generator [source]#
Iterate over the lower-case items of the delimiter and case-insensitive
dict
-like object.- Yields
Generator – Item generator.
- Return type
- slugified_keys() collections.abc.Generator [source]#
Iterate over the slugified keys of the delimiter and case-insensitive
dict
-like object.- Yields
Generator – Item generator.
- Return type
- slugified_items() collections.abc.Generator [source]#
Iterate over the slugified items of the delimiter and case-insensitive
dict
-like object.- Yields
Generator – Item generator.
- Return type
- canonical_keys() collections.abc.Generator [source]#
Iterate over the canonical keys of the delimiter and case-insensitive
dict
-like object.- Yields
Generator – Item generator.
- Return type
- canonical_items() collections.abc.Generator [source]#
Iterate over the canonical items of the delimiter and case-insensitive
dict
-like object.- Yields
Generator – Item generator.
- Return type
- __hash__ = None#
- __weakref__#
list of weak references to the object (if defined)