comparison data_schema/__init__.py @ 23:413b344be2d1

Consistent naming of validation methods: all lowercase
author Franz Glasner <fzglas.hg@dom66.de>
date Sat, 08 Jul 2023 10:15:50 +0200
parents c3a0fe8d4587
children fd2a40c3d87b
comparison
equal deleted inserted replaced
22:945ef382a1d1 23:413b344be2d1
554 combinator_schema = t[combinator] 554 combinator_schema = t[combinator]
555 if combinator == "not": 555 if combinator == "not":
556 yield from validate_not( 556 yield from validate_not(
557 obj, schema.ensure_child_schema(combinator_schema), context) 557 obj, schema.ensure_child_schema(combinator_schema), context)
558 elif combinator == "all-of": 558 elif combinator == "all-of":
559 yield from validate_allOf( 559 yield from validate_all_of(
560 obj, 560 obj,
561 schema.ensure_list_of_child_schemata(combinator_schema), 561 schema.ensure_list_of_child_schemata(combinator_schema),
562 context) 562 context)
563 elif combinator == "any-of": 563 elif combinator == "any-of":
564 yield from validate_anyOf( 564 yield from validate_any_of(
565 obj, 565 obj,
566 schema.ensure_list_of_child_schemata(combinator_schema), 566 schema.ensure_list_of_child_schemata(combinator_schema),
567 context) 567 context)
568 elif combinator == "one-of": 568 elif combinator == "one-of":
569 yield from validate_oneOf( 569 yield from validate_one_of(
570 obj, 570 obj,
571 schema.ensure_list_of_child_schemata(combinator_schema), 571 schema.ensure_list_of_child_schemata(combinator_schema),
572 context) 572 context)
573 else: 573 else:
574 raise SchemaError("unknown combinator: {}".format(combinator)) 574 raise SchemaError("unknown combinator: {}".format(combinator))
575 elif isinstance(t, (list, tuple)): 575 elif isinstance(t, (list, tuple)):
576 # a simple list is "any-of" 576 # a simple list is "any-of"
577 yield from validate_anyOf( 577 yield from validate_any_of(
578 obj, schema.ensure_list_of_child_schemata(t), context) 578 obj, schema.ensure_list_of_child_schemata(t), context)
579 elif t in ("dict", "map", "object"): 579 elif t in ("dict", "map", "object"):
580 yield from validate_dict(obj, schema, context) 580 yield from validate_dict(obj, schema, context)
581 elif t in ("list", "array",): 581 elif t in ("list", "array",):
582 yield from validate_list(obj, schema, context) 582 yield from validate_list(obj, schema, context)
1043 yield ValidationProblem(code=ERRORS.E10027, hint=obj, context=context) 1043 yield ValidationProblem(code=ERRORS.E10027, hint=obj, context=context)
1044 elif not value and obj: 1044 elif not value and obj:
1045 yield ValidationProblem(code=ERRORS.E10028, hint=obj, context=context) 1045 yield ValidationProblem(code=ERRORS.E10028, hint=obj, context=context)
1046 1046
1047 1047
1048 def validate_allOf(obj, schema, context): 1048 def validate_all_of(obj, schema, context):
1049 if not isinstance(schema, (list, tuple)): 1049 if not isinstance(schema, (list, tuple)):
1050 raise SchemaError("require a list of schematas for `all-of'") 1050 raise SchemaError("require a list of schematas for `all-of'")
1051 res = [] 1051 res = []
1052 for idx, s in enumerate(schema): 1052 for idx, s in enumerate(schema):
1053 assert isinstance(s, _Schema) 1053 assert isinstance(s, _Schema)
1064 context=context, 1064 context=context,
1065 cause=tr, 1065 cause=tr,
1066 index=idx) for (idx, tr) in res]) 1066 index=idx) for (idx, tr) in res])
1067 1067
1068 1068
1069 def validate_anyOf(obj, schema, context): 1069 def validate_any_of(obj, schema, context):
1070 if not isinstance(schema, (list, tuple)): 1070 if not isinstance(schema, (list, tuple)):
1071 raise SchemaError("require a list of schematas for `any-of'") 1071 raise SchemaError("require a list of schematas for `any-of'")
1072 res = [] 1072 res = []
1073 for s in schema: 1073 for s in schema:
1074 assert isinstance(s, _Schema) 1074 assert isinstance(s, _Schema)
1088 code=ERRORS.E10056, 1088 code=ERRORS.E10056,
1089 context=context, 1089 context=context,
1090 cause=tr) for tr in res]) 1090 cause=tr) for tr in res])
1091 1091
1092 1092
1093 def validate_oneOf(obj, schema, context): 1093 def validate_one_of(obj, schema, context):
1094 if not isinstance(schema, (list, tuple)): 1094 if not isinstance(schema, (list, tuple)):
1095 raise SchemaError("require a list of schematas for `one-of'") 1095 raise SchemaError("require a list of schematas for `one-of'")
1096 success_res = [] 1096 success_res = []
1097 failed_res = [] 1097 failed_res = []
1098 for idx, s in enumerate(schema): 1098 for idx, s in enumerate(schema):