-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
59 lines (42 loc) · 1 KB
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
class Client:
import shelve
filename = "clients.shelve"
client = dict()
def __setattr__(self, key, value):
self.client[key] = value
def __getattr__(self, key):
if key in self.client:
return self.client[key]
else:
return ""
def getValue(self, key):
if key in self.client:
return self.client[key]
else:
return ""
def setValue(self, key, value):
self.client[key] = value
def getNewClientId(self):
d = self.shelve.open(self.filename)
if (d.has_key("seq")):
id = d["seq"] + 1
else:
id = 1
d.close()
return id
def getClientById(self, id):
d = self.shelve.open(self.filename)
id = str(id)
if (d.has_key(id)):
client = d[id]
for k, v in client.items():
self.client[k] = v
d.close()
return self.client
def save(self):
id = self.getNewClientId()
self.client["id"] = id
d = self.shelve.open(self.filename)
d["seq"] = id
d[str(id)] = self.client
d.close()