[Zope3-Users] XMLRPC Method with **kwargs
Hello zope3 users! I'm using Zope-3.3.1, and I'm trying to expose a method via xmlrpc and I'm having trouble supporting a variable number of kwargs. My use case does not know ahead of time how many arguments will be passed to the method, hence the use of **kwargs in the method signature. I get the error: Unexpected Zope exception: TypeError: renderCode() takes at most 1 argument (2 given). The interface/class definitions with the method to be exposed are straight-forward: class IToolCode(IFolder): Code that is associated with a tool. code = Text( title=u'Code', description=u'The code.', required=True, ) def renderCode(): Use customization options posted via XMLRPC and ZPT to render customized code. class ToolCode(Folder): See IToolCode. implements(IToolCode) code = FieldProperty(IToolCode['code']) def renderCode(self, **kwargs): pt = PageTemplate() pt.write(self.code) return pt(customizations=kwargs) The XMLRPC view uses zope.app.publisher.xmlrpc.MethodPublisher and is simple: class ToolCodeXMLRPC(MethodPublisher): An XMLRPC view for ToolCode objects. def renderCode(self, **kwargs): return self.context.renderCode(kwargs) The XMLRPC view is configured like so: xmlrpc:view for=src.interfaces.IToolCode methods=renderCode class=src.browser.views.ToolCodeXMLRPC permission=src.ViewProtected / The XML posted by my JavaScript also seems to be appropriate: ?xml version=1.0? methodCall methodNamerenderCode/methodName params param value struct membernamecolor/namevaluestringblue/string/value/member membernamenumber/namevaluestring1/string/value/member /struct /value /param /params /methodCall I'm at a loss for what I am missing. Has anyone successfully exposed a method via XMLRPC that used **kwargs? Thanks for any advice! -Jer ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] XMLRPC Method with **kwargs
Darryl Cousins wrote: Hi Jeremy, On Thu, 2007-12-13 at 19:29 -0500, Jeremy Roberts wrote: class ToolCodeXMLRPC(MethodPublisher): An XMLRPC view for ToolCode objects. def renderCode(self, **kwargs): return self.context.renderCode(kwargs) try using: def renderCode(self, **kwargs): return self.context.renderCode(**kwargs) # !! Regards, Darryl Hey Darryl, Thanks for the suggestion. I tried the above edit (instructing python to unpack the kwargs dictionary back into keyword arguments with the ** operator) to no avail. With this edit in place, I still get the same error: Unexpected Zope exception: TypeError: renderCode() takes at most 1 argument (2 given) I'm going to poke around the Zope3 zope.publisher.xmlrpc to see if I can gain any insight by finding the code that raises this exception. If I find anything useful I'll post back to the list... Thanks! -Jer ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users
Re: [Zope3-Users] XMLRPC Method with **kwargs
Am 14.12.2007 um 01:29 schrieb Jeremy Roberts: Hello zope3 users! I'm using Zope-3.3.1, and I'm trying to expose a method via xmlrpc and I'm having trouble supporting a variable number of kwargs. My use case does not know ahead of time how many arguments will be passed to the method, hence the use of **kwargs in the method signature. I get the error: Unexpected Zope exception: TypeError: renderCode() takes at most 1 argument (2 given). Hi! I think this is because XML-RPC does not support (optional) keyword arguments, you only may use positional arguments. A solution for optional arguments can be a dictionary containing the optional arguments for your XML-RPC-View as the last parameter. But this parameter is not optional itself. So your view could look like: class ToolCodeXMLRPC(MethodPublisher): An XMLRPC view for ToolCode objects. def renderCode(self, data): return self.context.renderCode(**data) -- Yours sincerely, Michael Howitz gocept gmbh co. kg · forsterstrasse 29 · 06112 halle/saale www.gocept.com · fon: +49 345 12298898 · fax: +49 345 12298891 ___ Zope3-users mailing list Zope3-users@zope.org http://mail.zope.org/mailman/listinfo/zope3-users