Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def it_cant_parse_nonsense(self, tmpdir):
conffile = tmpdir.join('my.nonsense')
conffile.write(example1.yaml)
with ShouldRaise(
C.UnrecognizedConfig(S(r'Unknown config type: .*/my\.nonsense'))
):
example1.config.from_file(conffile.strpath)
result = dict(parser.items(self.projectname))
for key, value in result.items():
if key.endswith('_list'):
value = result.pop(key).split()
key = key.rsplit('_list', 1)[0]
result[key] = value
return result
elif filename.endswith(('.yaml', '.yml')):
return yaml.load(
io.open(filename),
Loader=getattr(yaml, 'CSafeLoader', yaml.SafeLoader),
)
elif filename.endswith('.json'):
return json.load(open(filename))
else:
raise UnrecognizedConfig('Unknown config type: %s' % filename)
def from_glob(self, pattern):
from pgctl.configsearch import glob
results = []
for fname in glob(pattern):
try:
config = self.from_file(fname)
except UnrecognizedConfig:
continue
else:
results.append(config)
if len(results) == 1:
return results[0]
elif len(results) > 1:
raise AmbiguousConfig('multiple configurations found at %s' % pattern)