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

fijal at codespeak.net fijal at codespeak.net
Fri Nov 3 15:34:43 CET 2006


Author: fijal
Date: Fri Nov  3 15:34:42 2006
New Revision: 34109

Modified:
   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:
(samuele, fijal) - Progress. For use objects we've got attribute getting and setting.


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 15:34:42 2006
@@ -2,7 +2,9 @@
 """ test transparent proxy features
 """
 
-class AppTestProxy(object):
+from pypy.conftest import gettestobjspace
+
+class AppProxyBasic(object):
     def setup_method(self, meth):
         self.w_Controller = self.space.appexec([], """():
         class Controller(object):
@@ -13,7 +15,8 @@
                 return getattr(self.obj, name)(*args, **kwargs)
         return Controller
         """)
-    
+
+class AppTestListProxy(AppProxyBasic):
     def test_proxy(self):
         lst = proxy(list, lambda : None)
         assert type(lst) is list
@@ -73,6 +76,7 @@
         else:
             fail("Accessing outside a list didn't raise")
 
+class AppTestDictProxy(AppProxyBasic):
     def test_dict(self):
         c = self.Controller({"xx":1})
         d = proxy(dict, c.perform)
@@ -94,3 +98,7 @@
         d = proxy(dict, c.perform)
         d['z'] = 4
         assert sorted(list(d.iterkeys())) == ['a', 'b', 'c', 'z']
+
+class AppTestDictStrProxy(AppTestDictProxy):
+    def setup_class(cls):
+        cls.space = gettestobjspace(**{"objspace.std.withstrdict": True})

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	Fri Nov  3 15:34:42 2006
@@ -4,11 +4,45 @@
 
 from pypy.objspace.std.objspace import *
 from pypy.objspace.std.proxy_helpers import register_type
+from pypy.interpreter.error import OperationError
 
 class W_Transparent(W_Object):
     def __init__(self, w_controller):
         self.controller = w_controller
 
+class W_TransparentObject(W_Object):
+    def __init__(self, w_type, w_controller):
+        self.w_type = w_type
+        self.w_controller = w_controller
+    
+    def getclass(self, space):
+        return self.w_type
+    
+    def setclass(self, space, w_subtype):
+        raise OperationError(space.w_TypeError,
+                             space.wrap("You cannot override __class__ for transparent proxies"))
+    
+    def getdictvalue(self, space, w_attr):
+        try:
+            return space.call_function(self.w_controller, space.wrap('__getattribute__'),
+               w_attr)
+        except OperationError, e:
+            if not e.match(space, space.w_AttributeError):
+                raise
+            return None
+    
+    def setdictvalue(self, space, w_attr, w_value):
+        try:
+            space.call_function(self.w_controller, space.wrap('__setattr__'),
+               w_attr, w_value)
+            return True
+        except OperationError, e:
+            if not e.match(space, space.w_AttributeError):
+                raise
+            return False
+    
+    from pypy.objspace.std.objecttype import object_typedef as typedef
+
 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

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	Fri Nov  3 15:34:42 2006
@@ -5,7 +5,8 @@
 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, W_TransparentDict
+from pypy.objspace.std.tlistobject import W_TransparentList, W_TransparentDict,\
+    W_TransparentObject
 
 def proxy(space, w_type, w_controller):
     if not space.is_true(space.callable(w_controller)):
@@ -15,7 +16,13 @@
         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"))
+    w_bestbase = w_type.w_bestbase
+    if w_bestbase is not None and space.is_w(w_bestbase, space.w_object):
+       return W_TransparentObject(w_type, w_controller)
+    #return type_cache[w_type or w_type.w_bestbase]
+        
+    raise OperationError(space.w_TypeError, space.wrap("Object type %s could not"\
+          "be wrapped (YET)" % w_type.getname(space, "?")))
 
 app_proxy = gateway.interp2app(proxy, unwrap_spec=[gateway.ObjSpace, gateway.W_Root, \
     gateway.W_Root])



More information about the Pypy-commit mailing list