1
0
mirror of https://github.com/django/django.git synced 2025-10-31 09:41:08 +00:00

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
This commit is contained in:
Malcolm Tredinnick
2007-04-26 13:30:48 +00:00
parent 6c02565e4f
commit 439cb4047f
37 changed files with 112 additions and 92 deletions

View File

@@ -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

View File

@@ -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

View File

@@ -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)