Changes
authorBernard Blackham <dagobah@ucc.gu.uwa.edu.au>
Fri, 25 Jun 2004 10:47:43 +0000 (10:47 +0000)
committerBernard Blackham <dagobah@ucc.gu.uwa.edu.au>
Fri, 25 Jun 2004 10:47:43 +0000 (10:47 +0000)
BankAccount.py
DispenseServer.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()
index 7b06713..467f1ff 100755 (executable)
@@ -6,11 +6,15 @@ from BankAccount import BankAccount
 namespace = 'Dispense'
 bind_port = 9900
 
+server = None
+
+def hello():
+       return "hello", server.address_string()
+
 if __name__ == '__main__':
        server = SOAPServer(('0.0.0.0', 9900))
        bank = BankAccount()
-       for f in []:
+       for f in [hello]:
                server.registerFunction(f, namespace)
        print "Serving forever ..."
        server.serve_forever()
-

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