cloudmesh-common.cloudmesh.common.FlatDict
¶
Module Contents¶
Classes¶
A data structure to manage a flattened dict. It is initialized by passing |
|
Functions¶
|
replaces the list of prefix in keys of a flattened dict |
|
|
|
flattens the dict into a one dimensional dictionary |
-
cloudmesh-common.cloudmesh.common.FlatDict.
collectionsAbc
¶
-
cloudmesh-common.cloudmesh.common.FlatDict.
key_prefix_replace
(d, prefix, new_prefix='')¶ replaces the list of prefix in keys of a flattened dict
- Parameters
d – the flattened dict
prefix (list of str) – a list of prefixes that are replaced with a new prefix. Typically this will be “”
new_prefix – The new prefix. By default it is set to “”
- Returns
the dict with the keys replaced as specified
-
cloudmesh-common.cloudmesh.common.FlatDict.
flatme
(d)¶
-
cloudmesh-common.cloudmesh.common.FlatDict.
flatten
(d, parent_key='', sep='__')¶ flattens the dict into a one dimensional dictionary
- Parameters
d – multidimensional dict
parent_key – replaces from the parent key
sep – the separation character used when fattening. the default is __
- Returns
the flattened dict
-
class
cloudmesh-common.cloudmesh.common.FlatDict.
FlatDict
(d, sep='__')¶ Bases:
dict
A data structure to manage a flattened dict. It is initialized by passing the dict at time of initialization.
-
property
dict
(self)¶ returns the dict :return: dict
-
__setitem__
(self, key, item)¶ sets an item at a key
- Parameters
key – this is the key
item – this is the item to be set
-
__getitem__
(self, key)¶ gets an item form the key
- Parameters
key – the key
- Returns
the value
-
__repr__
(self)¶ Return repr(self).
-
__str__
(self)¶ The string representation of the dict
- Returns
str
-
__len__
(self)¶ number of elements in the dict
- Returns
int
-
__delitem__
(self, key)¶ delete the specified item
- Parameters
key – key of the item
- Returns
dict with the elementremoved
-
keys
(self)¶ returns the keys
- Returns
list of keys
-
values
(self)¶ list of all values
- Returns
list
-
__cmp__
(self, dictionary)¶
-
__contains__
(self, item)¶ True if the dictionary has the specified key, else False.
-
add
(self, key, value)¶
-
__iter__
(self)¶ Implement iter(self).
-
__call__
(self)¶
-
__getattr__
(self, attr)¶
-
search
(self, key, value=None)¶ returns from a flatdict all keys that match the given pattern and have the given value. If the value None is specified or ommitted, all keys are returned regardless of value.
Example:
search(“cloudmesh.cloud.*.cm.active”, True)
- Parameters
key – The key pattern to be searched (given as regex)
value – The value
- Returns
keys matching the vakue in flat dict format.
-
property
-
class
cloudmesh-common.cloudmesh.common.FlatDict.
FlatDict2
¶ Bases:
object
-
classmethod
is_primitive
(cls, thing)¶
-
classmethod
convert
(cls, obj, flatten=True)¶ This function converts object into a Dict optionally Flattening it :param obj: Object to be converted :param flatten: boolean to specify if the dict has to be flattened :return dict: the dict of the object (Flattened or Un-flattened)
-
classmethod
object_to_dict
(cls, obj)¶ This function converts Objects into Dictionary
-
classmethod