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

Method search

pattern/web/__init__.py:2934–2954  ·  view source on GitHub ↗

Returns the nested elements that match the simple CSS selector.

(self, e)

Source from the content-addressed store, hash-verified

2932 return True
2933
2934 def search(self, e):
2935 """ Returns the nested elements that match the simple CSS selector.
2936 """
2937 # Map tag to True if it is "*".
2938 tag = self.tag == "*" or self.tag
2939 # Map id into a case-insensitive **kwargs dict.
2940 i = lambda s: re.compile("^%s$" % s, re.I)
2941 a = {"id": i(self.id)} if self.id else {}
2942 a.update(map(lambda (k, v): (k, i(v)), self.attributes.iteritems()))
2943 # Match tag + id + all classes + relevant pseudo-elements.
2944 if not isinstance(e, Element):
2945 return []
2946 if len(self.classes) == 0 or len(self.classes) >= 2:
2947 e = map(Element, e._p.findAll(tag, **a))
2948 if len(self.classes) == 1:
2949 e = map(Element, e._p.findAll(tag, **dict(a, **{"class": i(list(self.classes)[0])})))
2950 if len(self.classes) >= 2:
2951 e = filter(lambda e: self.classes.issubset(set(map(str.lower, e.attr.get("class", "").split()))), e)
2952 if "first-child" in self.pseudo:
2953 e = filter(lambda e: e == self._first_child(e.parent), e)
2954 return e
2955
2956 def __repr__(self):
2957 return "Selector(%s)" % repr(self.string)

Callers

nothing calls this directly

Calls 8

_first_childMethod · 0.95
lenFunction · 0.85
iteritemsMethod · 0.80
findAllMethod · 0.80
filterFunction · 0.50
updateMethod · 0.45
splitMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected