Skip to content

Commit

Permalink
Added docstrings to utils.walk
Browse files Browse the repository at this point in the history
  • Loading branch information
Bryan Worrell committed Feb 28, 2015
1 parent 7386b46 commit 329f111
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions stix/utils/walk.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ def _iter_vars(obj):


def iterwalk(obj):
"""Returns an generator which 'walks` the input `obj` model. Each
iteration yields a stix.Entity or cybox.Entity instance.
This is performed depth-first.
"""
def yield_and_walk(item):
if not is_entity(item):
return
Expand All @@ -52,6 +58,17 @@ def yield_and_walk(item):


def iterpath(obj, path=None):
"""Returns a generator which `walks` the input `obj` model. Each
iteration yields a triple containing a list of ancestor nodes, the name
of the field, and the field value.
Example:
An Indicator Title with a value of "Test" could be yielded as follows:
([STIXPackage, Indicators, Indicator], "title", "Test")
This is performed depth-first.
"""
def yield_and_descend(name, item):
yield (path, attr_name(name), item)

Expand Down

0 comments on commit 329f111

Please sign in to comment.