'Performs resolution of a real variable (i.e. not a literal) against the
given context.
As indicated by the method\'s name, this method is an implementation
detail and shouldn\'t be called by external code. Use Variable.resolve()
instead.'

def _resolve_lookup(self, context):

    current = context
    for bit in self.lookups:
        try:
            current = current[bit]
        except (TypeError, AttributeError, KeyError):
            try:
                current = getattr(current, bit)
                if callable(current):
                    if getattr(current, 'alters_data', False):
                        current = settings.TEMPLATE_STRING_IF_INVALID
                    else:
                        try:
                            current = current()
                        except TypeError:
                            current = settings.TEMPLATE_STRING_IF_INVALID
                        except Exception as e:
                            if getattr(e, 'silent_variable_failure', False):
                                current = settings.TEMPLATE_STRING_IF_INVALID
                            else:
                                raise
            except (TypeError, AttributeError):
                try:
                    current = current[int(bit)]
                except (IndexError, ValueError, KeyError, TypeError):
                    raise VariableDoesNotExist('Failed    lookup    for    key    [%s]    in    %r', (bit, current))
            except Exception as e:
                if getattr(e, 'silent_variable_failure', False):
                    current = settings.TEMPLATE_STRING_IF_INVALID
                else:
                    raise
        except Exception as e:
            if getattr(e, 'silent_variable_failure', False):
                current = settings.TEMPLATE_STRING_IF_INVALID
            else:
                raise
    return current
