[pypy-svn] r34045 - in pypy/branch/transparent-proxy/pypy/objspace/std: . test

fijal at codespeak.net fijal at codespeak.net
Wed Nov 1 17:37:59 CET 2006


Author: fijal
Date: Wed Nov  1 17:37:57 2006
New Revision: 34045

Modified:
   pypy/branch/transparent-proxy/pypy/objspace/std/model.py
   pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py
   pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py
   pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
Log:
(fijal, guido, arigo, pedronis) - Naively added dictionary


Modified: pypy/branch/transparent-proxy/pypy/objspace/std/model.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/model.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/model.py	Wed Nov  1 17:37:57 2006
@@ -122,6 +122,7 @@
 
         # xxx config
         self.typeorder[tlistobject.W_TransparentList] = []
+        self.typeorder[tlistobject.W_TransparentDict] = []
 
         if config.objspace.std.withstrdict:
             del self.typeorder[dictobject.W_DictObject]

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py	Wed Nov  1 17:37:57 2006
@@ -61,3 +61,13 @@
         assert lst[2] == 3
         lst[1] = 0
         assert lst[0] + lst[1] == 1
+
+    def test_dict(self):
+        c = self.Controller({"xx":1})
+        d = proxy(dict, c.perform)
+        assert d['xx'] == 1
+        assert 'yy' not in d
+        #d2 = {'yy':3}
+        #d.update(d2)
+        #assert sorted(d.keys()) == ['xx', 'yy']
+        #assert sorted(d.values()) == [1, 3]

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py	Wed Nov  1 17:37:57 2006
@@ -5,13 +5,21 @@
 from pypy.objspace.std.objspace import *
 from pypy.objspace.std.proxy_helpers import register_type
 
-class W_TransparentList(W_Object):
-    from pypy.objspace.std.listobject import W_ListObject as original
-    from pypy.objspace.std.listtype import list_typedef as typedef
-
+class W_Transparent(W_Object):
     def __init__(self, w_controller):
         self.controller = w_controller
 
+class W_TransparentList(W_Transparent):
+    from pypy.objspace.std.listobject import W_ListObject as original
+    from pypy.objspace.std.listtype import list_typedef as typedef
+    
+class W_TransparentDict(W_Transparent):
+    from pypy.objspace.std.dictobject import W_DictObject as original
+    from pypy.objspace.std.dicttype import dict_typedef as typedef
+
 registerimplementation(W_TransparentList)
+registerimplementation(W_TransparentDict)
+
 
 register_type(W_TransparentList)
+register_type(W_TransparentDict)

Modified: pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py	Wed Nov  1 17:37:57 2006
@@ -5,15 +5,17 @@
 from pypy.interpreter import gateway
 from pypy.interpreter.function import Function
 from pypy.interpreter.error import OperationError
-from pypy.objspace.std.tlistobject import W_TransparentList
+from pypy.objspace.std.tlistobject import W_TransparentList, W_TransparentDict
 
 def proxy(space, w_type, w_controller):
     if not space.is_true(space.callable(w_controller)):
         raise OperationError(space.w_TypeError, space.wrap("controller should be function"))
-    if not space.is_true(space.issubtype(w_type, space.w_list)):
-        raise OperationError(space.w_TypeError, space.wrap("type of object wrapped should be list"))
-
-    return W_TransparentList(w_controller)
+    
+    if space.is_true(space.issubtype(w_type, space.w_list)):
+        return W_TransparentList(w_controller)
+    if space.is_true(space.issubtype(w_type, space.w_dict)):
+        return W_TransparentDict(w_controller)
+    raise OperationError(space.w_TypeError, space.wrap("type of object wrapped should be list or int"))
 
 app_proxy = gateway.interp2app(proxy, unwrap_spec=[gateway.ObjSpace, gateway.W_Root, \
     gateway.W_Root])


More information about the pypy-svn mailing list