[pypy-svn] r34646 - in pypy/dist/pypy/lib: . test2

fijal at codespeak.net fijal at codespeak.net
Thu Nov 16 00:25:23 CET 2006


Author: fijal
Date: Thu Nov 16 00:25:22 2006
New Revision: 34646

Modified:
   pypy/dist/pypy/lib/distributed.py
   pypy/dist/pypy/lib/test2/test_distributed.py
Log:
Added simple fix and a fancy test.


Modified: pypy/dist/pypy/lib/distributed.py
==============================================================================
--- pypy/dist/pypy/lib/distributed.py	(original)
+++ pypy/dist/pypy/lib/distributed.py	Thu Nov 16 00:25:22 2006
@@ -50,6 +50,7 @@
 2. Refactor it a bit (split class into logical/bookkeeper one)
 3. Add some garbage collection
 4. Add caching of objects that are presented (even on name level)
+5. Add exceptions, frames and error handling
 """
 
 from pypymagic import pypy_repr
@@ -58,6 +59,8 @@
 from marshal import dumps
 
 class AbstractProtocol(object):
+    immutable_primitives = (str, int, float, long, unicode, bool, types.NotImplementedType)
+    
     letter_types = {
         'l' : list,
         'd' : dict,
@@ -68,6 +71,7 @@
         'u' : unicode,
         'l' : long,
         's' : str,
+        'ni' : types.NotImplementedType,
         'n' : types.NoneType,
         'lst' : list,
         'fun' : types.FunctionType,
@@ -97,7 +101,7 @@
             return "tp", self.remote_objects[ctrl]
         elif obj is None:
             return self.type_letters[tp]
-        elif tp in (str, int, float, long, unicode, bool):
+        elif tp in self.immutable_primitives:
             # simple, immutable object, just copy
             return (self.type_letters[tp], obj)
         elif tp is tuple:
@@ -129,7 +133,7 @@
         tp = self.letter_types[tp_letter]
         if tp is None:
             return self.objs[obj_data]
-        elif tp in (str, int, float, long, unicode, bool):
+        elif tp in self.immutable_primitives:
             return obj_data # this is the object
         elif tp is tuple:
             return tuple([self.unwrap(i) for i in obj_data])

Modified: pypy/dist/pypy/lib/test2/test_distributed.py
==============================================================================
--- pypy/dist/pypy/lib/test2/test_distributed.py	(original)
+++ pypy/dist/pypy/lib/test2/test_distributed.py	Thu Nov 16 00:25:22 2006
@@ -141,3 +141,22 @@
         xa = protocol.get_remote('a')
         assert xa.__class__.__doc__ == 'xxx'
         assert xa.meth(x) == 4
+
+    def test_double_reference(self):
+        class A:
+            def meth(self, one):
+                self.one = one
+            
+            def perform(self):
+                return 1 + len(self.one())
+        
+        class B:
+            def __call__(self):
+                return [1,2,3]
+        
+        from distributed import test_env
+        a = A()
+        protocol = test_env({'a': a})
+        xa = protocol.get_remote('a')
+        xa.meth(B())
+        assert xa.perform() == 4



More information about the Pypy-commit mailing list