[pypy-svn] r39718 - in pypy/dist/pypy/lib/distributed: . test

fijal at codespeak.net fijal at codespeak.net
Fri Mar 2 17:08:40 CET 2007


Author: fijal
Date: Fri Mar  2 17:08:39 2007
New Revision: 39718

Modified:
   pypy/dist/pypy/lib/distributed/objkeeper.py
   pypy/dist/pypy/lib/distributed/test/test_distributed.py
Log:
Explicitely disallow instantiating of remote types


Modified: pypy/dist/pypy/lib/distributed/objkeeper.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/objkeeper.py	(original)
+++ pypy/dist/pypy/lib/distributed/objkeeper.py	Fri Mar  2 17:08:39 2007
@@ -11,6 +11,10 @@
     _, _, tb = sys.exc_info()
     GetSetDescriptor = type(type(tb).tb_frame)
 
+class noninstantiabletype(object):
+    def __new__(cls, *args, **kwargs):
+        raise NotImplementedError("Cannot instantiate remote type")
+
 class ObjKeeper(object):
     def __init__(self, exported_names = {}):
         self.exported_objects = [] # list of object that we've exported outside
@@ -52,10 +56,10 @@
     def fake_remote_type(self, protocol, type_id, _name, _dict):
         print "Faking type %s as %s" % (_name, type_id)
         # create and register new type
-        d = dict([(key, None) for key in _dict])
+        d = dict([(key, None) for key in _dict if key != '__new__'])
         if '__doc__' in _dict:
             d['__doc__'] = protocol.unwrap(_dict['__doc__'])
-        tp = type(_name, (object,), d)
+        tp = type(_name, (noninstantiabletype,), d)
         # Make sure we cannot instantiate the remote type
         self.remote_types[type_id] = tp
         for key, value in _dict.items():

Modified: pypy/dist/pypy/lib/distributed/test/test_distributed.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/test/test_distributed.py	(original)
+++ pypy/dist/pypy/lib/distributed/test/test_distributed.py	Fri Mar  2 17:08:39 2007
@@ -199,10 +199,10 @@
             raise AssertionError("Did not raise")
 
     def test_instantiate_remote_type(self):
-        skip("Land of infinite recursion")
+        #skip("Land of infinite recursion")
         class C:
             pass
 
         protocol = self.test_env({'C':C})
         xC = protocol.get_remote('C')
-        xC()
+        raises(NotImplementedError, "xC()")



More information about the Pypy-commit mailing list