[pypy-svn] r40932 - in pypy/dist: demo pypy/doc pypy/lib pypy/lib/distributed pypy/lib/test2 pypy/objspace/std pypy/objspace/std/test
hpk at codespeak.net
hpk at codespeak.net
Wed Mar 21 15:05:45 CET 2007
Author: hpk
Date: Wed Mar 21 15:05:42 2007
New Revision: 40932
Modified:
pypy/dist/demo/tp-persistence.py
pypy/dist/pypy/doc/objspace-proxies.txt
pypy/dist/pypy/lib/distributed/protocol.py
pypy/dist/pypy/lib/test2/test_tputil.py
pypy/dist/pypy/lib/tputil.py
pypy/dist/pypy/objspace/std/objspace.py
pypy/dist/pypy/objspace/std/test/test_proxy.py
pypy/dist/pypy/objspace/std/test/test_proxy_function.py
pypy/dist/pypy/objspace/std/test/test_proxy_internals.py
pypy/dist/pypy/objspace/std/test/test_proxy_object.py
Log:
consistently rename transparent_proxy to tproxy
and get_transparent_controller to get_tproxy_controller
and make_proxy to make_instance_proxy (not completely
sure about the last one but i'd like to distinguish
the name a bit from the more "virtual" tproxy
operating on types whereas make_instance_proxy
helps to proxy an existing object (you can
still provide a type if you wish))
Modified: pypy/dist/demo/tp-persistence.py
==============================================================================
--- pypy/dist/demo/tp-persistence.py (original)
+++ pypy/dist/demo/tp-persistence.py Wed Mar 21 15:05:42 2007
@@ -4,8 +4,8 @@
mechanism on top of PyPy's transparent proxies.
"""
-from pypymagic import transparent_proxy, get_transparent_controller
-from tputil import make_proxy
+from pypymagic import tproxy, get_tproxy_controller
+from tputil import make_instance_proxy
list_changeops = set('__iadd__ __imul__ __delitem__ __setitem__ '
'__delslice__ __setslice__ '
@@ -17,7 +17,7 @@
if invocation.opname in list_changeops:
storage.dump(instance)
return res
- return make_proxy(instance, perform, typ=list)
+ return make_instance_proxy(instance, perform, typ=list)
def get_plist(storage):
obj = storage.load()
Modified: pypy/dist/pypy/doc/objspace-proxies.txt
==============================================================================
--- pypy/dist/pypy/doc/objspace-proxies.txt (original)
+++ pypy/dist/pypy/doc/objspace-proxies.txt Wed Mar 21 15:05:42 2007
@@ -468,13 +468,13 @@
return ``42`` on any add operation to the list::
$ py.py --with-transparent-proxy
- >>>> from pypymagic import transparent_proxy
+ >>>> from pypymagic import tproxy
>>>> def f(operation, *args, **kwargs):
>>>> if operation == '__add__':
>>>> return 42
>>>> raise AttributeError
>>>>
- >>>> i = transparent_proxy(list, f)
+ >>>> i = tproxy(list, f)
>>>> type(i)
list
>>>> i + 3
@@ -493,14 +493,14 @@
it for later analysis. We use a small `tputil.py`_ module that helps
with transparently proxying builtin instances::
- from tputil import make_proxy
+ from tputil import make_instance_proxy
history = []
def recorder(invocation):
history.append(invocation)
return invocation.perform()
- >>>> l = make_proxy([], recorder)
+ >>>> l = make_instance_proxy([], recorder)
>>>> type(l)
list
>>>> l.append(3)
@@ -533,9 +533,9 @@
Transparent proxy provides two functions in the pypymagic module.
-* `transparent_proxy` - a basic function to create proxy object.
+* `tproxy` - a basic function to create proxy object.
-* `get_transparent_controller` - for some use-cases there is need to know
+* `get_tproxy_controller` - for some use-cases there is need to know
when an object is a transparent proxy. This function returns an original controller
(a callable) or None in case this is a normal Python object. This is
the only official way of distinguishing transparent objects from normal ones.
Modified: pypy/dist/pypy/lib/distributed/protocol.py
==============================================================================
--- pypy/dist/pypy/lib/distributed/protocol.py (original)
+++ pypy/dist/pypy/lib/distributed/protocol.py Wed Mar 21 15:05:42 2007
@@ -36,8 +36,8 @@
"""
try:
- from pypymagic import transparent_proxy as proxy
- from pypymagic import get_transparent_controller
+ from pypymagic import tproxy as proxy
+ from pypymagic import get_tproxy_controller
except ImportError:
raise ImportError("Cannot work without transparent proxy functionality")
@@ -112,7 +112,7 @@
return False
tp = type(obj)
- ctrl = get_transparent_controller(obj)
+ ctrl = get_tproxy_controller(obj)
if ctrl:
return "tp", self.keeper.get_remote_object(ctrl)
elif obj is None:
Modified: pypy/dist/pypy/lib/test2/test_tputil.py
==============================================================================
--- pypy/dist/pypy/lib/test2/test_tputil.py (original)
+++ pypy/dist/pypy/lib/test2/test_tputil.py Wed Mar 21 15:05:42 2007
@@ -5,12 +5,12 @@
cls.space = gettestobjspace(**{"objspace.std.withtproxy": True})
def test_listproxy_basic(self):
- from tputil import make_proxy
+ from tputil import make_instance_proxy
record = []
def func(invocation):
record.append(invocation)
return invocation.perform()
- l = make_proxy([], func)
+ l = make_instance_proxy([], func)
l.append(1)
assert len(record) == 2
i1, i2 = record
@@ -18,7 +18,7 @@
assert i2.opname == 'append'
def test_proxy_double(self):
- from tputil import make_proxy
+ from tputil import make_instance_proxy
r1 = []
r2 = []
def func1(invocation):
@@ -28,8 +28,8 @@
r2.append(invocation)
return invocation.perform()
- l = make_proxy([], func1)
- l2 = make_proxy(l, func2)
+ l = make_instance_proxy([], func1)
+ l2 = make_instance_proxy(l, func2)
assert not r1 and not r2
l2.append
assert len(r2) == 1
Modified: pypy/dist/pypy/lib/tputil.py
==============================================================================
--- pypy/dist/pypy/lib/tputil.py (original)
+++ pypy/dist/pypy/lib/tputil.py Wed Mar 21 15:05:42 2007
@@ -7,16 +7,16 @@
the proxied object.
"""
-from pypymagic import transparent_proxy
+from pypymagic import tproxy
from types import MethodType
-def make_proxy(instance, invokefunc=None, typ=None):
+def make_instance_proxy(instance, invokefunc=None, typ=None):
if typ is None:
typ = type(instance)
def perform(opname, *args, **kwargs):
invocation = Invocation(tp, instance, opname, args, kwargs)
return invokefunc(invocation)
- tp = transparent_proxy(typ, perform)
+ tp = tproxy(typ, perform)
return tp
class Invocation(object):
Modified: pypy/dist/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/dist/pypy/objspace/std/objspace.py (original)
+++ pypy/dist/pypy/objspace/std/objspace.py Wed Mar 21 15:05:42 2007
@@ -215,9 +215,9 @@
w_pypymagic = self.getbuiltinmodule("pypymagic")
from pypy.objspace.std.transparent import app_proxy, app_proxy_controller
- self.setattr(w_pypymagic, self.wrap('transparent_proxy'),
+ self.setattr(w_pypymagic, self.wrap('tproxy'),
self.wrap(app_proxy))
- self.setattr(w_pypymagic, self.wrap('get_transparent_controller'),
+ self.setattr(w_pypymagic, self.wrap('get_tproxy_controller'),
self.wrap(app_proxy_controller))
def enable_old_style_classes_as_default_metaclass(self):
Modified: pypy/dist/pypy/objspace/std/test/test_proxy.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_proxy.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_proxy.py Wed Mar 21 15:05:42 2007
@@ -19,8 +19,8 @@
return Controller
""")
self.w_proxy = self.space.appexec([], """():
- from pypymagic import transparent_proxy
- return transparent_proxy
+ from pypymagic import tproxy
+ return tproxy
""")
class AppTestListProxy(AppProxyBasic):
Modified: pypy/dist/pypy/objspace/std/test/test_proxy_function.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_proxy_function.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_proxy_function.py Wed Mar 21 15:05:42 2007
@@ -19,7 +19,7 @@
return getattr(self.obj, name)(*args, **kwargs)
def get_proxy(f):
import types
- from pypymagic import transparent_proxy as proxy
+ from pypymagic import tproxy as proxy
return proxy(types.FunctionType, Controller(f).perform)
return get_proxy
""")
@@ -90,7 +90,7 @@
class AA:
pass
- from pypymagic import transparent_proxy as proxy
+ from pypymagic import tproxy as proxy
a = A()
class X:
def __init__(self, x):
Modified: pypy/dist/pypy/objspace/std/test/test_proxy_internals.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_proxy_internals.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_proxy_internals.py Wed Mar 21 15:05:42 2007
@@ -16,7 +16,7 @@
def perform(self, name, *args, **kwargs):
return getattr(self.obj, name)(*args, **kwargs)
def get_proxy(f):
- from pypymagic import transparent_proxy as proxy
+ from pypymagic import tproxy as proxy
return proxy(type(f), Controller(f).perform)
return get_proxy
""")
@@ -71,7 +71,7 @@
import traceback
def get_proxy(f):
- from pypymagic import transparent_proxy as proxy
+ from pypymagic import tproxy as proxy
return proxy(type(f), Controller(f).perform)
class FakeTb(object):
@@ -115,12 +115,12 @@
assert traceback.format_tb(last_tb) == traceback.format_tb(e[2])
def test_proxy_get(self):
- from pypymagic import transparent_proxy, get_transparent_controller
+ from pypymagic import tproxy, get_tproxy_controller
l = [1,2,3]
def f(name, *args, **kwargs):
return getattr(l, name)(*args, **kwargs)
- lst = transparent_proxy(list, f)
- assert get_transparent_controller(lst) is f
+ lst = tproxy(list, f)
+ assert get_tproxy_controller(lst) is f
class DONTAppTestProxyType(AppProxy):
def test_filetype(self):
Modified: pypy/dist/pypy/objspace/std/test/test_proxy_object.py
==============================================================================
--- pypy/dist/pypy/objspace/std/test/test_proxy_object.py (original)
+++ pypy/dist/pypy/objspace/std/test/test_proxy_object.py Wed Mar 21 15:05:42 2007
@@ -13,8 +13,8 @@
return A
""")
self.w_proxy = self.space.appexec([], """():
- from pypymagic import transparent_proxy
- return transparent_proxy
+ from pypymagic import tproxy
+ return tproxy
""")
def test_write_dict(self):
@@ -106,8 +106,8 @@
return A
""")
self.w_proxy = self.space.appexec([], """():
- from pypymagic import transparent_proxy
- return transparent_proxy
+ from pypymagic import tproxy
+ return tproxy
""")
More information about the Pypy-commit
mailing list