[pypy-svn] r41010 - pypy/dist/demo
hpk at codespeak.net
hpk at codespeak.net
Thu Mar 22 08:44:14 CET 2007
Author: hpk
Date: Thu Mar 22 08:44:12 2007
New Revision: 41010
Added:
pypy/dist/demo/tp-print-builtin-operation.py (contents, props changed)
Log:
add a quick demo that prints operations on builtins
Added: pypy/dist/demo/tp-print-builtin-operation.py
==============================================================================
--- (empty file)
+++ pypy/dist/demo/tp-print-builtin-operation.py Thu Mar 22 08:44:12 2007
@@ -0,0 +1,27 @@
+"""
+
+This example transparently intercepts and shows operations on
+builtin objects. It requires the "--with-transparent-proxy" option.
+
+"""
+
+from tputil import make_proxy
+from __pypy__ import become
+
+def make_show_proxy(instance):
+ def controller(operation):
+ res = operation.delegate()
+ print "proxy sees:", operation, "result=%s" %(res,)
+ return res
+ tproxy = make_proxy(controller, obj=instance)
+ return tproxy
+
+mydict = make_show_proxy({})
+
+assert type(mydict) is dict # this looks exactly like a dict
+mydict['hello'] = 'world' # will print __
+mydict[42] = 23
+assert mydict.pop('hello') == 'world'
+assert mydict.popitem() == (42,23)
+
+
More information about the Pypy-commit
mailing list