From a3dac1b67541388e45d5702bd566db347b111c51 Mon Sep 17 00:00:00 2001 From: helmutm Date: Mon, 27 Aug 2007 19:33:26 +0000 Subject: [PATCH] proof-of-concept for a simple AOP implementation git-svn-id: svn://svn.cy55.de/Zope3/src/cybertools/trunk@1967 fd906abe-77d9-0310-91a1-e0d9ade77398 --- util/aop.py | 11 ++++++++++- util/aop.txt | 4 ++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/util/aop.py b/util/aop.py index a66a1f6..7c160ee 100644 --- a/util/aop.py +++ b/util/aop.py @@ -24,8 +24,17 @@ $Id$ def getNotifier(method): - if isinstance(method, Notifier): + if isinstance(method, (Notifier, BoundNotifier)): return method + if method.im_self is not None: + name = method.im_func.func_name + classMethod = getattr(method.im_class, name) + if not isinstance(classMethod, Notifier): + classMethod = Notifier(classMethod) + setattr(method.im_class, name, classMethod) + notifier = BoundNotifier(classMethod, method.im_self) + setattr(method.im_self, name, notifier) + return notifier return Notifier(method) diff --git a/util/aop.txt b/util/aop.txt index 562faaa..5c05061 100644 --- a/util/aop.txt +++ b/util/aop.txt @@ -84,3 +84,7 @@ Combining class and instance level wrapping logging: after foo, result=48 48 +TODO: check case where instance is wrapped first, then class - +that means: always wrap class when wrapping an instance, and always +wrap instance with BoundNotifier. +