MCPcopy Create free account
hub / github.com/cdgriffith/Box / walk

Function walk

box/comments.py:164–188  ·  view source on GitHub ↗
(node, path)

Source from the content-addressed store, hash-verified

162 seen.update(id(token) for token in root_comment[1])
163
164 def walk(node, path):
165 if isinstance(node, CommentedMap):
166 items = node.items()
167 is_map = True
168 elif isinstance(node, CommentedSeq):
169 items = enumerate(node)
170 is_map = False
171 else:
172 return
173 node_comment = getattr(node.ca, "comment", None)
174 if path and node_comment and len(node_comment) > 1:
175 take_lines(node_comment[1])
176 for key, value in items:
177 item_path = path + (_ruamel_to_builtin(key),)
178 if pending:
179 entry(item_path)["before"].extend(pending)
180 pending.clear()
181 tokens = node.ca.items.get(key)
182 if tokens:
183 if is_map:
184 handle(tokens[2], item_path)
185 take_lines(tokens[3]) # comment lines between "key:" and its nested value
186 else:
187 handle(tokens[0], item_path)
188 walk(value, item_path)
189
190 walk(root, ())
191 if pending:

Callers 1

extract_commentsFunction · 0.85

Calls 8

_ruamel_to_builtinFunction · 0.90
take_linesFunction · 0.85
entryFunction · 0.85
handleFunction · 0.85
extendMethod · 0.80
getMethod · 0.80
itemsMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected