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

Method search

pattern/web/__init__.py:2984–3008  ·  view source on GitHub ↗

Returns the nested elements that match the CSS selector chain.

(self, e)

Source from the content-addressed store, hash-verified

2982 self[-1].append(("+", Selector(s[1:])))
2983
2984 def search(self, e):
2985 """ Returns the nested elements that match the CSS selector chain.
2986 """
2987 m, root = [], e
2988 for chain in self:
2989 e = [root]
2990 for combinator, s in chain:
2991 if combinator == " ":
2992 # X Y => X is ancestor of Y
2993 e = map(s.search, e)
2994 e = list(itertools.chain(*e))
2995 if combinator == ">":
2996 # X > Y => X is parent of Y
2997 e = map(lambda e: filter(s.match, e.children), e)
2998 e = list(itertools.chain(*e))
2999 if combinator == "<":
3000 # X < Y => X is child of Y
3001 e = map(lambda e: e.parent, e)
3002 e = filter(s.match, e)
3003 if combinator == "+":
3004 # X + Y => X directly precedes Y
3005 e = map(s._first_sibling, e)
3006 e = filter(s.match, e)
3007 m.extend(e)
3008 return m
3009
3010#dom = DOM("""
3011#<html>

Callers

nothing calls this directly

Calls 2

filterFunction · 0.50
extendMethod · 0.45

Tested by

no test coverage detected