我这样做了,但它没有接缝工作:
class PolicyValidator(SchemaNode):
def __init__(self):
super(PolicyValidator, self).__init__(
Mapping(unknown='preserve'), validator=self.policy_range)
# self.add(SchemaNode(Range(min=0, max=0xFFFF), name="preserved"))
def policy_range(self, node, policy):
for value in policy.itervalues():
if value < 0 or value > 0xFFFF:
raise Invalid(node, '%r is not a valid permission.' % value)
我找到了另一个解决方案:
class PolicyValidator(SchemaNode):
def __init__(self, policy):
super(PolicyValidator, self).__init__(Mapping(unknown='preserve'))
for key in policy.iterkeys():
self.add(SchemaNode(Int(), name=key,
validator=Range(min=0, max=0xFFFF)))