Merge pull request #1946 from hroff-1902/validator-cosmetics

minor: json validator cosmetics
This commit is contained in:
Matthias 2019-06-19 19:32:22 +02:00 committed by GitHub
commit 38712f8120
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -34,13 +34,17 @@ def set_loggers(log_level: int = 0) -> None:
logging.getLogger('telegram').setLevel(logging.INFO)
def _extend_with_default(validator_class):
validate_properties = validator_class.VALIDATORS["properties"]
def _extend_validator(validator_class):
"""
Extended validator for the Freqtrade configuration JSON Schema.
Currently it only handles defaults for subschemas.
"""
validate_properties = validator_class.VALIDATORS['properties']
def set_defaults(validator, properties, instance, schema):
for prop, subschema in properties.items():
if "default" in subschema:
instance.setdefault(prop, subschema["default"])
if 'default' in subschema:
instance.setdefault(prop, subschema['default'])
for error in validate_properties(
validator, properties, instance, schema,
@ -48,11 +52,11 @@ def _extend_with_default(validator_class):
yield error
return validators.extend(
validator_class, {"properties": set_defaults},
validator_class, {'properties': set_defaults}
)
ValidatorWithDefaults = _extend_with_default(Draft4Validator)
FreqtradeValidator = _extend_validator(Draft4Validator)
class Configuration(object):
@ -339,7 +343,7 @@ class Configuration(object):
:return: Returns the config if valid, otherwise throw an exception
"""
try:
ValidatorWithDefaults(constants.CONF_SCHEMA).validate(conf)
FreqtradeValidator(constants.CONF_SCHEMA).validate(conf)
return conf
except ValidationError as exception:
logger.critical(