diff options
author | haturatu <taro@eyes4you.org> | 2024-11-07 23:48:25 +0900 |
---|---|---|
committer | haturatu <taro@eyes4you.org> | 2024-11-07 23:48:25 +0900 |
commit | fcb7fe54373a771039842607d93537166752387f (patch) | |
tree | eb9ad5bc6c4b2202e16b0645d6c3640ff513baf5 /bs4/element.py | |
parent | 9786a62726de5a8caba10021c4d4a58c8a3e9e3f (diff) |
dont use or opemaster
Diffstat (limited to 'bs4/element.py')
-rw-r--r-- | bs4/element.py | 61 |
1 files changed, 34 insertions, 27 deletions
diff --git a/bs4/element.py b/bs4/element.py index 0aefe73..f68c4c9 100644 --- a/bs4/element.py +++ b/bs4/element.py @@ -2267,35 +2267,42 @@ class SoupStrainer(object): isinstance(self.name, Callable) and not isinstance(markup_name, Tag)) - if ((not self.name) - or call_function_with_tag_data - or (markup and self._matches(markup, self.name)) - or (not markup and self._matches(markup_name, self.name))): - if call_function_with_tag_data: - match = self.name(markup_name, markup_attrs) + if not self.name: + match = True + elif call_function_with_tag_data: + match = self.name(markup_name, markup_attrs) + elif markup: + if self._matches(markup, self.name): + match = True else: + match = False + elif not markup: + if self._matches(markup_name, self.name): match = True - markup_attr_map = None - for attr, match_against in list(self.attrs.items()): - if not markup_attr_map: - if hasattr(markup_attrs, 'get'): - markup_attr_map = markup_attrs - else: - markup_attr_map = {} - for k, v in markup_attrs: - markup_attr_map[k] = v - attr_value = markup_attr_map.get(attr) - if not self._matches(attr_value, match_against): - match = False - break - if match: - if markup: - found = markup - else: - found = markup_name - if found and self.string and not self._matches(found.string, self.string): - found = None - return found + else: + match = False + + if not call_function_with_tag_data and match: + match = True + markup_attr_map = None + for attr, match_against in list(self.attrs.items()): + if not markup_attr_map: + if hasattr(markup_attrs, 'get'): + markup_attr_map = markup_attrs + else: + markup_attr_map = {} + for k, v in markup_attrs: + markup_attr_map[k] = v + attr_value = markup_attr_map.get(attr) + if not self._matches(attr_value, match_against): + match = False + break + + if match: + if markup: + found = markup + else: + found = markup_name # For BS3 compatibility. searchTag = search_tag |