[Zope-dev] XMLRPC with varargs
Marco Catunda
catunda@embratel.net.br
17 Mar 2003 20:22:04 -0300
Hello,
Sorry, I made mistake on last patch...
I am sending the correct one
--- mapply.py 2003-03-17 20:11:23.000000000 -0300
+++ mapply.py.new 2003-03-17 20:11:16.000000000 -0300
@@ -13,6 +13,8 @@
"""Provide an apply-like facility that works with any mapping object
"""
+import inspect
+
def default_call_object(object, args, context):
result=apply(object,args) # Type s<cr> to step into published object.
return result
@@ -23,11 +25,15 @@
def default_handle_class(klass, context):
if hasattr(klass,'__init__'):
f=klass.__init__.im_func
- c=f.func_code
- names=c.co_varnames[1:c.co_argcount]
- return klass, names, f.func_defaults
+ #c=f.func_code
+ #names=c.co_varnames[1:c.co_argcount]
+ spec=inpect.getargspec(f)
+ names=spec[0][1:]
+ defaults=spec[3]
+ vargs=spec[1:3]
+ return klass, names, defaults, vargs
else:
- return klass, (), ()
+ return klass, (), (), []
def mapply(object, positional=(), keyword={},
debug=None, maybe=None,
@@ -37,7 +43,7 @@
):
if hasattr(object,'__bases__'):
- f, names, defaults = handle_class(object, context)
+ f, names, defaults, vargs = handle_class(object, context)
else:
f=object
im=0
@@ -53,20 +59,25 @@
if im:
f=f.im_func
- c=f.func_code
- defaults=f.func_defaults
- names=c.co_varnames[1:c.co_argcount]
+ #c=f.func_code
+ #defaults=f.func_defaults
+ #names=c.co_varnames[1:c.co_argcount]
+ spec=inspect.getargspec(f)
+ names=spec[0][1:]
+ defaults=spec[3]
+ vargs=spec[1:3]
else:
defaults=f.func_defaults
c=f.func_code
names=c.co_varnames[:c.co_argcount]
+ vargs=None
nargs=len(names)
if positional:
positional=list(positional)
if bind and nargs and names[0]=='self':
positional.insert(0, missing_name('self', context))
- if len(positional) > nargs: raise TypeError, 'too many arguments'
+ if (len(positional) > nargs) and not vargs: raise TypeError, 'too many arguments'
args=positional
else:
if bind and nargs and names[0]=='self':