Skip to content

Commit

Permalink
magic-removal: Moved django.template.ContextPopException to django.te…
Browse files Browse the repository at this point in the history
…mplate.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
  • Loading branch information
adrianholovaty committed Feb 27, 2006
1 parent e6962ff commit 1b55e49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 16 deletions.
6 changes: 1 addition & 5 deletions django/template/__init__.py
Expand Up @@ -58,7 +58,7 @@
from inspect import getargspec from inspect import getargspec
from django.utils.functional import curry from django.utils.functional import curry
from django.conf import settings 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') __all__ = ('Template', 'Context', 'RequestContext', 'compile_string')


Expand Down Expand Up @@ -93,10 +93,6 @@
class TemplateSyntaxError(Exception): class TemplateSyntaxError(Exception):
pass pass


class ContextPopException(Exception):
"pop() has been called more times than push()"
pass

class TemplateDoesNotExist(Exception): class TemplateDoesNotExist(Exception):
pass pass


Expand Down
26 changes: 15 additions & 11 deletions django/template/context.py
Expand Up @@ -3,11 +3,15 @@


_standard_context_processors = None _standard_context_processors = None


class ContextPopException(Exception):
"pop() has been called more times than push()"
pass

class Context: class Context:
"A stack container for variable context" "A stack container for variable context"
def __init__(self, dict=None): def __init__(self, dict_=None):
dict = dict or {} dict_ = dict_ or {}
self.dicts = [dict] self.dicts = [dict_]


def __repr__(self): def __repr__(self):
return repr(self.dicts) return repr(self.dicts)
Expand All @@ -30,25 +34,25 @@ def __setitem__(self, key, value):


def __getitem__(self, key): def __getitem__(self, key):
"Get a variable's value, starting at the current context and going upward" "Get a variable's value, starting at the current context and going upward"
for dict in self.dicts: for d in self.dicts:
if dict.has_key(key): if d.has_key(key):
return dict[key] return d[key]
return settings.TEMPLATE_STRING_IF_INVALID return settings.TEMPLATE_STRING_IF_INVALID


def __delitem__(self, key): def __delitem__(self, key):
"Delete a variable from the current context" "Delete a variable from the current context"
del self.dicts[0][key] del self.dicts[0][key]


def has_key(self, key): def has_key(self, key):
for dict in self.dicts: for d in self.dicts:
if dict.has_key(key): if d.has_key(key):
return True return True
return False return False


def get(self, key, otherwise): def get(self, key, otherwise):
for dict in self.dicts: for d in self.dicts:
if dict.has_key(key): if d.has_key(key):
return dict[key] return d[key]
return otherwise return otherwise


def update(self, other_dict): def update(self, other_dict):
Expand Down

0 comments on commit 1b55e49

Please sign in to comment.