Hello, I have tried call a function via XMLRPC with * and ** args with no success! The following error have appeared: ------------------------------------------------ Unexpected Zope error value: Traceback (most recent call last): File "/home/catunda/projetos/zope/cvs/zope/lib/python/ZPublisher/Publish.py", line 150, in publish_module response = publish(request, module_name, after_list, debug=debug) File "/home/catunda/projetos/zope/cvs/zope/lib/python/ZPublisher/Publish.py", line 114, in publish sys.exc_info()[2], File "/home/catunda/projetos/zope/cvs/zope/lib/python/ZPublisher/Publish.py", line 98, in publish request, bind=1) File "/home/catunda/projetos/zope/cvs/zope/lib/python/ZPublisher/mapply.py", line 71, in mapply if len(positional) > nargs: raise TypeError, 'too many arguments' TypeError: too many arguments ------------------------------------------------ I don't know if it's a bug but I debugged zope and changed some things in mapply.py. The idea of this changes is test if a function has *,** args or not using inspect module. I don't know if this changes will affect other things in zope. Follow the patch of changes. --- mapply.py 2003-03-17 19:30:12.000000000 -0300 +++ mapply.py.new 2003-03-17 18:59:54.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,28 @@ 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] + #c=f.func_code + #names=c.co_varnames[:c.co_argcount] + spec=inspect.getargspec(f) + names=spec[0] + defaults=spec[3] + vargs=spec[1:3] 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': -- Marco Catunda
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':
Marco Catunda wrote at 2003-3-17 19:39 -0300:
I have tried call a function via XMLRPC with * and ** args with no success!
XMLRPC is a cross language technology. It does not support Python specialities such as "*" and "**" arguments. Dieter
Dieter, Ok. But I was talking only about implementation of server side function and, I think, it is possible use python specialities without desagree XMLRPC cross language technology. In this case, only '*' arguments. If I make a call like Foo( 1, 2 ) The server side implementation could be def Foo( a, b ) or def Foo( *a ) I developed some kind of proxy function using '*' arguments and Acquisition. -- Marco Catunda On Tue, 2003-03-18 at 18:48, Dieter Maurer wrote:
Marco Catunda wrote at 2003-3-17 19:39 -0300:
I have tried call a function via XMLRPC with * and ** args with no success!
XMLRPC is a cross language technology.
It does not support Python specialities such as "*" and "**" arguments.
Dieter
_______________________________________________ Zope-Dev maillist - Zope-Dev@zope.org http://mail.zope.org/mailman/listinfo/zope-dev ** No cross posts or HTML encoding! ** (Related lists - http://mail.zope.org/mailman/listinfo/zope-announce http://mail.zope.org/mailman/listinfo/zope )
But I was talking only about implementation of server side function and, I think, it is possible use python specialities without desagree XMLRPC cross language technology. In this case, only '*' arguments.
If I make a call like Foo( 1, 2 )
The server side implementation could be
def Foo( a, b )
or
def Foo( *a )
I think that is a valid point. However I would enter a bug into the collector and add the patch there. Otherwise it will get lost in the traffic that is the mailing list and no action will happen. Thanks -- Andy McKay
participants (3)
-
Andy McKay -
Dieter Maurer -
Marco Catunda