Ejemplo n.º 1
0
 def __generate(self, schema: JSON = dict) -> JSON:
     data = dict()
     for k, v in schema.items():
         if isinstance(v, dict):
             data[k] = self.__generate(v)
         elif isinstance(v, list):
             data[k] = [self.__generate(i) for i in v]
         else:
             provider, method = v.split('.')
             data[k] = getattr(
                 getattr(self.generic, provider), method)()
     return data
Ejemplo n.º 2
0
    def _update_dict(self, initial: JSON, other: Mapping) -> JSON:
        """Recursively update a dictionary.

        :param initial: Dict to update.
        :param other: Dict to update from.
        :return: Updated dict.
        """
        for key, value in other.items():
            if isinstance(value, collections.abc.Mapping):
                r = self._update_dict(initial.get(key, {}), value)
                initial[key] = r
            else:
                initial[key] = other[key]
        return initial
Ejemplo n.º 3
0
def update_dict(initial: JSON, other: Mapping) -> JSON:
    """Recursively update a dictionary.

    :param initial: Dict to update.
    :type initial: dict or list
    :param other: Dict to update from.
    :type other: Mapping
    :return: Updated dict.
    :rtype: dict
    """
    for key, value in other.items():
        if isinstance(value, collections.Mapping):
            r = update_dict(initial.get(key, {}), value)
            initial[key] = r
        else:
            initial[key] = other[key]
    return initial