3. lib.utils — Utility classes¶
3.1. Concrete Classes¶
- class lib.utils.PrioritySubDictionary(parent_dict, key)[source]¶
An implementation of AbstractPriorityDictionary.
This priority dictionary get’s it contents from the values of key in the parent dictionary provided.
3.2. Abstract Classes¶
- class lib.utils.AbstractPriorityDictionary[source]¶
A dictionary that combines the contents of multiple other dictionaries together; with the value for a key taken from the dictionary that has the highest priority.
Subclasses simply need to provide an implementation for _ordered_configs().
Note
This class does no caching; so each call will recalculate the values. This can lead to values changing between calls. Be careful with it.
See also
This module includes collections.Mapping and this provides additional functionality.
- _ordered_configs()[source]¶
This should return an list(dict)(A list containing dictionaries) from which the key/value pairs for this dictionary are taken.
The earlier in the list, the higher priority.
Note
Only this method needs to be implemented.
- get(k[, d]) → D[k] if k in D, else d. d defaults to None.¶
- all(key)[source]¶
Returns a list of all the values associated with the key.
The order of the elements in the returned list is from highest priority(first) to lowest.
If the key is missing then an empty dictionary is returned.
- keys()[source]¶
Creates a set of all the keys across all the dictionaries.
Note
Each key will appear exactly once and in an undefined order.
- items() → list of D's (key, value) pairs, as 2-tuples¶
- values() → list of D's values¶
- __getitem__(key)[source]¶
Returns the value for key found in the first dictionary or raises a KeyError
Parameters: key – The key to find. Raises KeyError: When the key cannot be found.
- __eq__(other)¶
- __ne__(other)¶