:mod:`cloudmesh-common.cloudmesh.common.FlatDict` ================================================= .. py:module:: cloudmesh-common.cloudmesh.common.FlatDict Module Contents --------------- Classes ~~~~~~~ .. autoapisummary:: cloudmesh-common.cloudmesh.common.FlatDict.FlatDict cloudmesh-common.cloudmesh.common.FlatDict.FlatDict2 Functions ~~~~~~~~~ .. autoapisummary:: cloudmesh-common.cloudmesh.common.FlatDict.key_prefix_replace cloudmesh-common.cloudmesh.common.FlatDict.flatme cloudmesh-common.cloudmesh.common.FlatDict.flatten .. data:: collectionsAbc .. function:: key_prefix_replace(d, prefix, new_prefix='') replaces the list of prefix in keys of a flattened dict :param d: the flattened dict :param prefix: a list of prefixes that are replaced with a new prefix. Typically this will be "" :type prefix: list of str :param new_prefix: The new prefix. By default it is set to "" :return: the dict with the keys replaced as specified .. function:: flatme(d) .. function:: flatten(d, parent_key='', sep='__') flattens the dict into a one dimensional dictionary :param d: multidimensional dict :param parent_key: replaces from the parent key :param sep: the separation character used when fattening. the default is __ :return: the flattened dict .. class:: FlatDict(d, sep='__') Bases: :class:`dict` A data structure to manage a flattened dict. It is initialized by passing the dict at time of initialization. .. method:: dict(self) :property: returns the dict :return: dict .. method:: __setitem__(self, key, item) sets an item at a key :param key: this is the key :param item: this is the item to be set .. method:: __getitem__(self, key) gets an item form the key :param key: the key :return: the value .. method:: __repr__(self) Return repr(self). .. method:: __str__(self) The string representation of the dict :return: str .. method:: __len__(self) number of elements in the dict :return: int .. method:: __delitem__(self, key) delete the specified item :param key: key of the item :return: dict with the elementremoved .. method:: keys(self) returns the keys :return: list of keys .. method:: values(self) list of all values :return: list .. method:: __cmp__(self, dictionary) .. method:: __contains__(self, item) True if the dictionary has the specified key, else False. .. method:: add(self, key, value) .. method:: __iter__(self) Implement iter(self). .. method:: __call__(self) .. method:: __getattr__(self, attr) .. method:: 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) :param key: The key pattern to be searched (given as regex) :param value: The value :return: keys matching the vakue in flat dict format. .. class:: FlatDict2 Bases: :class:`object` .. method:: is_primitive(cls, thing) :classmethod: .. method:: convert(cls, obj, flatten=True) :classmethod: 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) .. method:: object_to_dict(cls, obj) :classmethod: This function converts Objects into Dictionary