Removed getitem_from_path---now uses eval() [eg, __getitem__] for such functions
This commit is contained in:
parent
7daf720ee7
commit
7224bda047
@ -447,27 +447,29 @@ class Struct(object):
|
|||||||
"""
|
"""
|
||||||
Given a path to a struct part, return the part, or None.
|
Given a path to a struct part, return the part, or None.
|
||||||
|
|
||||||
>>> Struct(struct)["primary_name.surname_list.0.surname"]
|
>>> Struct(struct)["primary_name"]
|
||||||
"""
|
"""
|
||||||
# For where eval:
|
# For where eval:
|
||||||
if isinstance(path, int):
|
return self.getitem(path)
|
||||||
return Struct(self.struct[path], self.db)
|
|
||||||
# Work way down to last part:
|
|
||||||
return self.getitem_from_path(parse(path))
|
|
||||||
|
|
||||||
def getitem_from_path(self, path):
|
# if isinstance(path, int):
|
||||||
"""
|
# return self.get_ref_struct(self.struct[path])
|
||||||
Given a path that is already parsed, return item.
|
# # Work way down to last part:
|
||||||
"""
|
# return self.getitem_from_path(parse(path))
|
||||||
struct = self.struct
|
|
||||||
for p in range(len(path)):
|
# def getitem_from_path(self, path):
|
||||||
part = path[p]
|
# """
|
||||||
struct = self.getitem(part, struct)
|
# Given a path that is already parsed, return item.
|
||||||
if isinstance(struct, Struct):
|
# """
|
||||||
return struct.getitem_from_path(path[p+1:])
|
# struct = self.struct
|
||||||
if struct is None:
|
# for p in range(len(path)):
|
||||||
return None
|
# part = path[p]
|
||||||
return struct
|
# struct = self.getitem(part, struct)
|
||||||
|
# if isinstance(struct, Struct):
|
||||||
|
# return struct.getitem_from_path(path[p+1:])
|
||||||
|
# if struct is None:
|
||||||
|
# return None
|
||||||
|
# return struct
|
||||||
|
|
||||||
def get_ref_struct(self, item):
|
def get_ref_struct(self, item):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user