'Subscribe an object from sandboxed code and prefer the
attribute.  The attribute passed *must* be a bytestring.'

def getattr(self, obj, attribute):

    try:
        value = getattr(obj, attribute)
    except AttributeError:
        try:
            return obj[attribute]
        except (TypeError, LookupError):
            pass
    else:
        if self.is_safe_attribute(obj, attribute, value):
            return value
        return self.unsafe_undefined(obj, attribute)
    return self.undefined(obj=obj, name=attribute)
