Mercurial > hgrepos > Python > libs > data-schema
diff data_schema/__init__.py @ 13:940676a0de84
ERRORS and WARNINGS are now enums
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Fri, 07 Jul 2023 02:10:32 +0200 |
| parents | 62823085e582 |
| children | cfb97c7c9e5b |
line wrap: on
line diff
--- a/data_schema/__init__.py Fri Jul 07 01:32:49 2023 +0200 +++ b/data_schema/__init__.py Fri Jul 07 02:10:32 2023 +0200 @@ -31,6 +31,7 @@ import collections import copy import datetime +import enum import re import urllib.parse @@ -57,74 +58,82 @@ } _name_to_level = {name: level for (level, name) in _level_to_name.items()} -ERRORS = { - 10000: NC_("schema-msg", "dict expected"), - 10001: NC_("schema-msg", "list expected"), - 10002: NC_("schema-msg", "string expected"), - 10003: NC_("schema-msg", "dict key must be a string"), - 10004: NC_("schema-msg", "additional key encountered"), - 10005: NC_("schema-msg", "required key(s) missing"), - 10006: NC_("schema-msg", "min string length encountered"), - 10007: NC_("schema-msg", "max string length exceeded"), - 10008: NC_("schema-msg", "string value does not match the required RE pattern"), - 10009: NC_("schema-msg", "string value does not validate"), - 10010: NC_("schema-msg", "validation error"), - 10011: NC_("schema-msg", "None/Null object expected"), - 10012: NC_("schema-msg", "min list length encountered"), - 10013: NC_("schema-msg", "max list length exceeded"), - 10014: NC_("schema-msg", "tuple expected"), - 10015: NC_("schema-msg", "min tuple length encountered"), - 10016: NC_("schema-msg", "max tuple length exceeded"), - 10017: NC_("schema-msg", "additional items in tuple not allowed"), - 10018: NC_("schema-msg", "object is not empty"), - 10019: NC_("schema-msg", "more than one match in `one-of' detected"), - 10020: NC_("schema-msg", "int expected"), - 10021: NC_("schema-msg", "int value lower than minValue"), - 10022: NC_("schema-msg", "int value greater than maxValue"), - 10023: NC_("schema-msg", "float expected"), - 10024: NC_("schema-msg", "float value lower than minValue"), - 10025: NC_("schema-msg", "float value greater than maxValue"), - 10026: NC_("schema-msg", "boolean value expected"), - 10027: NC_("schema-msg", "boolean true expected"), - 10028: NC_("schema-msg", "boolean false expected"), - 10029: NC_("schema-msg", "`not' expected problems but got none"), - 10030: NC_("schema-msg", "numeric type (int or float) expected"), - 10031: NC_("schema-msg", "numeric value lower than minValue"), - 10032: NC_("schema-msg", "numeric value greater than maxValue"), - 10033: NC_("schema-msg", "a plain scalar value expected"), - 10034: NC_("schema-msg", "dict key does not match required schema"), - 10035: NC_("schema-msg", "binary data expected"), - 10036: NC_("schema-msg", "length of binary data lower than minValue"), - 10037: NC_("schema-msg", "length of binary data exceeds maxValue"), - 10038: NC_("schema-msg", "a set is expected"), - 10039: NC_("schema-msg", "length of set lower than minLength"), - 10040: NC_("schema-msg", "length of set greater than maxLength"), - 10041: NC_("schema-msg", "timestamp expected"), - 10042: NC_("schema-msg", "value of timestamp does not validate"), - 10043: NC_("schema-msg", "enumerated string value expected but not found"), - 10044: NC_("schema-msg", "referenced object doest not exist"), - 10045: NC_("schema-msg", "key is not contained in referenced object"), - 10046: NC_("schema-msg", "referenced object is not a container"), - 10047: NC_("schema-msg", "binary data does not match the required RE pattern"), - 10048: NC_("schema-msg", "enumerated integer value expected but not found"), - 10049: NC_("schema-msg", "enumerated number value expected but not found"), - 10050: NC_("schema-msg", "min dict length encountered"), - 10051: NC_("schema-msg", "max dict length exceeded"), - 10052: NC_("schema-msg", "index constraint violated"), - 10053: NC_("schema-msg", "`one-of' failed"), - 10054: NC_("schema-msg", "failing `one-of' item"), - 10055: NC_("schema-msg", "`any-of' failed"), - 10056: NC_("schema-msg", "failing `any-of' item"), - 10057: NC_("schema-msg", "`all-of' failed"), - 10058: NC_("schema-msg", "failing `all-of' item"), -} -WARNINGS = { - 80000: NC_("schema-msg", "duplicate dict key"), -} +@enum.unique +class ERRORS(enum.Enum): + E10000 = NC_("schema-msg", "dict expected") + E10001 = NC_("schema-msg", "list expected") + E10002 = NC_("schema-msg", "string expected") + E10003 = NC_("schema-msg", "dict key must be a string") + E10004 = NC_("schema-msg", "additional key encountered") + E10005 = NC_("schema-msg", "required key(s) missing") + E10006 = NC_("schema-msg", "min string length encountered") + E10007 = NC_("schema-msg", "max string length exceeded") + E10008 = NC_("schema-msg", "string value does not match the required RE pattern") + E10009 = NC_("schema-msg", "string value does not validate") + E10010 = NC_("schema-msg", "validation error") + E10011 = NC_("schema-msg", "None/Null object expected") + E10012 = NC_("schema-msg", "min list length encountered") + E10013 = NC_("schema-msg", "max list length exceeded") + E10014 = NC_("schema-msg", "tuple expected") + E10015 = NC_("schema-msg", "min tuple length encountered") + E10016 = NC_("schema-msg", "max tuple length exceeded") + E10017 = NC_("schema-msg", "additional items in tuple not allowed") + E10018 = NC_("schema-msg", "object is not empty") + E10019 = NC_("schema-msg", "more than one match in `one-of' detected") + E10020 = NC_("schema-msg", "int expected") + E10021 = NC_("schema-msg", "int value lower than minValue") + E10022 = NC_("schema-msg", "int value greater than maxValue") + E10023 = NC_("schema-msg", "float expected") + E10024 = NC_("schema-msg", "float value lower than minValue") + E10025 = NC_("schema-msg", "float value greater than maxValue") + E10026 = NC_("schema-msg", "boolean value expected") + E10027 = NC_("schema-msg", "boolean true expected") + E10028 = NC_("schema-msg", "boolean false expected") + E10029 = NC_("schema-msg", "`not' expected problems but got none") + E10030 = NC_("schema-msg", "numeric type (int or float) expected") + E10031 = NC_("schema-msg", "numeric value lower than minValue") + E10032 = NC_("schema-msg", "numeric value greater than maxValue") + E10033 = NC_("schema-msg", "a plain scalar value expected") + E10034 = NC_("schema-msg", "dict key does not match required schema") + E10035 = NC_("schema-msg", "binary data expected") + E10036 = NC_("schema-msg", "length of binary data lower than minValue") + E10037 = NC_("schema-msg", "length of binary data exceeds maxValue") + E10038 = NC_("schema-msg", "a set is expected") + E10039 = NC_("schema-msg", "length of set lower than minLength") + E10040 = NC_("schema-msg", "length of set greater than maxLength") + E10041 = NC_("schema-msg", "timestamp expected") + E10042 = NC_("schema-msg", "value of timestamp does not validate") + E10043 = NC_("schema-msg", "enumerated string value expected but not found") + E10044 = NC_("schema-msg", "referenced object doest not exist") + E10045 = NC_("schema-msg", "key is not contained in referenced object") + E10046 = NC_("schema-msg", "referenced object is not a container") + E10047 = NC_("schema-msg", "binary data does not match the required RE pattern") + E10048 = NC_("schema-msg", "enumerated integer value expected but not found") + E10049 = NC_("schema-msg", "enumerated number value expected but not found") + E10050 = NC_("schema-msg", "min dict length encountered") + E10051 = NC_("schema-msg", "max dict length exceeded") + E10052 = NC_("schema-msg", "index constraint violated") + E10053 = NC_("schema-msg", "`one-of' failed") + E10054 = NC_("schema-msg", "failing `one-of' item") + E10055 = NC_("schema-msg", "`any-of' failed") + E10056 = NC_("schema-msg", "failing `any-of' item") + E10057 = NC_("schema-msg", "`all-of' failed") + E10058 = NC_("schema-msg", "failing `all-of' item") -if not set(ERRORS.keys()).isdisjoint(set(WARNINGS.keys())): - raise ValueError("ERRORS and WARNINGS must be disjoint") + +@enum.unique +class WARNINGS(enum.Enum): + W80000 = NC_("schema-msg", "duplicate dict key") + + +# Check some invariants at import time +for e in ERRORS.__members__: + assert e.startswith('E'), "ERROR code `{}' shall start with letter `E'".format(e) + assert 10000 <= int(e[1:], 10) < 80000, "Invalid ERROR code number in `{}'".format(e) +for w in WARNINGS.__members__: + assert w.startswith('W'), "WARNING code `{}' must start with letter `W'".format(w) + assert 80000 <= int(w[1:], 10), "Invalid WARNING code number in `{}'".format(w) TYPE_RE = type(re.compile(r"\A.+\Z")) @@ -151,12 +160,14 @@ def problem_message(pr): if isinstance(pr, ValidationProblem): code = getattr(pr, "code", None) - else: + elif isinstance(pr, (ERRORS, WARNINGS)): code = pr - msg = ERRORS.get(code, None) - if msg is None: - msg = WARNINGS[code] - return msg + else: + if pr >= 80000: + code = WARNINGS["W" + str(pr)] + else: + code = ERRORS["E" + str(pr)] + return code.value class ValidationProblem(object): @@ -645,24 +656,24 @@ if idx == effective_index: break else: - yield ValidationProblem(code=10052, context=context) + yield ValidationProblem(code=ERRORS.E10052, context=context) def validate_dict(obj, schema, context): if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, dict): - yield ValidationProblem(code=10000, hint="got: {}".format(type(obj).__name__), context=context) + yield ValidationProblem(code=ERRORS.E10000, hint="got: {}".format(type(obj).__name__), context=context) return yield from _validate_index_constraint(obj, schema, context) minlen = schema.get("minLength", None) if minlen: if len(obj) < minlen: - yield ValidationProblem(code=10050, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10050, hint=obj, context=context) maxlen = schema.get("maxLength", None) if maxlen is not None: if len(obj) > maxlen: - yield ValidationProblem(code=10051, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10051, hint=obj, context=context) schema_keys = schema.get("keys", {}) if schema else {} seen_keys = set() schema_keynames = schema.get_child("keyNames", None) @@ -671,18 +682,18 @@ idx += 1 if schema_keynames is None: if not isinstance(key, str): - yield ValidationProblem(code=10003, hint=repr(key), context=context) + yield ValidationProblem(code=ERRORS.E10003, hint=repr(key), context=context) else: # validate the key against given schema new_context = Context(context, key=key, key_index=idx, current_object=key) key_probs = list(_validate(key, schema_keynames, new_context)) if key_probs: yield ValidationProblem( - code=10034, hint=key, context=context, cause=key_probs) + code=ERRORS.E10034, hint=key, context=context, cause=key_probs) if context.settings.break_on_keynames_problems: return if key in seen_keys: - yield ValidationProblem(code=80000, hint=key, context=context) + yield ValidationProblem(code=WARNINGS.W80000, hint=key, context=context) else: seen_keys.add(key) # XXX FIXME: context: new leaf context with new key for recursion @@ -695,7 +706,7 @@ if isinstance(additional_keys, bool): if not additional_keys: if not _is_in_skip_keys(key, context.settings.skip_keys): - yield ValidationProblem(code=10004, hint=str(key), context=context) + yield ValidationProblem(code=ERRORS.E10004, hint=str(key), context=context) else: if not _is_in_skip_keys(key, context.settings.skip_keys): # try this as the common schema for all the additional keys @@ -708,24 +719,24 @@ raise SchemaError("`required` must be an iterable") if not required_keys <= seen_keys: hs = [str(i) for i in required_keys - seen_keys] - yield ValidationProblem(code=10005, hint=sorted(hs), context=context) + yield ValidationProblem(code=ERRORS.E10005, hint=sorted(hs), context=context) def validate_list(obj, schema, context): if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, (list, tuple)): - yield ValidationProblem(code=10001, hint="got: {}".format(type(obj).__name__), context=context) + yield ValidationProblem(code=ERRORS.E10001, hint="got: {}".format(type(obj).__name__), context=context) return yield from _validate_index_constraint(obj, schema, context) minlen = schema.get("minLength", None) if minlen: if len(obj) < minlen: - yield ValidationProblem(code=10012, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10012, hint=obj, context=context) maxlen = schema.get("maxLength", None) if maxlen is not None: if len(obj) > maxlen: - yield ValidationProblem(code=10013, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10013, hint=obj, context=context) try: schema_items = schema.ensure_child_schema(schema["items"]) except KeyError: @@ -739,17 +750,17 @@ if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, (set, frozenset)): - yield ValidationProblem(code=10038, hint="got: {}".format(type(obj).__name__), context=context) + yield ValidationProblem(code=ERRORS.E10038, hint="got: {}".format(type(obj).__name__), context=context) return yield from _validate_index_constraint(obj, schema, context) minlen = schema.get("minLength", None) if minlen: if len(obj) < minlen: - yield ValidationProblem(code=10039, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10039, hint=obj, context=context) maxlen = schema.get("maxLength", None) if maxlen is not None: if len(obj) > maxlen: - yield ValidationProblem(code=10040, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10040, hint=obj, context=context) try: schema_items = schema.ensure_child_schema(schema["items"]) except KeyError: @@ -763,17 +774,17 @@ if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, (list, tuple)): - yield ValidationProblem(code=10014, hint="got: {}".format(type(obj).__name__), context=context) + yield ValidationProblem(code=ERRORS.E10014, hint="got: {}".format(type(obj).__name__), context=context) return yield from _validate_index_constraint(obj, schema, context) minlen = schema.get("minLength", None) if minlen: if len(obj) < minlen: - yield ValidationProblem(code=10015, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10015, hint=obj, context=context) maxlen = schema.get("maxLength", None) if maxlen is not None: if len(obj) > maxlen: - yield ValidationProblem(code=10016, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10016, hint=obj, context=context) schema_items = schema.get("items", []) if not isinstance(schema_items, (list, tuple)): raise SchemaError("tuple items require a list of schemata in items") @@ -788,7 +799,7 @@ additional_items = schema.get_child("additionalItems", False) if isinstance(additional_items, bool): if not additional_items: - yield ValidationProblem(code=10017, context=new_context) + yield ValidationProblem(code=ERRORS.E10017, context=new_context) else: yield from _validate(o, additional_items, new_context) else: @@ -799,7 +810,7 @@ if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, str): - yield ValidationProblem(code=10002, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10002, hint=obj, context=context) else: yield from _validate_index_constraint(obj, schema, context) enumvalues = schema.get("enum", None) @@ -808,25 +819,25 @@ if ev == obj: break else: - yield ValidationProblem(code=10043, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10043, hint=obj, context=context) minlen = schema.get("minLength", None) if minlen: if len(obj) < minlen: - yield ValidationProblem(code=10006, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10006, hint=obj, context=context) maxlen = schema.get("maxLength", None) if maxlen is not None: if len(obj) > maxlen: - yield ValidationProblem(code=10007, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10007, hint=obj, context=context) pattern = schema.get("pattern", None) if pattern is not None: if isinstance(pattern, str): mo = re.search(pattern, obj) if not mo: - yield ValidationProblem(code=10008, context=context) + yield ValidationProblem(code=ERRORS.E10008, context=context) elif isinstance(pattern, TYPE_RE): mo = pattern.search(obj) if not mo: - yield ValidationProblem(code=10008, context=context) + yield ValidationProblem(code=ERRORS.E10008, context=context) elif callable(pattern): yield from pattern(obj, schema, context) else: @@ -838,28 +849,28 @@ schema, default=_SENTINEL) if refobj is _SENTINEL: - yield ValidationProblem(code=10044, context=context) + yield ValidationProblem(code=ERRORS.E10044, context=context) else: try: if obj not in refobj: - yield ValidationProblem(code=10045, context=context) + yield ValidationProblem(code=ERRORS.E10045, context=context) except TypeError: - yield ValidationProblem(code=10046, context=context) + yield ValidationProblem(code=ERRORS.E10046, context=context) def validate_binary(obj, schema, context): if not isinstance(obj, (bytes, bytearray)): - yield ValidationProblem(code=10035, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10035, hint=obj, context=context) else: yield from _validate_index_constraint(obj, schema, context) minlen = schema.get("minLength", None) if minlen: if len(obj) < minlen: - yield ValidationProblem(code=10036, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10036, hint=obj, context=context) maxlen = schema.get("maxLength", None) if maxlen is not None: if len(obj) > maxlen: - yield ValidationProblem(code=10037, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10037, hint=obj, context=context) pattern = schema.get("pattern", None) if pattern is not None: if isinstance(pattern, (str, bytes, bytearray)): @@ -876,11 +887,11 @@ bytes_pattern = pattern mo = re.search(bytes_pattern, obj) if not mo: - yield ValidationProblem(code=10047, context=context) + yield ValidationProblem(code=ERRORS.E10047, context=context) elif isinstance(pattern, TYPE_RE): mo = pattern.search(obj) if not mo: - yield ValidationProblem(code=10047, context=context) + yield ValidationProblem(code=ERRORS.E10047, context=context) elif callable(pattern): yield from pattern(obj, schema, context) else: @@ -889,7 +900,7 @@ def validate_timestamp(obj, schema, context): if not isinstance(obj, datetime.datetime): - yield ValidationProblem(code=10041, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10041, hint=obj, context=context) else: yield from _validate_index_constraint(obj, schema, context) value = schema.get("value", None) @@ -904,22 +915,22 @@ if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, int): - yield ValidationProblem(code=10020, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10020, hint=obj, context=context) else: yield from _validate_index_constraint(obj, schema, context) minValue = schema.get("minValue", None) if minValue is not None and obj < minValue: - yield ValidationProblem(code=10021, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10021, hint=obj, context=context) maxValue = schema.get("maxValue", None) if maxValue is not None and obj > maxValue: - yield ValidationProblem(code=10022, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10022, hint=obj, context=context) enumvalues = schema.get("enum", None) if enumvalues is not None: for ev in enumvalues: if ev == obj: break else: - yield ValidationProblem(code=10048, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10048, hint=obj, context=context) value = schema.get("value", None) if value is not None: if callable(value): @@ -932,15 +943,15 @@ if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, float): - yield ValidationProblem(code=10023, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10023, hint=obj, context=context) else: yield from _validate_index_constraint(obj, schema, context) minValue = schema.get("minValue", None) if minValue is not None and obj < minValue: - yield ValidationProblem(code=10024, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10024, hint=obj, context=context) maxValue = schema.get("maxValue", None) if maxValue is not None and obj > maxValue: - yield ValidationProblem(code=10025, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10025, hint=obj, context=context) value = schema.get("value", None) if value is not None: if callable(value): @@ -953,26 +964,26 @@ if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, (int, float)): - yield ValidationProblem(code=10030, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10030, hint=obj, context=context) else: yield from _validate_index_constraint(obj, schema, context) minValue = schema.get("minValue", None) if minValue is not None and isinstance(obj, float): minValue *= 1.0 if minValue is not None and obj < minValue: - yield ValidationProblem(code=10031, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10031, hint=obj, context=context) maxValue = schema.get("maxValue", None) if maxValue is not None and isinstance(obj, float): maxValue *= 1.0 if maxValue is not None and obj > maxValue: - yield ValidationProblem(code=10032, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10032, hint=obj, context=context) enumvalues = schema.get("enum", None) if enumvalues is not None: for ev in enumvalues: if ev == obj: break else: - yield ValidationProblem(code=10049, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10049, hint=obj, context=context) value = schema.get("value", None) if value is not None: if callable(value): @@ -986,14 +997,14 @@ return yield from _validate_index_constraint(obj, schema, context) if obj is None: - yield ValidationProblem(code=10033, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10033, hint=obj, context=context) if isinstance(obj, (dict, list, tuple, set, frozenset)): - yield ValidationProblem(code=10033, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10033, hint=obj, context=context) def validate_deny(obj, schema, context): yield from _validate_index_constraint(obj, schema, context) - yield ValidationProblem(code=10010, context=context) + yield ValidationProblem(code=ERRORS.E10010, context=context) def validate_accept(obj, schema, context): @@ -1003,7 +1014,7 @@ def validate_null(obj, schema, context): yield from _validate_index_constraint(obj, schema, context) if obj is not None: - yield ValidationProblem(code=10011, context=context) + yield ValidationProblem(code=ERRORS.E10011, context=context) def validate_empty(obj, schema, context): @@ -1012,14 +1023,14 @@ return if isinstance(obj, (dict, list, tuple, set, frozenset)) and not obj: return - yield ValidationProblem(10018, context=context) + yield ValidationProblem(ERRORS.E10018, context=context) def validate_bool(obj, schema, context): if _is_null_allowed_for_object(obj, schema, context): return if not isinstance(obj, bool): - yield ValidationProblem(code=10026, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10026, hint=obj, context=context) else: yield from _validate_index_constraint(obj, schema, context) value = schema.get("value", None) @@ -1027,9 +1038,9 @@ if callable(value): yield from value(obj, schema, context) elif value and not obj: - yield ValidationProblem(code=10027, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10027, hint=obj, context=context) elif not value and obj: - yield ValidationProblem(code=10028, hint=obj, context=context) + yield ValidationProblem(code=ERRORS.E10028, hint=obj, context=context) def validate_allOf(obj, schema, context): @@ -1043,11 +1054,11 @@ res.append((idx, tr, )) if res: yield ValidationProblem( - code=10057, + code=ERRORS.E10057, context=context, cause=[ ValidationProblem( - code=10058, + code=ERRORS.E10058, context=context, cause=tr, index=idx) for (idx, tr) in res]) @@ -1068,11 +1079,11 @@ # Ansonsten: alle Fehlschlaege protokollieren if res: yield ValidationProblem( - code=10055, + code=ERRORS.E10055, context=context, cause=[ ValidationProblem( - code=10056, + code=ERRORS.E10056, context=context, cause=tr) for tr in res]) @@ -1095,24 +1106,24 @@ # Ansonsten: alle Fehlschlaege protokollieren if failed_res: yield ValidationProblem( - code=10053, + code=ERRORS.E10053, context=context, cause=[ ValidationProblem( - code=10054, + code=ERRORS.E10054, context=context, cause=tr, index=idx) for (idx, tr) in failed_res]) else: # Die Indizes der "zuvielen" in "hint" anzeigen - yield ValidationProblem(code=10019, hint=",".join([str(k) for k in success_res])) + yield ValidationProblem(code=ERRORS.E10019, hint=",".join([str(k) for k in success_res])) def validate_not(obj, schema, context): assert isinstance(schema, _Schema) res = list(_validate(obj, schema, context)) if not res: - yield ValidationProblem(code=10029, hint=obj, context=context, + yield ValidationProblem(code=ERRORS.E10029, hint=obj, context=context, cause=res)
