python - Overloading validate in cerberus
问题描述
I'd like to overload validate in my custom validator class so that if the client only gives me text, I can convert it to yaml for validation.
I've tried the following:
import cerberus
from cerberus import Validator
from ruamel.yaml import YAML
class SchemaValidator(Validator):
def _validate(self, schema_to_check_in_text, schema_from_catalog_in_yaml):
ruamel_yaml = YAML()
parsed_proposed_yaml = ruamel_yaml.load(schema_to_check_in_text)
self.validate(parsed_proposed_yaml, schema_from_catalog_in_yaml)
But it doesn't work. Is this possible?
解决方案
您不会重载任何东西,而是添加一个额外的方法,按照约定标记为私有。
推荐阅读
- javascript - 如何从作为appium中元素承诺的一部分的元素中提取文本
- vue.js - Vue - URL 查询参数未显示
- python - 无法计算 Add 作为输入 #1(从零开始)应该是一个 int32 张量,但它是一个双张量 [Op:Add]
- c# - 橡皮筋(在 Unity 2D 中实现)
- c++ - 在什么情况下你应该更喜欢使用 std::copy 写入 cout?
- javascript - TypeScript 不解决序列化和静态类型检查,那怎么办呢?
- python - Python - 从列表中提取值
- java - 装饰器设计模式java覆盖方法问题
- powershell - 返回属性的全部值
- typescript - 打字稿:在类型上动态构造属性名称