[pypy-svn] r40266 - pypy/dist/demo

hpk at codespeak.net hpk at codespeak.net
Sun Mar 11 22:22:00 CET 2007


Author: hpk
Date: Sun Mar 11 22:21:58 2007
New Revision: 40266

Modified:
   pypy/dist/demo/tp-persistence.py
Log:
strip down example (no need for an actual Storage class in this example)


Modified: pypy/dist/demo/tp-persistence.py
==============================================================================
--- pypy/dist/demo/tp-persistence.py	(original)
+++ pypy/dist/demo/tp-persistence.py	Sun Mar 11 22:21:58 2007
@@ -19,7 +19,7 @@
         self.proxy = transparent_proxy(list, self.perform)
 
     def persist(self):
-        self._storage.pickle(self._obj) 
+        self._storage.dump(self._obj) 
 
     def perform(self, operation, *args, **kwargs):
         result = getattr(self._obj, operation)(*args, **kwargs)
@@ -41,28 +41,18 @@
 
     @classmethod
     def load(cls, storage):
-        obj = storage.unpickle(storage)
+        obj = storage.load()
         return cls(obj, storage) 
 
-
-class Storage:
-    def __init__(self, path): 
-        self.path = py.path.local(path)
-
-    def pickle(self, obj): 
-        self.path.dump(obj) 
-
-    def unpickle(self, storage): 
-        return self.path.load()
-    
 if __name__ == '__main__': 
     import py 
-    storage = Storage("/tmp/mystorage")
+    storage = py.path.local("/tmp/mystorage")
             
     somelist = [1,2,3]
     newlist = PersistentListController(somelist, storage).proxy 
     newlist.append(4) 
     newlist += [5,6,7]
+    assert isinstance(newlist, list)
     #call_some_function(newlist) # will see a regular list
     del somelist, newlist 
     restoredlist = PersistentListController.load(storage).proxy



More information about the Pypy-commit mailing list