Add configuration utilities

This commit is contained in:
allegroai 2020-11-08 00:09:15 +02:00
parent cc5da546fa
commit 9b3d107934
2 changed files with 19 additions and 0 deletions

View File

@ -16,3 +16,7 @@ class attrs(object):
def __call__(self, f):
return attr.attrs(*self.args, **self.kwargs)(f)
def readonly(value):
return property(lambda self: value)

View File

@ -1,5 +1,7 @@
from __future__ import division
import json
import six
import humanfriendly
import pyparsing
@ -81,3 +83,16 @@ def text_to_config_dict(text):
six.raise_from(ValueError("Could not parse configuration text ({}):\n{}".format(pos, text)), None)
except Exception:
six.raise_from(ValueError("Could not parse configuration text:\n{}".format(text)), None)
def verify_basic_value(value):
# return True if value of of basic type (json serializable)
if not isinstance(value,
six.string_types + six.integer_types +
(six.text_type, float, list, tuple, dict, type(None))):
return False
try:
json.dumps(value)
return True
except TypeError:
return False