changeset 38:df2a719a9b6e

stubbing deletion of nodes + edges
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 24 Dec 2012 22:57:02 -0800
parents f17a6577cc0d
children d1e9602145fa
files tests/doctest.txt wsgraph/model.py
diffstat 2 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/tests/doctest.txt	Sat Dec 15 23:22:19 2012 -0800
+++ b/tests/doctest.txt	Mon Dec 24 22:57:02 2012 -0800
@@ -62,3 +62,11 @@
     'easy as 1..2..3..'
     >>> 'd' in graph['C']
     False
+
+Delete an edge:
+
+    >>> graph = MemoryCache()
+    >>> graph[('a', 'b')] = {'key': 'value'}
+    >>> graph.edges()
+    [('a', 'b')]
+
--- a/wsgraph/model.py	Sat Dec 15 23:22:19 2012 -0800
+++ b/wsgraph/model.py	Mon Dec 24 22:57:02 2012 -0800
@@ -38,6 +38,13 @@
     def edges(self):
         """returns a list of all edges"""
 
+    @abstractmethod
+    def delete(self, node1, node2=None):
+        """
+        delete a node or edge if node2 is given
+        If a node is deleted, all edges to it should be deleted
+        """
+
     def __call__(self):
         """
         returns JSGN format of graph:
@@ -73,6 +80,13 @@
             key1, key2 = key
             self.edge(key1, key2, value)
 
+    def __delitem__(self, key):
+        if isinstance(key, basestring) or (not isiterable(key)):
+            self.delete(key)
+        else:
+            key1, key2 = key
+            self.delete(key1, key2)
+
     def __contains__(self, key):
         """
         if key is ..., returns if that node is in the graph