comparison wsgraph/model.py @ 25:d1a8c1436ded

notes to self
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 12 Dec 2012 18:39:47 -0800
parents 24d57daaca21
children 4bed1424bb3f
comparison
equal deleted inserted replaced
24:e46b4466abac 25:d1a8c1436ded
1 from abc import abstractmethod 1 from abc import abstractmethod
2 from copy import deepcopy 2 from copy import deepcopy
3 from utils import isiterable 3 from utils import isiterable
4 4
5 class GraphModel(object): 5 class Graph(object):
6 6
7 @abstractmethod 7 @abstractmethod
8 def node(self, name, **values): 8 def node(self, name, **values):
9 """ 9 """
10 get or set a node 10 get or set a node
68 return key in self.nodes() 68 return key in self.nodes()
69 else: 69 else:
70 return tuple(key) in self.edges() 70 return tuple(key) in self.edges()
71 71
72 72
73 class MemoryCache(GraphModel): 73 class MemoryCache(Graph):
74 """volatile in-memory representation of a graph""" 74 """volatile in-memory representation of a graph"""
75 75
76 def __init__(self): 76 def __init__(self):
77 self._edges = {} 77 self._edges = {}
78 self._nodes = {} 78 self._nodes = {}
98 # TODO: deepcopy 98 # TODO: deepcopy
99 return self._edges.get((node1, node2), None) 99 return self._edges.get((node1, node2), None)
100 100
101 def edges(self): 101 def edges(self):
102 return self._edges.keys() 102 return self._edges.keys()
103
104 class FileCache(MemoryCache):
105 """on-disk JSON file cache"""
106
107 def __init__(self, filename):
108 self.filename = filename
109 raise NotImplementedError
110
111 # TODO: CLI entry point to convert from one model to another
112 # def main()