MCPcopy Index your code
hub / github.com/clips/pattern / match

Method match

pattern/web/__init__.py:2916–2932  ·  view source on GitHub ↗

Returns True if the given element matches the simple CSS selector.

(self, e)

Source from the content-addressed store, hash-verified

2914 return e
2915
2916 def match(self, e):
2917 """ Returns True if the given element matches the simple CSS selector.
2918 """
2919 if not isinstance(e, Element):
2920 return False
2921 if self.tag not in (e.tag, "*"):
2922 return False
2923 if self.id not in (e.id.lower(), "", None):
2924 return False
2925 if self.classes.issubset(set(map(str.lower, e.attr.get("class", "").split()))) is False:
2926 return False
2927 if "first-child" in self.pseudo and self._first_child(e.parent) != e:
2928 return False
2929 for k, v in self.attributes:
2930 if k not in e.attrs or v not in (e.attrs[k].lower(), True):
2931 return False
2932 return True
2933
2934 def search(self, e):
2935 """ Returns the nested elements that match the simple CSS selector.

Callers 15

searchMethod · 0.45
searchMethod · 0.45
_parse_articleMethod · 0.45
load_fallbackMethod · 0.45
_parse_literal_hexMethod · 0.45
_parse_string_1Method · 0.45
searchMethod · 0.45
sanitize_styleMethod · 0.45
_parse_date_onblogFunction · 0.45
_parse_date_nateFunction · 0.45
_parse_date_greekFunction · 0.45
_parse_date_hungarianFunction · 0.45

Calls 3

_first_childMethod · 0.95
splitMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected