From 1b55e492eff85a65c96b84a5bfa42978a291392b Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Mon, 27 Feb 2006 05:19:25 +0000 Subject: [PATCH] magic-removal: Moved django.template.ContextPopException to django.template.context module, where the code that calls it can find it. Also removed use of 'dict' as a local variable, because that's a Python builtin git-svn-id: http://code.djangoproject.com/svn/django/branches/magic-removal@2408 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/template/__init__.py | 6 +----- django/template/context.py | 26 +++++++++++++++----------- 2 files changed, 16 insertions(+), 16 deletions(-) diff --git a/django/template/__init__.py b/django/template/__init__.py index 473f618cd5..0644f758f3 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -58,7 +58,7 @@ import re from inspect import getargspec from django.utils.functional import curry from django.conf import settings -from django.template.context import Context, RequestContext +from django.template.context import Context, RequestContext, ContextPopException __all__ = ('Template', 'Context', 'RequestContext', 'compile_string') @@ -93,10 +93,6 @@ builtins = [] class TemplateSyntaxError(Exception): pass -class ContextPopException(Exception): - "pop() has been called more times than push()" - pass - class TemplateDoesNotExist(Exception): pass diff --git a/django/template/context.py b/django/template/context.py index d1c2e15736..f50fb07598 100644 --- a/django/template/context.py +++ b/django/template/context.py @@ -3,11 +3,15 @@ from django.core.exceptions import ImproperlyConfigured _standard_context_processors = None +class ContextPopException(Exception): + "pop() has been called more times than push()" + pass + class Context: "A stack container for variable context" - def __init__(self, dict=None): - dict = dict or {} - self.dicts = [dict] + def __init__(self, dict_=None): + dict_ = dict_ or {} + self.dicts = [dict_] def __repr__(self): return repr(self.dicts) @@ -30,9 +34,9 @@ class Context: def __getitem__(self, key): "Get a variable's value, starting at the current context and going upward" - for dict in self.dicts: - if dict.has_key(key): - return dict[key] + for d in self.dicts: + if d.has_key(key): + return d[key] return settings.TEMPLATE_STRING_IF_INVALID def __delitem__(self, key): @@ -40,15 +44,15 @@ class Context: del self.dicts[0][key] def has_key(self, key): - for dict in self.dicts: - if dict.has_key(key): + for d in self.dicts: + if d.has_key(key): return True return False def get(self, key, otherwise): - for dict in self.dicts: - if dict.has_key(key): - return dict[key] + for d in self.dicts: + if d.has_key(key): + return d[key] return otherwise def update(self, other_dict):