Sophie

Sophie

distrib > Mageia > 1 > i586 > by-pkgid > 22e60e8a385ab7f1c7f2eb7eb45c6aef > files > 194

python-foolscap-0.6.1-2.mga1.noarch.rpm

#! /usr/bin/python

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

# the receiving side defines the RemoteCopy
class RemoteUserRecord(RemoteCopy):
    copytype = "unique-string-UserRecord" # this matches the sender

    def __init__(self):
        # note: our __init__ must take no arguments
        pass

    def setCopyableState(self, d):
        self.name = d['name']
        self.age = d['age']
        self.shoe_size = "they wouldn't tell us"

    def display(self):
        print "Name:", self.name
        print "Age:", self.age
        print "Shoe Size:", self.shoe_size

def getRecord(rref, name):
    d = rref.callRemote("getuser", name=name)
    def _gotRecord(r):
        # r is an instance of RemoteUserRecord
        r.display()
        reactor.stop()
    d.addCallback(_gotRecord)


from foolscap.api import Tub
tub = Tub()
tub.startService()

d = tub.getReference(sys.argv[1])
d.addCallback(getRecord, "alice")

reactor.run()