X-Git-Url: http://git.tremily.us/?p=hooke.git;a=blobdiff_plain;f=hooke%2Futil%2Fcallback.py;h=0e76e815001cc1026784ca071850645a90f5489b;hp=ec7895c6569c48fa63148ec0a4b3dd1336231d8b;hb=06dd575fc4ec14c30f6c7ed2d3c9268c7387509b;hpb=246feda8324f79709af3aa2619ae15844c80fa3d diff --git a/hooke/util/callback.py b/hooke/util/callback.py index ec7895c..0e76e81 100644 --- a/hooke/util/callback.py +++ b/hooke/util/callback.py @@ -1,10 +1,28 @@ -# Copyright +# Copyright (C) 2010 W. Trevor King +# +# This file is part of Hooke. +# +# Hooke is free software: you can redistribute it and/or modify it +# under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# Hooke is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General +# Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public +# License along with Hooke. If not, see +# . """Define the `@callback` decorator. See :pep:`318` for an introduction to decorators. """ +import logging + from .caller import caller_name @@ -123,12 +141,14 @@ def callback(method): def new_m(self, *args, **kwargs): result = method(self, *args, **kwargs) callback = self._callbacks.get(method.func_name, None) - nm = getattr(self, method.func_name) + mn = getattr(self, method.func_name) + log = logging.getLogger('hooke') + log.debug('callback: %s (%s) calling %s' % (method.func_name, mn, callback)) if is_iterable(callback): for cb in callback: - cb(self, nm, result) + cb(self, mn, result) elif callback != None: - callback(self, nm, result) + callback(self, mn, result) return result new_m.func_name = method.func_name new_m.func_doc = method.func_doc @@ -222,9 +242,11 @@ def in_callback(self, *args, **kwargs): """ method_name = caller_name(depth=2) callback = self._callbacks.get(method_name, None) - nm = getattr(self, method_name) + mn = getattr(self, method_name) + log = logging.getLogger('hooke') + log.debug('callback: %s (%s) calling %s' % (method_name, mn, callback)) if is_iterable(callback): for cb in callback: - cb(self, nm, *args, **kwargs) + cb(self, mn, *args, **kwargs) elif callback != None: - callback(self, nm, *args, **kwargs) + callback(self, mn, *args, **kwargs)