- @staticmethod
- def _ContainerToDicts(container):
- """Convert the elements of a container to standard python types.
-
- This method converts a container with elements derived from
- ConfigData to standard python types. If the container is a dict,
- we don't touch the keys, only the values.
-
- """
- if isinstance(container, dict):
- ret = dict([(k, v.ToDict()) for k, v in container.iteritems()])
- elif isinstance(container, (list, tuple, set, frozenset)):
- ret = [elem.ToDict() for elem in container]
- else:
- raise TypeError("Invalid type %s passed to _ContainerToDicts" %
- type(container))
- return ret
-
- @staticmethod
- def _ContainerFromDicts(source, c_type, e_type):
- """Convert a container from standard python types.
-
- This method converts a container with standard python types to
- ConfigData objects. If the container is a dict, we don't touch the
- keys, only the values.
-
- """
- if not isinstance(c_type, type):
- raise TypeError("Container type %s passed to _ContainerFromDicts is"
- " not a type" % type(c_type))
- if source is None:
- source = c_type()
- if c_type is dict:
- ret = dict([(k, e_type.FromDict(v)) for k, v in source.iteritems()])
- elif c_type in (list, tuple, set, frozenset):
- ret = c_type([e_type.FromDict(elem) for elem in source])
- else:
- raise TypeError("Invalid container type %s passed to"
- " _ContainerFromDicts" % c_type)
- return ret
-