Esempio n. 1
0
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))
Esempio n. 2
0
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))
Esempio n. 3
0
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))
Esempio n. 4
0
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))
Esempio n. 5
0
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))