def _attribute_match_query(self, attribute_names, query):
"""
Take a list/tuple of attributes that can match and a query, return True
if any of the attributes match the query.
"""
assert isinstance(attribute_names, (list, tuple))
if isinstance(query, string_instance) and query.startswith("re:"):
query = re.compile(query[3:])
for attribute in attribute_names:
if callable(query):
if query(attribute):
return True
elif isinstance(query, string_instance) and query.startswith("g:"):
if fnmatch(attribute, query[2:]):
return True
elif isinstance(query, re._pattern_type):
if query.match(attribute):
return True
elif isinstance(query, (list, tuple)):
if attribute in query:
return True
else:
if attribute == query:
return True
return False
评论列表
文章目录