草庐IT

colander

全部标签

python - 用漏勺捕捉空列表

我正在使用colander来验证(和反序列化json数据)对一些网络服务的输入。我想向漏勺模式添加规则以捕获空列表,但我不知道该怎么做。现在我有以下示例,演示了使用两组不同的数据调用函数f()。我希望后者触发colander.Invalid异常,因为events列表为空importcolanderdeff(data):classEventList(colander.SequenceSchema):list_item=colander.SchemaNode(colander.Int())classSchema(colander.MappingSchema):txt=colander.Sc