6
# The client searches the two banks and performs a set of operations.
7
# (the banks are searched simply by listing the :banks namespace!)
11
import Pyro.naming, Pyro.core
13
from banks import BankError
15
group = ':banks' # the default namespace group
17
# initialize the client and set the default namespace group
18
Pyro.core.initClient()
19
Pyro.config.PYRO_NS_DEFAULTGROUP=group
22
locator = Pyro.naming.NameServerLocator()
23
print 'Searching Naming Service...',
26
print 'Naming Service found at',ns.URI.address,'('+(Pyro.protocol.getHostname(ns.URI.address) or '??')+') port',ns.URI.port
29
# This is done by simply looking in the :banks namespace, to see what
30
# banks have registered. The filter is for removing any groups that could
31
# be in the namespace (the type of real names is 1).
32
banknames = filter(lambda x: x[1]==1, ns.list(group))
33
banknames = map(lambda (x,y): x, banknames) # keep only the object name
35
raise RuntimeError('There are no banks to do business with!')
37
banks={} # banks (proxies)
41
for name in banknames:
42
print 'Found a bank: ',name
45
except Pyro.core.PyroError,x:
46
print 'Bank can\'t be found:',x
49
# create a proxy for the bank object
50
banks[name] = Pyro.core.getAttrProxyForURI(URI)
54
banknames=banks.keys()
58
b = input("Select a bank: ")
59
return banks[banknames[b-1]]
62
print "\nCreate Account."
64
name = raw_input("Enter name: ")
65
a = bank.createAccount(name)
66
amount = input("Initial deposit: ")
68
print "Balance:", a.balance
72
print "\nRemove Account."
74
name = raw_input("Enter name: ")
75
bank.deleteAccount(name)
78
print "\nView Balance."
80
name = raw_input("Enter name: ")
81
ac = bank.findAccount(name)
87
name = raw_input("Enter name: ")
88
ac = bank.findAccount(name)
89
amount = input("Amount: ")
91
print "New balance:", ac.balance
96
name = raw_input("Enter name: ")
97
ac = bank.findAccount(name)
98
amount = input("Amount: ")
100
print "New balance:", ac.balance
103
print "\nList all accounts."
104
for (bankname,bank) in banks.items():
106
accs = bank.allAccounts()
108
print " No accounts."
110
print " ",a.name, a.balance
115
print "\n---- menu ----"
116
print "1: create account"
117
print "2: remove account"
118
print "3: view balance"
119
print "4: list all accounts"
120
print "5: deposit money"
121
print "6: withdraw money"
125
choice = input("Choice: ")
126
if choice==0: going=0
127
elif choice==1: createAccount()
128
elif choice==2: removeAccount()
129
elif choice==3: viewBalance()
130
elif choice==4: listAll()
131
elif choice==5: deposit()
132
elif choice==6: withdraw()
133
except SyntaxError,x:
134
print "Input problem:",x
137
except StandardError,x:
138
print 'Try again (input incorrect?)'