def _resolve_udn_prefer_attr3(_object, name, raise_exception=False): if hasattr(_object, name): return getattr(_object, name) try: return _object[name] except (KeyError, TypeError): if raise_exception: raise runtime.UDNResolveError(name, dir(_object)) else: return UndefinedAttribute(name, dir(_object))
def _resolve_udn_prefer_attr2(_object, name, raise_exception=False): val = getattr(_object, name, MissingAttr) if val is not MissingAttr: return val try: return _object[name] except (KeyError, TypeError): if raise_exception: raise runtime.UDNResolveError(name, dir(_object)) else: return UndefinedAttribute(name, dir(_object))