diff --git a/src/commands.py b/src/commands.py index 309a5e4f9..0940befd0 100644 --- a/src/commands.py +++ b/src/commands.py @@ -64,7 +64,7 @@ def thread(f): t.start() else: f(self, irc, msg, args, *L, **kwargs) - return utils.changeFunctionName(newf, f.func_name, f.__doc__) + return utils.python.changeFunctionName(newf, f.func_name, f.__doc__) class UrlSnarfThread(world.SupyThread): def __init__(self, *args, **kwargs): @@ -132,7 +132,7 @@ def urlSnarfer(f): L = list(L) t = UrlSnarfThread(target=doSnarf, url=url) t.start() - newf = utils.changeFunctionName(newf, f.func_name, f.__doc__) + newf = utils.python.changeFunctionName(newf, f.func_name, f.__doc__) return newf @@ -878,6 +878,7 @@ class Spec(object): return state def wrap(f, specList=[], name=None, **kw): + name = name or f.func_name spec = Spec(specList, **kw) def newf(self, irc, msg, args, **kwargs): state = spec(irc, msg, args, stateAttrs={'cb': self, 'log': self.log}) @@ -890,7 +891,7 @@ def wrap(f, specList=[], name=None, **kw): funcArgs = inspect.getargs(f.func_code)[0][len(self.commandArgs):] self.log.error('Extra args: %s', funcArgs) raise - return utils.changeFunctionName(newf, name or f.func_name, f.__doc__) + return utils.python.changeFunctionName(newf, name, f.__doc__) __all__ = [ # Contexts. diff --git a/src/log.py b/src/log.py index baaf9afae..6ecf9079b 100644 --- a/src/log.py +++ b/src/log.py @@ -325,7 +325,7 @@ def firewall(f, errorHandler=None): except Exception, e: logException(self, 'Uncaught exception in errorHandler') - m = utils.gen.changeFunctionName(m, f.func_name, f.__doc__) + m = utils.python.changeFunctionName(m, f.func_name, f.__doc__) return m class MetaFirewall(type): diff --git a/src/test.py b/src/test.py index 6218d4cc0..674b3e3ce 100644 --- a/src/test.py +++ b/src/test.py @@ -128,7 +128,7 @@ class PluginTestCase(SupyTestCase): run = False if run: originalRunTest() - runTest = utils.changeFunctionName(runTest, methodName) + runTest = utils.python.changeFunctionName(runTest, methodName) setattr(self.__class__, methodName, runTest) SupyTestCase.__init__(self, methodName=methodName) self.originals = {} diff --git a/src/utils/gen.py b/src/utils/gen.py index 52b8bf2cd..ae9093cdd 100644 --- a/src/utils/gen.py +++ b/src/utils/gen.py @@ -218,14 +218,6 @@ class IterableMap(object): return False -def changeFunctionName(f, name, doc=None): - if doc is None: - doc = f.__doc__ - newf = types.FunctionType(f.func_code, f.func_globals, name, - f.func_defaults, f.func_closure) - newf.__doc__ = doc - return newf - class InsensitivePreservingDict(UserDict.DictMixin, object): def key(self, s): """Override this if you wish.""" diff --git a/src/utils/python.py b/src/utils/python.py index 3ed20059b..2f272e58a 100644 --- a/src/utils/python.py +++ b/src/utils/python.py @@ -27,6 +27,16 @@ # POSSIBILITY OF SUCH DAMAGE. ### +import types + +def changeFunctionName(f, name, doc=None): + if doc is None: + doc = f.__doc__ + newf = types.FunctionType(f.func_code, f.func_globals, name, + f.func_defaults, f.func_closure) + newf.__doc__ = doc + return newf + class Object(object): def __ne__(self, other): return not self == other