changeset 10:a3599e4db9a4

python 2.4 compatability
author Jeff Hammel <jhammel@mozilla.com>
date Mon, 02 Apr 2012 10:21:59 -0700
parents 0069096e8e22
children 03db23600c1f
files commandparser/command.py
diffstat 1 files changed, 9 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/commandparser/command.py	Fri Mar 30 16:45:50 2012 -0700
+++ b/commandparser/command.py	Mon Apr 02 10:21:59 2012 -0700
@@ -13,6 +13,9 @@
 except ImportError:
     import simplejson as json
 
+# BBB python 2.4
+cleandoc = getattr(inspect, 'cleandoc', lambda x: x.strip())
+
 __all__ = ['Undefined', 'CommandParser']
 
 class Undefined(object):
@@ -159,22 +162,21 @@
     def command(self, function):
         name = function.func_name
         if function.__doc__:
-            doc = inspect.cleandoc(function.__doc__)
+            doc = cleandoc(function.__doc__)
         else:
             doc = ''
-        argspec = inspect.getargspec(function)
-        defaults = argspec.defaults
+        args, varargs, varkw, defaults = inspect.getargspec(function)
         if defaults:
-            args = argspec.args[1:-len(defaults)]
-            optional = dict(zip(argspec.args[-len(defaults):], defaults))
+            args = args[1:-len(defaults)]
+            optional = dict(zip(args[-len(defaults):], defaults))
         else:
-            args = argspec.args[1:]
+            args = args[1:]
             optional = None
         command = {'doc': doc,
                    'name': name,
                    'args': args,
                    'optional': optional,
-                   'varargs': argspec.varargs
+                   'varargs': varargs
                    }
         return command