[pypy-svn] r34115 - in pypy/branch/transparent-proxy/pypy/objspace/std: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Nov 3 16:13:19 CET 2006
Author: fijal
Date: Fri Nov 3 16:13:15 2006
New Revision: 34115
Modified:
pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_object.py
pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py
pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
Log:
(samuele, fijal) - __dict__ writing/reading.
Modified: pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_object.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_object.py (original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_object.py Fri Nov 3 16:13:15 2006
@@ -57,6 +57,21 @@
obj = proxy(self.A, c.perform)
del obj.f
raises(AttributeError, "obj.f")
+
+ def test__dict__(self):
+ a = self.A()
+ a.x = 3
+ c = self.Controller(a)
+ obj = proxy(self.A, c.perform)
+ assert 'x' in obj.__dict__
+
+ def test_set__dict__(self):
+ a = self.A()
+ c = self.Controller(a)
+ obj = proxy(self.A, c.perform)
+ obj.__dict__ = {'x':3}
+ assert obj.x == 3
+ assert obj.__dict__.keys() == ['x']
class AppTestProxyObjectList(AppTestProxyObj):
def setup_method(self, meth):
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 16:13:15 2006
@@ -11,9 +11,10 @@
# self.controller = w_controller
class W_Transparent(W_Object):
- def __init__(self, w_type, w_controller):
+ def __init__(self, space, w_type, w_controller):
self.w_type = w_type
self.w_controller = w_controller
+ self.space = space
def getclass(self, space):
return self.w_type
@@ -51,6 +52,13 @@
raise
return False
+ def getdict(self):
+ return self.getdictvalue(self.space, self.space.wrap('__dict__'))
+
+ def setdict(self, space, w_dict):
+ if not self.setdictvalue(space, space.wrap('__dict__'), w_dict):
+ W_Root.setdict(self, space, w_dict)
+
from pypy.objspace.std.objecttype import object_typedef as typedef
class W_TransparentList(W_Transparent):
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 16:13:15 2006
@@ -13,11 +13,11 @@
raise OperationError(space.w_TypeError, space.wrap("controller should be function"))
if space.is_true(space.issubtype(w_type, space.w_list)):
- return W_TransparentList(w_type, w_controller)
+ return W_TransparentList(space, w_type, w_controller)
if space.is_true(space.issubtype(w_type, space.w_dict)):
- return W_TransparentDict(w_type, w_controller)
+ return W_TransparentDict(space, w_type, w_controller)
if w_type.instancetypedef is space.w_object.instancetypedef:
- return W_Transparent(w_type, w_controller)
+ return W_Transparent(space, 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, "?")))
More information about the pypy-svn
mailing list