# HG changeset patch # User Jeff Hammel # Date 1355642539 28800 # Node ID f17a6577cc0d9e12dcfa6d9c89c9cbad55e79f59 # Parent 5ea58a6ea8207345641459b6857b55b1d9307bd9 make default type configurable diff -r 5ea58a6ea820 -r f17a6577cc0d wsgraph/model.py --- a/wsgraph/model.py Fri Dec 14 20:53:41 2012 -0800 +++ b/wsgraph/model.py Sat Dec 15 23:22:19 2012 -0800 @@ -85,12 +85,18 @@ return tuple(key) in self.edges() +class DirectedGraph(Graph): + """mix-in class for directed graphs""" + # TODO: is this possible without super or other black magicks? + + class MemoryCache(Graph): """volatile in-memory representation of a graph""" - def __init__(self): + def __init__(self, node_type=dict): self._edges = {} self._nodes = {} + self.node_type = node_type def node(self, name, value=None): if value is not None: @@ -109,7 +115,7 @@ # setter self._edges[(node1, node2)] = deepcopy(value) for node in node1, node2: - self._nodes.setdefault(node, {}) + self._nodes.setdefault(node, self.node_type()) else: # getter # TODO: deepcopy @@ -118,6 +124,7 @@ def edges(self): return self._edges.keys() + class FileCache(MemoryCache): """on-disk JSON file cache"""