Sophie

Sophie

distrib > Fedora > 13 > i386 > media > updates > by-pkgid > 8e2794c56d40434f013b2f4bb2904b31 > files > 296

python-foolscap-0.5.1-1.fc13.noarch.rpm

#! /usr/bin/python

import sys
from twisted.internet import reactor
from foolscap.api import Tub

def gotError1(why):
    print "unable to get the RemoteReference:", why
    reactor.stop()

def gotError2(why):
    print "unable to invoke the remote method:", why
    reactor.stop()

def gotReference(remote):
    print "got a RemoteReference"
    print "asking it to add 1+2"
    d = remote.callRemote("add", a=1, b=2)
    d.addCallbacks(gotAnswer, gotError2)

def gotAnswer(answer):
    print "the answer is", answer
    reactor.stop()

if len(sys.argv) < 2:
    print "Usage: pb2client.py URL"
    sys.exit(1)
url = sys.argv[1]
tub = Tub()
tub.startService()
d = tub.getReference(url)
d.addCallbacks(gotReference, gotError1)

reactor.run()