def __call__(self, inst, attr, value):
if not isinstance(value, dict) and \
not isinstance(value, MappingProxyType):
raise TypeError(
"""'{name}' must be a dict object or
instance of MappingProxyType.""".format(
name=attr.name,
),
)
if not self.required_keypaths:
return
for keypath in self.required_keypaths:
current = value
components = keypath.split('.')
for component in components[:-1]:
current = current.get(component, {})
if components[-1] not in current:
raise DictValidatorKeypathDoesNotExistError(
"'{keypath}' not found".format(
keypath=keypath,
)
)
评论列表
文章目录