Skip to content

Instantly share code, notes, and snippets.

@neuman
Created August 31, 2015 18:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save neuman/ba234ecdb5a6a04975b8 to your computer and use it in GitHub Desktop.
Save neuman/ba234ecdb5a6a04975b8 to your computer and use it in GitHub Desktop.
Test Code
class EmbeddedMixin(object):
def get_embedded(self, hierarchy, key, value, depth=0, indexes=False):
index = 0
domain = hierarchy.pop(0)
if len(hierarchy) == 0:
for embedded in self[domain]:
if embedded[key] == value:
if indexes == True:
return [index]
else:
return embedded
index += 1
else:
for embedded in self[domain]:
output = embedded.get_embedded(hierarchy, key, value, depth=depth + 1, indexes=indexes)
if output != None:
if indexes == True:
output.insert(0, index)
return output
else:
return output
index += 1
hierarchy.insert(0, domain)
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment