summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMagnus Hagander2019-01-03 10:01:56 +0000
committerMagnus Hagander2019-01-03 10:01:56 +0000
commit46372add400ffa5295969aa2e4e8c468d4ada937 (patch)
treed54ab386c13780b3a778294804f6af1a21d88626 /django
parent98c6b19fae0c8d59d8752e5ee6cefd76e2d56c97 (diff)
Use "in" syntax instead of has_key()
has_key() has been deprecated for a while and will be gone in Python3. The in syntax is available in both the old and the new versions.
Diffstat (limited to 'django')
-rw-r--r--django/archives/auth.py12
-rw-r--r--django/archives/mailarchives/api.py8
-rw-r--r--django/archives/mailarchives/views.py20
3 files changed, 20 insertions, 20 deletions
diff --git a/django/archives/auth.py b/django/archives/auth.py
index 6cf2c80..b3af1a5 100644
--- a/django/archives/auth.py
+++ b/django/archives/auth.py
@@ -53,7 +53,7 @@ def login(request):
from django.contrib.auth.views import login
return login(request, template_name='admin.html')
- if request.GET.has_key('next'):
+ if 'next' in request.GET:
# Put together an url-encoded dict of parameters we're getting back,
# including a small nonce at the beginning to make sure it doesn't
# encrypt the same way every time.
@@ -82,13 +82,13 @@ def logout(request):
# Receive an authentication response from the main website and try
# to log the user in.
def auth_receive(request):
- if request.GET.has_key('s') and request.GET['s'] == "logout":
+ if 's' in request.GET and request.GET['s'] == "logout":
# This was a logout request
return HttpResponseRedirect('/')
- if not request.GET.has_key('i'):
+ if 'i' not in request.GET:
return HttpResponse("Missing IV in url!", status=400)
- if not request.GET.has_key('d'):
+ if 'd' not in request.GET:
return HttpResponse("Missing data in url!", status=400)
# Set up an AES object and decrypt the data we received
@@ -170,7 +170,7 @@ We apologize for the inconvenience.
# Finally, check of we have a data package that tells us where to
# redirect the user.
- if data.has_key('d'):
+ if 'd' in data:
(ivs, datas) = data['d'][0].split('$')
decryptor = AES.new(SHA.new(settings.SECRET_KEY).digest()[:16],
AES.MODE_CBC,
@@ -180,7 +180,7 @@ We apologize for the inconvenience.
rdata = urlparse.parse_qs(s, strict_parsing=True)
except ValueError:
return HttpResponse("Invalid encrypted data received.", status=400)
- if rdata.has_key('r'):
+ if 'r' in rdata:
# Redirect address
return HttpResponseRedirect(rdata['r'][0])
# No redirect specified, see if we have it in our settings
diff --git a/django/archives/mailarchives/api.py b/django/archives/mailarchives/api.py
index 6ba1378..85eae8e 100644
--- a/django/archives/mailarchives/api.py
+++ b/django/archives/mailarchives/api.py
@@ -37,7 +37,7 @@ def latest(request, listname):
# Return the latest <n> messages on this list.
# If <n> is not specified, return 50. Max value for <n> is 100.
- if request.GET.has_key('n'):
+ if 'n' in request.GET:
try:
limit = int(request.GET['n'])
except:
@@ -51,12 +51,12 @@ def latest(request, listname):
extraparams=[]
# Return only messages that have attachments?
- if request.GET.has_key('a'):
+ if 'a' in request.GET:
if request.GET['a'] == '1':
extrawhere.append("has_attachment")
# Restrict by full text search
- if request.GET.has_key('s') and request.GET['s']:
+ if 's' in request.GET and request.GET['s']:
extrawhere.append("fti @@ plainto_tsquery('public.pg', %s)")
extraparams.append(request.GET['s'])
@@ -118,7 +118,7 @@ def thread_subscribe(request, msgid):
if not request.META['REMOTE_ADDR'] in settings.API_CLIENTS:
return HttpResponseForbidden('Invalid host')
- if not request.META.has_key('HTTP_X_APIKEY'):
+ if 'HTTP_X_APIKEY' not in request.META:
return HttpResponseForbidden('No API key')
if request.method != 'PUT':
diff --git a/django/archives/mailarchives/views.py b/django/archives/mailarchives/views.py
index 4d5304b..dc5c177 100644
--- a/django/archives/mailarchives/views.py
+++ b/django/archives/mailarchives/views.py
@@ -145,7 +145,7 @@ def get_all_groups_and_lists(request, listid=None):
if l.listid == listid:
listgroupid = l.group.groupid
- if groups.has_key(l.group.groupid):
+ if l.group.groupid in groups:
groups[l.group.groupid]['lists'].append(l)
else:
groups[l.group.groupid] = {
@@ -409,7 +409,7 @@ SELECT l.listid,0,
'subject': data[2],
'from': data[3],
}
- if retval.has_key(listname):
+ if listname in retval:
retval[listname][isnext and 'next' or 'prev'] = d
else:
retval[listname] = {
@@ -430,7 +430,7 @@ def message(request, msgid):
listmap = dict([(l.listid, l.listname) for l in lists])
threadstruct = list(_build_thread_structure(m.threadid))
newest = calendar.timegm(max(threadstruct, key=lambda x: x['date'])['date'].utctimetuple())
- if request.META.has_key('HTTP_IF_MODIFIED_SINCE') and not settings.DEBUG:
+ if 'HTTP_IF_MODIFIED_SINCE' in request.META and not settings.DEBUG:
ims = parse_http_date_safe(request.META.get("HTTP_IF_MODIFIED_SINCE"))
if ims >= newest:
return HttpResponseNotModified()
@@ -472,7 +472,7 @@ def message_flat(request, msgid):
isfirst = (msg == allmsg[0])
newest = calendar.timegm(max(allmsg, key=lambda x: x.date).date.utctimetuple())
- if request.META.has_key('HTTP_IF_MODIFIED_SINCE') and not settings.DEBUG:
+ if 'HTTP_IF_MODIFIED_SINCE' in request.META and not settings.DEBUG:
ims = parse_http_date_safe(request.META.get('HTTP_IF_MODIFIED_SINCE'))
if ims >= newest:
return HttpResponseNotModified()
@@ -608,11 +608,11 @@ def search(request):
if not request.method == 'POST':
raise Http404('I only respond to POST')
- if not request.POST.has_key('q'):
+ if 'q' not in request.POST:
raise Http404('No search query specified')
query = request.POST['q']
- if request.POST.has_key('ln'):
+ if 'ln' in request.POST:
try:
curs.execute("SELECT listid FROM lists WHERE listname=ANY(%(names)s)", {
'names': request.POST['ln'].split(','),
@@ -624,7 +624,7 @@ def search(request):
else:
lists = None
- if request.POST.has_key('d'):
+ if 'd' in request.POST:
days = int(request.POST['d'])
if days < 1 or days > 365:
firstdate = None
@@ -633,7 +633,7 @@ def search(request):
else:
firstdate = None
- if request.POST.has_key('s'):
+ if 's' in request.POST:
list_sort = request.POST['s']
if not list_sort in ('d', 'r', 'i'):
list_stort = 'r'
@@ -727,7 +727,7 @@ _dynamic_cssmap = {
@cache(hours=8)
def dynamic_css(request, css):
- if not _dynamic_cssmap.has_key(css):
+ if css not in _dynamic_cssmap:
raise Http404('CSS not found')
files = _dynamic_cssmap[css]
resp = HttpResponse(content_type='text/css')
@@ -744,7 +744,7 @@ def dynamic_css(request, css):
# If we somehow referred to a file that didn't exist, or
# one that we couldn't access.
raise Http404('CSS (sub) not found')
- if request.META.has_key('HTTP_IF_MODIFIED_SINCE'):
+ if 'HTTP_IF_MODIFIED_SINCE' in request.META:
# This code is mostly stolen from django :)
matches = re.match(r"^([^;]+)(; length=([0-9]+))?$",
request.META.get('HTTP_IF_MODIFIED_SINCE'),