Commit 28381d12 authored by Jameson Rollins's avatar Jameson Rollins

add ability to retrieve nested items from Budget and Trace objects

e.g. Budget['SubBuget.BudgetItem']
parent 89c435ad
......@@ -418,13 +418,33 @@ class Budget(Noise):
return name
def __getitem__(self, name):
"""Get a (possibly nested) sub-BudgetItem.
"""
try:
name, rest = name.split('.', 1)
except ValueError:
rest = None
try:
return self._noise_objs[name]
o = self._noise_objs[name]
except KeyError:
try:
return self._cal_objs[name]
o = self._cal_objs[name]
except KeyError:
raise KeyError("unknown noise or cal name '{}".format(name))
if rest:
return o[rest]
else:
return o
def get(self, key, default=None):
"""Get a (possibly nested) sub-BudgetItem.
"""
try:
return self[key]
except KeyError:
return default
def keys(self):
"""Iterate over budget noise names."""
......
......@@ -61,8 +61,23 @@ class BudgetTrace:
raise AttributeError
def __getitem__(self, name):
"""get budget trace by name"""
return self._bdict[name]
"""get budget trace by name
"""
try:
name, rest = name.split('.', 1)
return self._bdict[name][rest]
except ValueError:
return self._bdict[name]
def get(self, key, default=None):
"""get a (possibly nested) Trace item.
"""
try:
return self[key]
except KeyError:
return default
def items(self):
"""iterator of budget (name, trace) tuples"""
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment