put in a generic exception handler
[zanchey/dispense2.git] / BankAccount.py
index ae33dd9..6565b65 100644 (file)
@@ -19,7 +19,7 @@ class BankAccount:
        def sanity_check_user(self, user):
                wanted_fields = ['balance']
                for f in user:
-                       if wanted_fields.has_key(f):
+                       if f in wanted_fields:
                                if f == 'balance':
                                        if not isinstance(user['balance'], tuple):
                                                return False
@@ -54,11 +54,13 @@ class BankAccount:
 
        def get_balance(self, username):
                if self.bank.has_key(username):
-                       return self.bank['username']['balance']
+                       return self.bank[username]['balance']
                return (0,0)
 
        def add_amount(self, username, amount):
-               ensure_user_exists(username)
-               self.bank['username']['balance'][0] += amount[0]
-               self.bank['username']['balance'][1] += amount[1]
+               self.ensure_user_exists(username)
+               (cur_cents, cur_bytes) = self.bank[username]['balance']
+               (add_cents, add_bytes) = amount
+               self.bank[username]['balance'] = (cur_cents+add_cents,
+                       cur_bytes+add_bytes)
                self.save()

UCC git Repository :: git.ucc.asn.au