From fb590bfa9bfdeb622677187552cae707f379c7b1 Mon Sep 17 00:00:00 2001 From: Jannis Leidel Date: Fri, 9 Sep 2011 19:33:40 +0000 Subject: [PATCH] =?UTF-8?q?Replaced=20`has=5Fkey()`=20calls=20with=20`in`?= =?UTF-8?q?=20to=20ease=20Python=203=20port.=20Thanks,=20Martin=20von=20L?= =?UTF-8?q?=C3=B6wis.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit git-svn-id: http://code.djangoproject.com/svn/django/trunk@16740 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/contrib/databrowse/plugins/calendars.py | 2 +- django/contrib/databrowse/plugins/fieldchoices.py | 2 +- django/contrib/sessions/backends/base.py | 2 +- django/contrib/sessions/backends/cache.py | 4 +--- django/contrib/sessions/backends/file.py | 4 +--- django/contrib/sessions/tests.py | 2 +- django/core/management/__init__.py | 2 +- django/http/__init__.py | 4 ++-- django/views/debug.py | 2 +- 9 files changed, 10 insertions(+), 14 deletions(-) diff --git a/django/contrib/databrowse/plugins/calendars.py b/django/contrib/databrowse/plugins/calendars.py index 4a9468e3960..3416f88ca7f 100644 --- a/django/contrib/databrowse/plugins/calendars.py +++ b/django/contrib/databrowse/plugins/calendars.py @@ -86,7 +86,7 @@ class CalendarPlugin(DatabrowsePlugin): 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.') diff --git a/django/contrib/databrowse/plugins/fieldchoices.py b/django/contrib/databrowse/plugins/fieldchoices.py index e0c01e95e63..b3210681e9e 100644 --- a/django/contrib/databrowse/plugins/fieldchoices.py +++ b/django/contrib/databrowse/plugins/fieldchoices.py @@ -53,7 +53,7 @@ class FieldChoicePlugin(DatabrowsePlugin): 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.') diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py index 050ed7b69eb..920b3e68cd0 100644 --- a/django/contrib/sessions/backends/base.py +++ b/django/contrib/sessions/backends/base.py @@ -113,7 +113,7 @@ class SessionBase(object): 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() diff --git a/django/contrib/sessions/backends/cache.py b/django/contrib/sessions/backends/cache.py index ab0716dcb44..22c95b23d5c 100644 --- a/django/contrib/sessions/backends/cache.py +++ b/django/contrib/sessions/backends/cache.py @@ -43,9 +43,7 @@ class SessionStore(SessionBase): 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: diff --git a/django/contrib/sessions/backends/file.py b/django/contrib/sessions/backends/file.py index 2c4e40dbc7a..0c60fff3899 100644 --- a/django/contrib/sessions/backends/file.py +++ b/django/contrib/sessions/backends/file.py @@ -131,9 +131,7 @@ class SessionStore(SessionBase): 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: diff --git a/django/contrib/sessions/tests.py b/django/contrib/sessions/tests.py index 2a4d6c8766d..95e8e901a8e 100644 --- a/django/contrib/sessions/tests.py +++ b/django/contrib/sessions/tests.py @@ -80,7 +80,7 @@ class SessionTestsMixin(object): 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) diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index 1345eaf66a4..c66a0b0e295 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -283,7 +283,7 @@ class ManagementUtility(object): 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:] diff --git a/django/http/__init__.py b/django/http/__init__.py index 3d928d9f5d5..4f1cda77850 100644 --- a/django/http/__init__.py +++ b/django/http/__init__.py @@ -23,7 +23,7 @@ except ImportError: 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 @@ class HttpResponse(object): 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 diff --git a/django/views/debug.py b/django/views/debug.py index 69cea898125..6041930d62f 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -141,7 +141,7 @@ class SafeExceptionReporterFilter(ExceptionReporterFilter): 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: