[Zope] XML-RPC, ZSQL, and Python-Scripts - an example
Steve Drees
drees@the-bridge.net
Thu, 24 May 2001 10:50:39 -0500
Following up to my own post Re: XML-RPC marshalling.
First the givens.
ZSQL Method: view_sql
#
# Schema (Postgres)
# entry_title varchar
# entry_username varchar
# entry_body varchar
# entry_timestamp timestamp
#
<params></params>
select
*
from
weblog
where
entry_username ='steve'
order by
entry_timestamp desc
## Script (Python) "view"
##bind container=container
##bind context=context
##bind namespace=
##bind script=script
##bind subpath=traverse_subpath
##parameters=
##title=
##
items=[]
for item in context.view_sql():
new_dict = {'title':item.entry_title,
'username':item.entry_username,
'body':item.entry_body,
'timestamp':item.entry_timestamp}
items.append(new_dict)
return items
--------------------------------------------------------
[drees@gfa drees]$ python
Python 1.5.2 (#1, Dec 21 2000, 15:29:08) [GCC egcs-2.91.66 19990314/Linux
(egcs- on linux-i386
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import xmlrpclib
>>> s=xmlrpclib.Server('http://somedomain.com')
>>> for i in s.view():
... print i['title'], i['timestamp']
... print i['body']
...
<output snipped> you get the idea from here...
--
Steve Drees
SysAdmin/Software Developer/Web Geek/Chief Bottle Washer
"A problem well-stated is a problem half-solved."
http://stve.wejustrock.com