def __init__(self, init_value=None, dirs=None, files=None, filename_as_namespace=True): ConfigDict.__init__(self) # track filenames we've loaded self.__filenames = [] # track dirnames we've loaded self.__dirnames = [] if init_value: if isinstance(init_value, (list, tuple)): for iv in init_value: self.merge(iv) elif isinstance(init_value, dict): self.merge(init_value) elif isinstance(init_value, basestring): self.merge(load_string(init_value)) else: raise Exception("Invalid config value") if dirs: if isinstance(dirs, basestring): dirs = [d.strip() for d in dirs.split(';')] self.load_dirs(dirs, filename_as_namespace=filename_as_namespace) if files: if isinstance(files, basestring): files = [f.strip() for f in files.split(';')] self._load_files(files)
def merge(self, *args): """ Merges this instance with new instances, in-place. returns the self.empty(), if the empty string or None was passed as data. """ for data in args: to_merge = None if isinstance(data, str): to_merge = load_string(data) else: to_merge = data if self.can_merge(to_merge): self._merge(to_merge) else: raise ValueError('Cannot merge myself:%s with %s. data: %s' % (type(self),type(data),data))
def __init__(self, init_value=None, dirs=None, files=None, filename_as_namespace=True): ConfigDict.__init__(self) if init_value: if isinstance(init_value, (list, tuple)): for iv in init_value: self.merge(iv) elif isinstance(init_value, dict): self.merge(init_value) elif isinstance(init_value, basestring): self.merge(load_string(init_value)) else: raise Exception("Invalid config value") if dirs: if isinstance(dirs, basestring): dirs = [d.strip() for d in dirs.split(';')] self.load_dirs(dirs, filename_as_namespace=filename_as_namespace) if files: if isinstance(files, basestring): files = [f.strip() for f in files.split(';')] self._load_files(files)
def merge(self, *args): """ Merges this instance with new instances, in-place. :param \*args: Configuration values to merge with current instance. :type \*args: iterable """ for data in args: if isinstance(data, str): to_merge = load_string(data, self.context) if not to_merge: continue else: to_merge = data if self.can_merge(to_merge): self._merge(to_merge) else: raise ConfigurationMergeError( 'Cannot merge myself:%s with %s. data: %s' % (type(self), type(data), data))
def merge(self, *args): for data in args: if isinstance(data, str): data = load_string(data) super(ConfigDict, self).merge(ConfigDict(data))