def _resolve_coerce(self, schema):
"""add coerce rules to convert datatypes of int and float,
recusively using the rules combinations of cerberus:
{TERM : {RULE: --> str (STOP)
--> list/Sequence --> str (STOP)
--> dict => (if type: ADD) + RECALL
--> dict/Mapping => (if type: ADD) + RECALL
}}
"""
for term, rules in schema.items():
if isinstance(rules, _str_type):
continue
elif isinstance(rules, Sequence):
for subschema in rules:
if isinstance(subschema, Mapping):
if 'type' in subschema.keys():
self._add_coerce(subschema)
self._resolve_coerce(subschema)
elif isinstance(rules, Mapping):
if 'type' in rules.keys():
self._add_coerce(rules)
self._resolve_coerce(rules)
else:
NotImplemented
评论列表
文章目录