diff options
Diffstat (limited to 'doc/core/howto/listings/pb/copy_sender.py')
-rwxr-xr-x | doc/core/howto/listings/pb/copy_sender.py | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/doc/core/howto/listings/pb/copy_sender.py b/doc/core/howto/listings/pb/copy_sender.py new file mode 100755 index 0000000..fca0594 --- /dev/null +++ b/doc/core/howto/listings/pb/copy_sender.py @@ -0,0 +1,57 @@ +#!/usr/bin/env python + +# Copyright (c) Twisted Matrix Laboratories. +# See LICENSE for details. + +from twisted.spread import pb, jelly +from twisted.python import log +from twisted.internet import reactor + +class LilyPond: + def setStuff(self, color, numFrogs): + self.color = color + self.numFrogs = numFrogs + def countFrogs(self): + print "%d frogs" % self.numFrogs + +class CopyPond(LilyPond, pb.Copyable): + pass + +class Sender: + def __init__(self, pond): + self.pond = pond + + def got_obj(self, remote): + self.remote = remote + d = remote.callRemote("takePond", self.pond) + d.addCallback(self.ok).addErrback(self.notOk) + + def ok(self, response): + print "pond arrived", response + reactor.stop() + def notOk(self, failure): + print "error during takePond:" + if failure.type == jelly.InsecureJelly: + print " InsecureJelly" + else: + print failure + reactor.stop() + return None + +def main(): + from copy_sender import CopyPond # so it's not __main__.CopyPond + pond = CopyPond() + pond.setStuff("green", 7) + pond.countFrogs() + # class name: + print ".".join([pond.__class__.__module__, pond.__class__.__name__]) + + sender = Sender(pond) + factory = pb.PBClientFactory() + reactor.connectTCP("localhost", 8800, factory) + deferred = factory.getRootObject() + deferred.addCallback(sender.got_obj) + reactor.run() + +if __name__ == '__main__': + main() |