[Zope] Wrapping ZSQL method for XML-RPC access

peter sabaini sabaini@inode.at
Fri, 02 Aug 2002 20:30:45 +0200


use the magic of python, specifically the getattr() builtin :-)

ie. you'd use for example

zsql = getattr(context, 'getSalesmen')
# 'getSalesmen' could be any string you want
# now call your zsql method in the usual way
rs = zsql(param='val')
# do whatever youre going to do to your salesmen

hth
peter.

Erik Myllymaki wrote:
> So, thanks to the archives, I see that ZSQL methods need to be wrapped to
> get at them via XML-RPC. Modifying a snippet from a previous post, I got the
> following Python Script:
> 
> -------Begin script-------------------
> items=[]
> names = context.getSalesmen().names()
> for item in getSaleman():
>   new_dict = {}
>   k=0
>   while k < len(item):
>     new_dict[names[k]] = item[k]
>     k=k+1
>   items.append(new_dict)
> 
> return items
> --------End script-----------------
> 
> this gives me what I need for the "getSalesmen" ZSQL method.
> 
> But I would like to use the script with any ZSQL Method. So,  i will need to
> pass in two parameters - the first a ZSQL Method name, and the second, a
> list of parameters.
> 
> Problem is, I don't know how I would go about building and executing the
> statement:
> 
>  for item in getSalemen():
> 
> if all I have is the string "getSalesmen" ?
> 
> exec(), eval() ...
> 
> TIA
> 
> 
> _______________________________________________
> Zope maillist  -  Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://lists.zope.org/mailman/listinfo/zope-announce
>  http://lists.zope.org/mailman/listinfo/zope-dev )
> 
>