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

fijal at codespeak.net fijal at codespeak.net
Fri Nov 3 14:12:52 CET 2006


Author: fijal
Date: Fri Nov  3 14:12:51 2006
New Revision: 34098

Modified:
   pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py
   pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py
Log:
(samuele, fijal) - It seems that TransparentList and TransparentDict are working quite well.


Modified: pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py	(original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py	Fri Nov  3 14:12:51 2006
@@ -5,6 +5,7 @@
 
 from pypy.objspace.std.model import W_ANY, W_Object
 from pypy.interpreter import baseobjspace
+from pypy.interpreter.argument import Arguments
 
 def create_mm_names(classname, mm, is_local):
     s = ""
@@ -16,9 +17,31 @@
         return s, '__' + mm.name + '__'
     return s, mm.name
 
+def install_general_args_trampoline(type_, mm, is_local):
+    def function(space, w_transparent_list, __args__):
+        args = __args__.prepend(space.wrap(mm.name))
+        return space.call_args(w_transparent_list.controller, args)
+    
+    function.func_name = mm.name
+    mm.register(function, type_)
+
+def install_w_args_trampoline(type_, mm, is_local):
+    def function(space, w_transparent_list, *args_w):
+        args = Arguments(space, [space.wrap(mm.name)] + list(args_w[:-1]), w_stararg=args_w[-1])
+        return space.call_args(w_transparent_list.controller, args)
+    
+    function.func_name = mm.name
+    mm.register(function, type_, *([W_ANY] * (mm.arity - 1)))
+
 def install_mm_trampoline(type_, mm, is_local):
     classname = type_.__name__[2:]
     mm_name, op_name = create_mm_names(classname, mm, is_local)
+    
+    if ['__args__'] == mm.argnames_after:
+        return install_general_args_trampoline(type_, mm, is_local)
+    if ['w_args'] == mm.argnames_after:
+        return install_w_args_trampoline(type_, mm, is_local)
+    assert not mm.argnames_after
     # we search here for special-cased stuff
     def function(space, w_transparent_list, *args_w):
         return space.call_function(w_transparent_list.controller, space.wrap\

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	Fri Nov  3 14:12:51 2006
@@ -9,8 +9,8 @@
             def __init__(self, obj):
                 self.obj = obj
     
-            def perform(self, name, *args):
-                return getattr(self.obj, name)(*args)
+            def perform(self, name, *args, **kwargs):
+                return getattr(self.obj, name)(*args, **kwargs)
         return Controller
         """)
     
@@ -63,12 +63,34 @@
         lst[1] = 0
         assert lst[0] + lst[1] == 1
 
+    def test_list_setitem(self):
+        c = self.Controller([1,2,3])
+        lst = proxy(list, c.perform)
+        try:
+            lst[3] = "x"
+        except IndexError:
+            pass
+        else:
+            fail("Accessing outside a list didn't raise")
+
     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]
+        d2 = {'yy':3}
+        d.update(d2, x=4)
+        assert sorted(d.keys()) == ['x', 'xx', 'yy']
+        assert sorted(d.values()) == [1, 3, 4]
+    
+    def test_dict_pop(self):
+        c = self.Controller({'x':1})
+        d = proxy(dict, c.perform)
+        assert d.pop('x') == 1
+        assert d.pop('x', None) is None
+
+    def test_dict_iter(self):
+        c = self.Controller({'a':1, 'b':2, 'c':3})
+        d = proxy(dict, c.perform)
+        d['z'] = 4
+        assert sorted(list(d.iterkeys())) == ['a', 'b', 'c', 'z']



More information about the Pypy-commit mailing list