#inside $ZOPE/Extensions
#create a file, xmlrpc_example.py
from xmlrpclib import Server
def getStateNameByNumber(number=1):
""" python lib example """
# simple test program (from the XML-RPC specification)
# server = Server("http://localhost:8000") # local server
server = Server("http://betty.userland.com")
try:
return server.examples.getStateName(number)
except Error, v:
raise v
#inside ZOPE create a External Method:
#id: getStateName
#module: xmlrpc_example
#function: getStateNameByNumber
#then you can test that or call it from a Pagetemplate:
<span tal:define="stateNumber python:33">
The #<span tal:replace="stateNumber"/> is
<span tal:replace="python:here.getStateName(stateNumber)" />
</span>
Explanation:
this is taken from Python library reference and modified (put into a function)
and then a external method in teh ZODB was created to call it. now you
can just 'test' the external method or call it.
Comments:
fix for call to External Method by tlynch@nal - 2004-10-14
I got this example to work by adding "here." to the line that
calls the external method:
<span tal:replace="python:here.getStateName(stateNumber)" />
credit to Chris Beaven for figuring this out
tlynch@nal
Re: fix for call to External Method by runyaga - 2004-10-14