summaryrefslogtreecommitdiffstats
path: root/Demo/metaclasses/Trace.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>1997-08-25 15:37:59 (GMT)
committerGuido van Rossum <guido@python.org>1997-08-25 15:37:59 (GMT)
commit27e4aa316875b1e5ad7fd85f93707ddf4fdba063 (patch)
tree17c0e25dbcec051797235ca89bc7e0f5c3e486ee /Demo/metaclasses/Trace.py
parentbff110f3f10027cf03457556e42af2d3d87d5e7f (diff)
downloadcpython-27e4aa316875b1e5ad7fd85f93707ddf4fdba063.zip
cpython-27e4aa316875b1e5ad7fd85f93707ddf4fdba063.tar.gz
cpython-27e4aa316875b1e5ad7fd85f93707ddf4fdba063.tar.bz2
Arbitrary point checkpoint commit. Take no notice.
Diffstat (limited to 'Demo/metaclasses/Trace.py')
-rw-r--r--Demo/metaclasses/Trace.py29
1 files changed, 24 insertions, 5 deletions
diff --git a/Demo/metaclasses/Trace.py b/Demo/metaclasses/Trace.py
index ed3944f..a5b765a 100644
--- a/Demo/metaclasses/Trace.py
+++ b/Demo/metaclasses/Trace.py
@@ -1,6 +1,10 @@
-"""Tracing metaclass."""
+"""Tracing metaclass.
-import types
+XXX This is very much a work in progress.
+
+"""
+
+import types, sys
class TraceMetaClass:
"""Metaclass for tracing.
@@ -28,7 +32,7 @@ class TraceMetaClass:
except KeyError:
for base in self.__bases__:
try:
- return getattr(base, name)
+ return base.__getattr__(name)
except AttributeError:
pass
raise AttributeError, name
@@ -106,12 +110,15 @@ Traced = TraceMetaClass('Traced', (), {'__trace_output__': None})
def _test():
- import sys
+ global C, D
class C(Traced):
def __init__(self, x=0): self.x = x
def m1(self, x): self.x = x
def m2(self, y): return self.x + y
- C.__trace_output__ = sys.stdout
+ __trace_output__ = sys.stdout
+ class D(C):
+ def m2(self, y): print "D.m2(%s)" % `y`; return C.m2(self, y)
+ __trace_output__ = None
x = C(4321)
print x
print x.x
@@ -122,5 +129,17 @@ def _test():
print x.m2(4000)
print x.x
+ print C.__init__
+ print C.m2
+ print D.__init__
+ print D.m2
+
+ y = D()
+ print y
+ print y.m1(10)
+ print y.m2(100)
+ print y.x
+
if __name__ == '__main__':
_test()
+