Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def set(self, value):
self.sources.insert(0, ConfigSource.of(value))
def of(cls, value):
"""Given either a dictionary or a `ConfigSource` object, return
a `ConfigSource` object. This lets a function accept either type
of object as an argument.
"""
if isinstance(value, ConfigSource):
return value
elif isinstance(value, dict):
return ConfigSource(value)
else:
raise TypeError(u'source value must be a dict')
def add(self, obj):
self.sources.append(ConfigSource.of(obj))
def of(cls, value):
"""Given either a dictionary or a `ConfigSource` object, return
a `ConfigSource` object. This lets a function accept either type
of object as an argument.
"""
if isinstance(value, ConfigSource):
return value
elif isinstance(value, dict):
return ConfigSource(value)
else:
raise TypeError(u'source value must be a dict')
def _add_default_source(self):
"""Add the package's default configuration settings. This looks
for a YAML file located inside the package for the module
`modname` if it was given.
"""
if self.modname:
if self._package_path:
filename = os.path.join(self._package_path, DEFAULT_FILENAME)
if os.path.isfile(filename):
yaml_data = yaml_util.load_yaml(
filename,
loader=self.loader,
)
self.add(ConfigSource(yaml_data, filename, True))
def _add_user_source(self):
"""Add the configuration options from the YAML file in the
user's configuration directory (given by `config_dir`) if it
exists.
"""
filename = self.user_config_path()
if os.path.isfile(filename):
yaml_data = yaml_util.load_yaml(filename, loader=self.loader) \
or {}
self.add(ConfigSource(yaml_data, filename))
def __init__(self, value, filename=None, default=False):
super(ConfigSource, self).__init__(value)
if (filename is not None
and not isinstance(filename, BASESTRING)):
raise TypeError(u'filename must be a string or None')
self.filename = filename
self.default = default