[pypy-svn] r34017 - in pypy/branch/transparent-proxy/pypy/objspace/std: . test
fijal at codespeak.net
fijal at codespeak.net
Wed Nov 1 13:51:13 CET 2006
Author: fijal
Date: Wed Nov 1 13:51:12 2006
New Revision: 34017
Added:
pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py (contents, props changed)
pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py (contents, props changed)
pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py (contents, props changed)
Modified:
pypy/branch/transparent-proxy/pypy/objspace/std/model.py
pypy/branch/transparent-proxy/pypy/objspace/std/objspace.py
Log:
(pedronis, guido, fijal) - First operation on transparent list.
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 13:51:12 2006
@@ -66,6 +66,7 @@
from pypy.objspace.std import stringobject
from pypy.objspace.std import strsliceobject
from pypy.objspace.std import strjoinobject
+ from pypy.objspace.std import tlistobject
from pypy.objspace.std import typeobject
from pypy.objspace.std import sliceobject
from pypy.objspace.std import longobject
@@ -119,6 +120,9 @@
else:
imported_but_not_registered[implcls] = True
+ # xxx config
+ self.typeorder[tlistobject.W_TransparentList] = []
+
if config.objspace.std.withstrdict:
del self.typeorder[dictobject.W_DictObject]
del self.typeorder[dictobject.W_DictIterObject]
@@ -137,6 +141,7 @@
# register the order in which types are converted into each others
# when trying to dispatch multimethods.
# XXX build these lists a bit more automatically later
+
if config.objspace.std.withsmallint:
self.typeorder[boolobject.W_BoolObject] += [
(smallintobject.W_SmallIntObject, boolobject.delegate_Bool2SmallInt),
Modified: pypy/branch/transparent-proxy/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/branch/transparent-proxy/pypy/objspace/std/objspace.py (original)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/objspace.py Wed Nov 1 13:51:12 2006
@@ -135,6 +135,11 @@
# final setup
self.setup_builtin_modules()
+ # Adding transparent proxy call
+ from pypy.objspace.std.transparent import app_proxy
+
+ self.setitem(self.builtin.w_dict, self.wrap('proxy'),
+ self.wrap(app_proxy))
def enable_old_style_classes_as_default_metaclass(self):
self.setitem(self.builtin.w_dict, self.wrap('__metaclass__'), self.w_classobj)
Added: pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py
==============================================================================
--- (empty file)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/test/test_proxy.py Wed Nov 1 13:51:12 2006
@@ -0,0 +1,31 @@
+
+""" test transparent proxy features
+"""
+
+class AppTestProxy(object):
+ def test_proxy(self):
+ lst = proxy(list, lambda : None)
+ assert type(lst) is list
+
+ def test_proxy_repr(self):
+ def controller(name, *args):
+ lst = [1,2,3]
+ if name == '__repr__':
+ return repr(lst)
+
+ lst = proxy(list, controller)
+ assert repr(lst) == repr([1,2,3])
+
+ def test_proxy_append(self):
+ class Controller(object):
+ def __init__(self, obj):
+ self.obj = obj
+
+ def perform(self, name, *args):
+ return getattr(self.obj, name)(*args)
+
+ c = Controller([])
+ lst = proxy(list, c.perform)
+ lst.append(1)
+ lst.append(2)
+ assert repr(lst) == repr([1,2])
Added: pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py
==============================================================================
--- (empty file)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/tlistobject.py Wed Nov 1 13:51:12 2006
@@ -0,0 +1,27 @@
+
+""" transparent list implementation
+"""
+
+from pypy.objspace.std.objspace import *
+
+class W_TransparentList(W_Object):
+ from pypy.objspace.std.listtype import list_typedef as typedef
+
+ def __init__(self, w_controller):
+ self.controller = w_controller
+
+registerimplementation(W_TransparentList)
+
+def repr__TransparentList(space, w_transparent_list):
+ return space.call_function(w_transparent_list.controller, space.wrap("__repr__"))
+
+def list_append__TransparentList_ANY(space, w_transparent_list, w_any):
+ space.call_function(w_transparent_list.controller, space.wrap("append"), w_any)
+ return space.w_None
+
+def list_extend__TransparentList_ANY(space, w_list, w_any):
+ space.call_function(w_transparent_list.controller, space.wrap("extend"), w_any)
+ return space.w_None
+
+from pypy.objspace.std import listtype
+register_all(vars(), listtype)
Added: pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py
==============================================================================
--- (empty file)
+++ pypy/branch/transparent-proxy/pypy/objspace/std/transparent.py Wed Nov 1 13:51:12 2006
@@ -0,0 +1,18 @@
+
+""" transparent.py - Several transparent proxy helpers
+"""
+
+from pypy.objspace.std.tlistobject import W_TransparentList
+from pypy.interpreter import gateway
+from pypy.interpreter.function import Function
+from pypy.interpreter.error import OperationError
+
+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_w(w_type, space.w_list):
+ raise OperationError(space.w_TypeError, space.wrap("type of object wrapped should be list"))
+ return W_TransparentList(w_controller)
+
+app_proxy = gateway.interp2app(proxy, unwrap_spec=[gateway.ObjSpace, gateway.W_Root, \
+ gateway.W_Root])
More information about the Pypy-commit
mailing list