[pypy-svn] r34112 - in pypy/branch/transparent-proxy/pypy/objspace/std: . test
fijal at codespeak.net
fijal at codespeak.net
Fri Nov 3 16:03:43 CET 2006
Author: fijal
Date: Fri Nov 3 16:03:41 2006
New Revision: 34112
Added:
pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_object.py (contents, props changed)
Modified:
pypy/branch/transparent-proxy/pypy/objspace/std/proxy_helpers.py
pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py
pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
Log:
(samuele, fijal) - Added user created objects and fixed some bugs.
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 16:03:41 2006
@@ -20,7 +20,7 @@
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)
+ return space.call_args(w_transparent_list.w_controller, args)
function.func_name = mm.name
mm.register(function, type_)
@@ -28,7 +28,7 @@
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)
+ return space.call_args(w_transparent_list.w_controller, args)
function.func_name = mm.name
mm.register(function, type_, *([W_ANY] * (mm.arity - 1)))
@@ -44,7 +44,7 @@
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\
+ return space.call_function(w_transparent_list.w_controller, space.wrap\
(op_name), *args_w)
function.func_name = mm_name
mm.register(function, type_, *([W_ANY] * (mm.arity - 1)))
@@ -70,7 +70,7 @@
#mm_name, op_name = create_mm_names(classname, mm, is_local)
def function(space, w_any, w_transparent_list):
- retval = space.call_function(w_transparent_list.controller, space.wrap(mm.specialnames[1]),
+ retval = space.call_function(w_transparent_list.w_controller, space.wrap(mm.specialnames[1]),
w_any)
return retval
Added: pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_object.py
==============================================================================
--- (empty file)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy_object.py Fri Nov 3 16:03:41 2006
@@ -0,0 +1,75 @@
+
+""" test proxy object
+"""
+
+from pypy.objspace.std.test.test_proxy import AppProxyBasic
+
+class AppTestProxyObj(AppProxyBasic):
+ def setup_method(self, meth):
+ super(AppTestProxyObj, self).setup_method(meth)
+ self.w_A = self.space.appexec([], """():
+ class A(object):
+ pass
+ return A
+ """)
+
+ def test_simple_obj(self):
+ class AT(self.A):
+ pass
+
+ c = self.Controller(self.A())
+ obj = proxy(AT, c.perform)
+
+ assert type(obj) is AT
+ assert obj.__class__ is AT
+
+ def test__class__override(self):
+ c = self.Controller(self.A())
+ obj = proxy(self.A, c.perform)
+
+ raises(TypeError, "obj.__class__ = self.A")
+
+ def test_attribute_access(self):
+ a = self.A()
+ a.x = 3
+ c = self.Controller(a)
+ obj = proxy(self.A, c.perform)
+
+ assert obj.x == 3
+
+ def test_nonexistant_attribuite_access(self):
+ c = self.Controller(self.A())
+ obj = proxy(self.A, c.perform)
+ raises(AttributeError, "obj.x")
+
+ def test_setattr(self):
+ a = self.A()
+ c = self.Controller(a)
+ obj = proxy(self.A, c.perform)
+ obj.x = 1
+ assert obj.x == 1
+ assert a.x == 1
+
+ def test_delattr(self):
+ a = self.A()
+ a.f = 3
+ c = self.Controller(a)
+ obj = proxy(self.A, c.perform)
+ del obj.f
+ raises(AttributeError, "obj.f")
+
+class AppTestProxyObjectList(AppTestProxyObj):
+ def setup_method(self, meth):
+ super(AppTestProxyObj, self).setup_method(meth)
+ self.w_A = self.space.appexec([], """():
+ class A(list):
+ pass
+ return A
+ """)
+
+ def test_list_append(self):
+ a = self.A([1,2,3])
+ c = self.Controller(a)
+ obj = proxy(self.A, c.perform)
+ assert len(obj) == 3
+ assert obj[1] == 2
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:03:41 2006
@@ -6,11 +6,11 @@
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_Transparent(W_Object):
+# def __init__(self, w_controller):
+# self.controller = w_controller
-class W_TransparentObject(W_Object):
+class W_Transparent(W_Object):
def __init__(self, w_type, w_controller):
self.w_type = w_type
self.w_controller = w_controller
@@ -41,6 +41,16 @@
raise
return False
+ def deldictvalue(self, space, w_attr):
+ try:
+ space.call_function(self.w_controller, space.wrap('__delattr__'),
+ w_attr)
+ 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):
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:03:41 2006
@@ -6,21 +6,19 @@
from pypy.interpreter.function import Function
from pypy.interpreter.error import OperationError
from pypy.objspace.std.tlistobject import W_TransparentList, W_TransparentDict,\
- W_TransparentObject
+ W_Transparent
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 space.is_true(space.issubtype(w_type, space.w_list)):
- return W_TransparentList(w_controller)
+ return W_TransparentList(w_type, w_controller)
if space.is_true(space.issubtype(w_type, space.w_dict)):
- return W_TransparentDict(w_controller)
- 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 W_TransparentDict(w_type, w_controller)
+ if w_type.instancetypedef is space.w_object.instancetypedef:
+ return W_Transparent(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-commit
mailing list