diff MoinMoin/wikiutil.py @ 2557:cc5a81bda460

allow the invoke_extension_function to invoke constructors too
author Johannes Berg <johannes AT sipsolutions DOT net>
date Wed, 25 Jul 2007 10:49:36 +0200
parents 2523642e9516
children fb05ca2c0bdc
line wrap: on
line diff
--- a/MoinMoin/wikiutil.py	Tue Jul 24 17:30:40 2007 +0200
+++ b/MoinMoin/wikiutil.py	Wed Jul 25 10:49:36 2007 +0200
@@ -19,8 +19,7 @@
 
 from MoinMoin import config
 from MoinMoin.util import pysupport, lock
-from inspect import getargspec
-from types import MethodType
+from inspect import getargspec, isfunction, isclass, ismethod
 
 
 # Exceptions
@@ -1573,10 +1572,18 @@
     else:
         positional = []
 
-    argnames, varargs, varkw, defaultlist = getargspec(function)
+    if isfunction(function) or ismethod(function):
+        argnames, varargs, varkw, defaultlist = getargspec(function)
+    elif isclass(function):
+        (argnames, varargs,
+         varkw, defaultlist) = getargspec(function.__init__.im_func)
+    else:
+        raise TypeError('function must be a function, method or class')
+
     # self is implicit!
-    if isinstance(function, MethodType):
+    if ismethod(function) or isclass(function):
         argnames = argnames[1:]
+
     fixed_argc = len(fixed_args)
     argnames = argnames[fixed_argc:]
     argc = len(argnames)