def resolve_udn_prefer_attr3(_object, name): if hasattr(_object, name): return getattr(_object, name) try: return _object[name] except (KeyError, TypeError): raise UDNResolveError(name, dir(_object))
def resolve_udn_prefer_attr2(_object, name): val = getattr(_object, name, MissingAttr) if val is not MissingAttr: return val try: return _object[name] except (KeyError, TypeError): raise UDNResolveError(name, dir(_object))
def resolve_udn_prefer_dict(_object, name): try: return _object[name] except (KeyError, TypeError): try: return getattr(_object, name) except AttributeError: raise UDNResolveError(name, dir(_object))
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 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 UDNResolveError(name, dir(_object)) else: return UndefinedAttribute(name, dir(_object))