Callers don't expect this, and there will be unfortunate behaviour. For
example, `T.timespec' explodes if handed a literal integer rather than a
string.
a FILTER function is given then apply it to the information from the
database before returning it.
"""
a FILTER function is given then apply it to the information from the
database before returning it.
"""
- attr = me.__dict__.get(key, default)
- if attr is _magic:
- raise T.TripeJobError('malformed-peer', me.name, 'missing-key', key)
- elif filter is not None:
- attr = filter(attr)
- return attr
+ try:
+ attr = me.__dict__[key]
+ except KeyError:
+ if default is _magic:
+ raise T.TripeJobError('malformed-peer', me.name, 'missing-key', key)
+ return default
+ else:
+ if filter is not None: attr = filter(attr)
+ return attr