Change some deprecated code

Python docs say:
"Test for the presence of key in the dictionary. has_key() is
deprecated in favor of key in d."
This commit is contained in:
MasterofJOKers 2012-03-11 02:11:11 +01:00
parent a7ec8bc5fa
commit edc81ca1e1
4 changed files with 11 additions and 11 deletions

View File

@ -59,7 +59,7 @@ class BuyableItemHandler(BaseHandler):
except Buyable.DoesNotExist: except Buyable.DoesNotExist:
return rc.NOT_FOUND return rc.NOT_FOUND
else: else:
if request.GET.has_key('type'): if 'type' in request.GET:
obj = Buyable.objects.filter(buyableType__name=request.GET['type']) obj = Buyable.objects.filter(buyableType__name=request.GET['type'])
return obj return obj
try: try:
@ -129,12 +129,12 @@ class BuyableItemHandler(BaseHandler):
if not request.content_type: if not request.content_type:
return getError(rc.BAD_REQUEST, "The content-type of the request must not be empty/urlencoded") return getError(rc.BAD_REQUEST, "The content-type of the request must not be empty/urlencoded")
if not request.data.has_key("items") and not request.data.has_key("deposits"): if not "items" in request.data and not "deposits" in request.data:
return getError(rc.BAD_REQUEST, "You need to specify either items or deposits (or both).") return getError(rc.BAD_REQUEST, "You need to specify either items or deposits (or both).")
if not request.data.has_key("items"): if not "items" in request.data:
request.data['items'] = [] request.data['items'] = []
if not request.data.has_key("deposits"): if not "deposits" in request.data:
request.data['deposits'] = [] request.data['deposits'] = []
itemList = [] itemList = []
@ -142,7 +142,7 @@ class BuyableItemHandler(BaseHandler):
if not isinstance(request.data['items'], Iterable): if not isinstance(request.data['items'], Iterable):
raise TypeError() raise TypeError()
itemList += request.data['items'] itemList += request.data['items']
if request.data.has_key('items'): if 'items' in request.data:
if not isinstance(request.data['deposits'], Iterable): if not isinstance(request.data['deposits'], Iterable):
raise TypeError() raise TypeError()
itemList += request.data['deposits'] itemList += request.data['deposits']
@ -157,7 +157,7 @@ class BuyableItemHandler(BaseHandler):
ids = {} ids = {}
for item in itemList: for item in itemList:
if not ids.has_key(item): if not item in ids:
try: try:
ids[item] = Buyable.objects.get(id=item) ids[item] = Buyable.objects.get(id=item)
except Buyable.DoesNotExist: except Buyable.DoesNotExist:
@ -397,7 +397,7 @@ class AuthBlobHandler(BaseHandler):
""" """
if not request.plugin.pluginCanWriteAuthblob: if not request.plugin.pluginCanWriteAuthblob:
return getError(rc.FORBIDDEN, "This plugin is not allowed to write the user's authblob") return getError(rc.FORBIDDEN, "This plugin is not allowed to write the user's authblob")
if not request.data.has_key('authblob'): if not 'authblob' in request.data:
return getError(rc.BAD_REQUEST, "To change the user's auth blob you actually need to provide one") return getError(rc.BAD_REQUEST, "To change the user's auth blob you actually need to provide one")
request.pluginperms.authblob = request.data['authblob'] request.pluginperms.authblob = request.data['authblob']
request.pluginperms.authblob.save() request.pluginperms.authblob.save()
@ -424,7 +424,7 @@ class AuthUserHandler(BaseHandler):
if not request.plugin.uniqueAuthblob: if not request.plugin.uniqueAuthblob:
return getError(rc.BAD_REQUEST, "This plugin does not support unique auth blobs, therefore we can't identify a user uniquely by their authblob") return getError(rc.BAD_REQUEST, "This plugin does not support unique auth blobs, therefore we can't identify a user uniquely by their authblob")
if not request.GET.has_key('authblob') or request.GET['authblob'] == '': if request.GET.get('authblob', '') == '':
return getError(rc.BAD_REQUEST, "Authblob was empty.") return getError(rc.BAD_REQUEST, "Authblob was empty.")
user = getUserFromAuthblob(request.GET['authblob'], request.plugin) user = getUserFromAuthblob(request.GET['authblob'], request.plugin)

View File

@ -138,7 +138,7 @@ def pluginAuthblob(request, pluginId):
return render_to_response("settings/settings.html", d, RequestContext(request)) return render_to_response("settings/settings.html", d, RequestContext(request))
# has the user write access to the authblob? # has the user write access to the authblob?
if not p.plugin.userCanWriteAuthblob or not request.POST.has_key("authblob"): if not p.plugin.userCanWriteAuthblob or not "authblob" in request.POST:
d = getPluginDict(request) d = getPluginDict(request)
d['pluginerror'] = "Der Authblob darf für dieses Plugin nicht vom User verändert werden (oder der Authblob war kaputt)" d['pluginerror'] = "Der Authblob darf für dieses Plugin nicht vom User verändert werden (oder der Authblob war kaputt)"
return render_to_response("settings/settings.html", d, RequestContext(request)) return render_to_response("settings/settings.html", d, RequestContext(request))

View File

@ -25,7 +25,7 @@ class TransactionForm(forms.ModelForm):
def clean(self): def clean(self):
# needed to enforce TransactionTypes needsCheck "default value" # needed to enforce TransactionTypes needsCheck "default value"
cleaned_data = super(TransactionForm, self).clean() cleaned_data = super(TransactionForm, self).clean()
if cleaned_data.has_key("transactionType"): if "transactionType" in cleaned_data:
self.instance.checked = not cleaned_data['transactionType'].needsCheck self.instance.checked = not cleaned_data['transactionType'].needsCheck
return cleaned_data return cleaned_data

View File

@ -27,7 +27,7 @@ def overview(request):
vform = VirtualTransactionForm() vform = VirtualTransactionForm()
state = None state = None
payway = "payin" payway = "payin"
if request.method == 'POST' and request.POST.has_key('_formtype'): if request.method == 'POST' and '_formtype' in request.POST:
if request.POST['_formtype'] == "normal": if request.POST['_formtype'] == "normal":
transaction = Transaction(user=request.user) transaction = Transaction(user=request.user)
form = TransactionForm(request.POST, instance=transaction) form = TransactionForm(request.POST, instance=transaction)