forked from pahaz/homework-simple-python-web-application
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMyModel.py
More file actions
32 lines (24 loc) · 762 Bytes
/
Copy pathMyModel.py
File metadata and controls
32 lines (24 loc) · 762 Bytes
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
__author__ = 'Alexey'
import shelve
import random
class AddressModel(object):
def __init__(self, db_file):
self._db=shelve.open(db_file)
def exist_id(self, addrid):
return addrid in self._db
def exist_address(self, address):
return address in self._db.values()
def new(self, address):
addrid = str(random.randint(1000,9999))
while addrid in self._db:
addrid = str(random.randint(1000,9999))
self._db[addrid] = address
self._db.sync()
return addrid
def get(self, addrid):
return self._db.get(addrid)
def get_id(self,address):
for id in self._db.keys():
if self._db[id] == address:
return id
return False