Add a has_matches() method for convenience

This commit is contained in:
Kovid Goyal 2015-02-21 10:47:31 +05:30
parent 880391ce34
commit e7caf265c1

View File

@ -141,6 +141,7 @@ class Select(object):
else: else:
self.ignore_inappropriate_pseudo_classes = frozenset() self.ignore_inappropriate_pseudo_classes = frozenset()
# External API {{{
def invalidate_caches(self): def invalidate_caches(self):
'Invalidate all caches. You must call this before using this object if you have made changes to the HTML tree' 'Invalidate all caches. You must call this before using this object if you have made changes to the HTML tree'
self._element_map = None self._element_map = None
@ -165,6 +166,13 @@ class Select(object):
yield item yield item
seen.add(item) seen.add(item)
def has_matches(self, selector):
'Return True iff selector matches at least one item in the tree'
for elem in self(selector):
return True
return False
# }}}
def iterparsedselector(self, parsed_selector): def iterparsedselector(self, parsed_selector):
type_name = type(parsed_selector).__name__ type_name = type(parsed_selector).__name__
try: try: