MCPcopy Index your code
hub / github.com/STIXProject/python-stix / iterwalk

Function iterwalk

stix/utils/walk.py:40–67  ·  view source on GitHub ↗

Returns an generator which 'walks` the input `obj` model. Each iteration yields a stix.Entity or cybox.Entity instance. This is performed depth-first.

(obj)

Source from the content-addressed store, hash-verified

38
39
40def iterwalk(obj):
41 """Returns an generator which 'walks` the input `obj` model. Each
42 iteration yields a stix.Entity or cybox.Entity instance.
43
44 This is performed depth-first.
45
46 """
47 def yield_and_walk(item):
48 if not is_entity(item):
49 return
50
51 yield item
52 for descendant in iterwalk(item):
53 yield descendant
54
55 for varname, varobj in _iter_vars(obj):
56 if _is_skippable(obj, varname, varobj):
57 continue
58
59 if is_sequence(varobj) and not is_entitylist(varobj):
60 for item in varobj:
61 for descendant in yield_and_walk(item):
62 yield descendant
63
64 continue
65
66 for descendant in yield_and_walk(varobj):
67 yield descendant
68
69
70def iterpath(obj, path=None):

Callers 1

yield_and_walkFunction · 0.85

Calls 5

_iter_varsFunction · 0.85
_is_skippableFunction · 0.85
is_sequenceFunction · 0.85
is_entitylistFunction · 0.85
yield_and_walkFunction · 0.85

Tested by

no test coverage detected