def match(self, props):
"""
Check whether the given props match all the conditions.
"""
def match_condition(props, cond):
"""
Check whether the given props match the given condition.
"""
try:
prop, op, ref = props[cond[0]], cond[1], cond[2]
except KeyError:
return False
if op == "~":
return fnmatch.fnmatchcase(prop.lower(), ref.lower())
elif op == "=":
return prop == ref
elif op == ">":
return prop > ref
elif op == "<":
return prop < ref
else:
return False
#
return functools.reduce(operator.and_,
[ match_condition(props, cond) \
for cond in self.conditions ],
True)
评论列表
文章目录