diff options
| author | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-04-26 13:30:48 +0000 |
|---|---|---|
| committer | Malcolm Tredinnick <malcolm.tredinnick@gmail.com> | 2007-04-26 13:30:48 +0000 |
| commit | 439cb4047fb583d08149f28e2ce66a8edfe0efa7 (patch) | |
| tree | 47ef30e70bf1d757f08b133d3aa47704db13c714 /django/template | |
| parent | 6c02565e4fb92c4cc3bfb45bcc89eb9aa299efdc (diff) | |
Fixed #4040 -- Changed uses of has_key() to "in". Slight performance
improvement and forward-compatible with future Python releases. Patch from Gary
Wilson.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@5091 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/template')
| -rw-r--r-- | django/template/__init__.py | 2 | ||||
| -rw-r--r-- | django/template/context.py | 6 | ||||
| -rw-r--r-- | django/template/defaulttags.py | 8 |
3 files changed, 8 insertions, 8 deletions
diff --git a/django/template/__init__.py b/django/template/__init__.py index a32b3f5a0b..a592765db6 100644 --- a/django/template/__init__.py +++ b/django/template/__init__.py @@ -338,7 +338,7 @@ class Parser(object): return FilterExpression(token, self) def find_filter(self, filter_name): - if self.filters.has_key(filter_name): + if filter_name in self.filters: return self.filters[filter_name] else: raise TemplateSyntaxError, "Invalid filter: '%s'" % filter_name diff --git a/django/template/context.py b/django/template/context.py index 25397b0e1a..59650b05fe 100644 --- a/django/template/context.py +++ b/django/template/context.py @@ -35,7 +35,7 @@ class Context(object): def __getitem__(self, key): "Get a variable's value, starting at the current context and going upward" for d in self.dicts: - if d.has_key(key): + if key in d: return d[key] raise KeyError(key) @@ -45,7 +45,7 @@ class Context(object): def has_key(self, key): for d in self.dicts: - if d.has_key(key): + if key in d: return True return False @@ -54,7 +54,7 @@ class Context(object): def get(self, key, otherwise=None): for d in self.dicts: - if d.has_key(key): + if key in d: return d[key] return otherwise diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py index 2deae6d403..1ebb01442e 100644 --- a/django/template/defaulttags.py +++ b/django/template/defaulttags.py @@ -87,7 +87,7 @@ class ForNode(Node): def render(self, context): nodelist = NodeList() - if context.has_key('forloop'): + if 'forloop' in context: parentloop = context['forloop'] else: parentloop = {} @@ -133,7 +133,7 @@ class IfChangedNode(Node): self._varlist = varlist def render(self, context): - if context.has_key('forloop') and context['forloop']['first']: + if 'forloop' in context and context['forloop']['first']: self._last_seen = None try: if self._varlist: @@ -432,7 +432,7 @@ def cycle(parser, token): name = args[1] if not hasattr(parser, '_namedCycleNodes'): raise TemplateSyntaxError("No named cycles in template: '%s' is not defined" % name) - if not parser._namedCycleNodes.has_key(name): + if name not in parser._namedCycleNodes: raise TemplateSyntaxError("Named cycle '%s' does not exist" % name) return parser._namedCycleNodes[name] @@ -911,7 +911,7 @@ def templatetag(parser, token): if len(bits) != 2: raise TemplateSyntaxError, "'templatetag' statement takes one argument" tag = bits[1] - if not TemplateTagNode.mapping.has_key(tag): + if tag not in TemplateTagNode.mapping: raise TemplateSyntaxError, "Invalid templatetag argument: '%s'. Must be one of: %s" % \ (tag, TemplateTagNode.mapping.keys()) return TemplateTagNode(tag) |
