[Zope3-Users] XMLRPC Method with **kwargs

Jeremy Roberts jerbear at incrediblepear.com
Thu Dec 13 19:29:29 EST 2007


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>
<methodName>renderCode</methodName>
<params>

<param>
<value>
<struct>
<member><name>color</name><value><string>blue</string></value></member>
<member><name>number</name><value><string>1</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


More information about the Zope3-users mailing list