'Subscribe an object from sandboxed code.'

def getitem(self, obj, argument):

    try:
        return obj[argument]
    except (TypeError, LookupError):
        if isinstance(argument, string_types):
            try:
                attr = str(argument)
            except Exception:
                pass
            else:
                try:
                    value = getattr(obj, attr)
                except AttributeError:
                    pass
                else:
                    if self.is_safe_attribute(obj, argument, value):
                        return value
                    return self.unsafe_undefined(obj, argument)
    return self.undefined(obj=obj, name=argument)
