quick search:
 

Make XMLRPC Calls From ZOPE

Submitted by: runyaga
Last Edited: 2004-10-14

Category: Python(External Method)

Average rating is: 4.5 out of 5 (2 ratings)

Description:
if you want to use any python libraries, or xmlrpclib you can do this from python external methods. this is very simple.

Source (Text):
#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
fixed thanks