comparison wsgraph/model.py @ 9:0affca1f4dc0

start using deepcopy since lord knows we cant trust users
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 10 Dec 2012 17:10:50 -0800
parents f1f7a505e0d0
children 81d68388ec97
comparison
equal deleted inserted replaced
8:f1f7a505e0d0 9:0affca1f4dc0
1 from abc import abstractmethod 1 from abc import abstractmethod
2 from copy import deepcopy
2 from utils import iterable 3 from utils import iterable
3 4
4 class GraphModel(object): 5 class GraphModel(object):
5 6
6 @abstractmethod 7 @abstractmethod
48 self._nodes = {} 49 self._nodes = {}
49 50
50 def node(self, name, **values): 51 def node(self, name, **values):
51 if values: 52 if values:
52 # setter 53 # setter
53 self._nodes[name] = values 54 self._nodes[name] = deepcopy(values)
54 else: 55 else:
55 # getter 56 # getter
57 # TODO: deepcopy
56 return self._nodes.get(name, None) 58 return self._nodes.get(name, None)
57 59
58 def nodes(self): 60 def nodes(self):
59 return self._nodes.keys() 61 return self._nodes.keys()
60 62
61 def edge(self, node1, node2, **values): 63 def edge(self, node1, node2, **values):
62 if values: 64 if values:
63 # setter 65 # setter
64 self._edges[(node1, node2)] = values 66 self._edges[(node1, node2)] = deepcopy(values)
65 else: 67 else:
66 # getter 68 # getter
69 # TODO: deepcopy
67 return self._edges.get((node1, node2), None) 70 return self._edges.get((node1, node2), None)
68 71
69 def edges(self): 72 def edges(self):
70 return self._edges.keys() 73 return self._edges.keys()