From edc81ca1e163012cf3e66e28a21af20ea342ea2c Mon Sep 17 00:00:00 2001 From: MasterofJOKers Date: Sun, 11 Mar 2012 02:11:11 +0100 Subject: [PATCH] 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." --- k4ever/api2/handlers.py | 16 ++++++++-------- k4ever/main/views.py | 2 +- k4ever/transaction/forms.py | 2 +- k4ever/transaction/views.py | 2 +- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/k4ever/api2/handlers.py b/k4ever/api2/handlers.py index 49dc7d1..de5ac4b 100644 --- a/k4ever/api2/handlers.py +++ b/k4ever/api2/handlers.py @@ -59,7 +59,7 @@ class BuyableItemHandler(BaseHandler): except Buyable.DoesNotExist: return rc.NOT_FOUND else: - if request.GET.has_key('type'): + if 'type' in request.GET: obj = Buyable.objects.filter(buyableType__name=request.GET['type']) return obj try: @@ -129,12 +129,12 @@ class BuyableItemHandler(BaseHandler): if not request.content_type: 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).") - if not request.data.has_key("items"): + if not "items" in request.data: request.data['items'] = [] - if not request.data.has_key("deposits"): + if not "deposits" in request.data: request.data['deposits'] = [] itemList = [] @@ -142,7 +142,7 @@ class BuyableItemHandler(BaseHandler): if not isinstance(request.data['items'], Iterable): raise TypeError() itemList += request.data['items'] - if request.data.has_key('items'): + if 'items' in request.data: if not isinstance(request.data['deposits'], Iterable): raise TypeError() itemList += request.data['deposits'] @@ -157,7 +157,7 @@ class BuyableItemHandler(BaseHandler): ids = {} for item in itemList: - if not ids.has_key(item): + if not item in ids: try: ids[item] = Buyable.objects.get(id=item) except Buyable.DoesNotExist: @@ -397,7 +397,7 @@ class AuthBlobHandler(BaseHandler): """ if not request.plugin.pluginCanWriteAuthblob: 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") request.pluginperms.authblob = request.data['authblob'] request.pluginperms.authblob.save() @@ -424,7 +424,7 @@ class AuthUserHandler(BaseHandler): 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") - if not request.GET.has_key('authblob') or request.GET['authblob'] == '': + if request.GET.get('authblob', '') == '': return getError(rc.BAD_REQUEST, "Authblob was empty.") user = getUserFromAuthblob(request.GET['authblob'], request.plugin) diff --git a/k4ever/main/views.py b/k4ever/main/views.py index 67a20fa..3982303 100644 --- a/k4ever/main/views.py +++ b/k4ever/main/views.py @@ -138,7 +138,7 @@ def pluginAuthblob(request, pluginId): return render_to_response("settings/settings.html", d, RequestContext(request)) # 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['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)) diff --git a/k4ever/transaction/forms.py b/k4ever/transaction/forms.py index 087e451..4bb3a96 100644 --- a/k4ever/transaction/forms.py +++ b/k4ever/transaction/forms.py @@ -25,7 +25,7 @@ class TransactionForm(forms.ModelForm): def clean(self): # needed to enforce TransactionTypes needsCheck "default value" 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 return cleaned_data diff --git a/k4ever/transaction/views.py b/k4ever/transaction/views.py index b233753..544d3c5 100644 --- a/k4ever/transaction/views.py +++ b/k4ever/transaction/views.py @@ -27,7 +27,7 @@ def overview(request): vform = VirtualTransactionForm() state = None 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": transaction = Transaction(user=request.user) form = TransactionForm(request.POST, instance=transaction)