-
Notifications
You must be signed in to change notification settings - Fork 2
/
paddb.py
41 lines (32 loc) · 824 Bytes
/
paddb.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
from util import keys, values, items
__all__ = [
'PadDB',
]
class PadDB:
"""Proxy for a read-only indexable.
Doesn't load file unless used.
"""
def __init__(self, loader):
self.load = loader
def __getattr__(self, attr):
if attr == 'db':
self.db = self.load()
return self.db
else:
raise AttributeError
def __getitem__(self, index):
return self.db[index]
def keys(self):
return keys(self.db)
def values(self):
return values(self.db)
def items(self):
return items(self.db)
def __len__(self):
return len(self.db)
def __reversed__(self):
return reversed(self.db)
# def __iter__(self):
# return values(self.db)
###
# cards = PadDB(load)