-
Notifications
You must be signed in to change notification settings - Fork 0
/
couch.py
47 lines (33 loc) · 907 Bytes
/
couch.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
import copy
class CouchCollection():
def __init__(self):
""":type : list[CouchItem] """
self.items = []
def add_item(self, item):
"""
:type item: CouchItem
"""
self.items.append(item)
def len(self):
return len(self.items)
def __repr__(self):
result = "[ "
for item in self.items:
result += "\t{}".format(item)
return result + " ]"
class CouchItem:
def __init__(self):
pass
def to_dict(self):
"""
:rtype: dict
"""
return copy.deepcopy(self.__dict__)
def __repr__(self):
result = ""
for key, value in self.to_dict().iteritems():
try:
result += "{0:20} -> {1}\n".format(key, value)
except UnicodeEncodeError:
result += "UnicodeEncodeError\n"
return result