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
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()
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()
-