Permalink
Browse files

Replaced `has_key()` calls with `in` to ease Python 3 port. Thanks, M…

…artin von Löwis.

git-svn-id: http://code.djangoproject.com/svn/django/trunk@16740 bcc190cf-cafb-0310-a4f2-bffc1f526a37
  • Loading branch information...
1 parent 7deb25b commit fb590bfa9bfdeb622677187552cae707f379c7b1 @jezdez jezdez committed Sep 9, 2011
@@ -86,7 +86,7 @@ def model_view(self, request, model_databrowse, url):
if url is None:
return self.homepage_view(request)
url_bits = url.split('/')
- if self.fields.has_key(url_bits[0]):
+ if url_bits[0] in self.fields:
return self.calendar_view(request, self.fields[url_bits[0]], *url_bits[1:])
raise http.Http404('The requested page does not exist.')
@@ -53,7 +53,7 @@ def model_view(self, request, model_databrowse, url):
if url is None:
return self.homepage_view(request)
url_bits = url.split('/', 1)
- if self.fields.has_key(url_bits[0]):
+ if url_bits[0] in self.fields:
return self.field_view(request, self.fields[url_bits[0]], *url_bits[1:])
raise http.Http404('The requested page does not exist.')
@@ -113,7 +113,7 @@ def update(self, dict_):
self.modified = True
def has_key(self, key):
- return self._session.has_key(key)
+ return key in self._session
def values(self):
return self._session.values()
@@ -43,9 +43,7 @@ def save(self, must_create=False):
raise CreateError
def exists(self, session_key):
- if self._cache.has_key(session_key):
- return True
- return False
+ return session_key in self._cache
def delete(self, session_key=None):
if session_key is None:
@@ -131,9 +131,7 @@ def save(self, must_create=False):
pass
def exists(self, session_key):
- if os.path.exists(self._key_to_file(session_key)):
- return True
- return False
+ return os.path.exists(self._key_to_file(session_key))
def delete(self, session_key=None):
if session_key is None:
@@ -80,7 +80,7 @@ def test_has_key(self):
self.session['some key'] = 1
self.session.modified = False
self.session.accessed = False
- self.assertTrue(self.session.has_key('some key'))
+ self.assertTrue('some key' in self.session)
self.assertTrue(self.session.accessed)
self.assertFalse(self.session.modified)
@@ -283,7 +283,7 @@ def autocomplete(self):
and formatted as potential completion suggestions.
"""
# Don't complete if user hasn't sourced bash_completion file.
- if not os.environ.has_key('DJANGO_AUTO_COMPLETE'):
+ if 'DJANGO_AUTO_COMPLETE' not in os.environ:
return
cwords = os.environ['COMP_WORDS'].split()[1:]
@@ -23,7 +23,7 @@
import Cookie
# httponly support exists in Python 2.6's Cookie library,
# but not in Python 2.5.
-_morsel_supports_httponly = Cookie.Morsel._reserved.has_key('httponly')
+_morsel_supports_httponly = 'httponly' in Cookie.Morsel._reserved
# Some versions of Python 2.7 and later won't need this encoding bug fix:
_cookie_encodes_correctly = Cookie.SimpleCookie().value_encode(';') == (';', '"\\073"')
# See ticket #13007, http://bugs.python.org/issue2193 and http://trac.edgewall.org/ticket/2256
@@ -591,7 +591,7 @@ def __getitem__(self, header):
def has_header(self, header):
"""Case-insensitive check for a header."""
- return self._headers.has_key(header.lower())
+ return header.lower() in self._headers
__contains__ = has_header
@@ -141,7 +141,7 @@ def get_post_parameters(self, request):
else:
# Cleanse only the specified parameters.
for param in sensitive_post_parameters:
- if cleansed.has_key(param):
+ if param in cleansed:
cleansed[param] = CLEANSED_SUBSTITUTE
return cleansed
else:

0 comments on commit fb590bf

Please sign in to comment.