~ntt-pf-lab/nova/monkey_patch_notification

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/howto/listings/pb/copy_sender.py

  • Committer: Jesse Andrews
  • Date: 2010-05-28 06:05:26 UTC
  • Revision ID: git-v1:bf6e6e718cdc7488e2da87b21e258ccc065fe499
initial commit

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
# Copyright (c) 2009 Twisted Matrix Laboratories.
 
4
# See LICENSE for details.
 
5
 
 
6
from twisted.spread import pb, jelly
 
7
from twisted.python import log
 
8
from twisted.internet import reactor
 
9
 
 
10
class LilyPond:
 
11
    def setStuff(self, color, numFrogs):
 
12
        self.color = color
 
13
        self.numFrogs = numFrogs
 
14
    def countFrogs(self):
 
15
        print "%d frogs" % self.numFrogs
 
16
 
 
17
class CopyPond(LilyPond, pb.Copyable):
 
18
    pass
 
19
 
 
20
class Sender:
 
21
    def __init__(self, pond):
 
22
        self.pond = pond
 
23
 
 
24
    def got_obj(self, remote):
 
25
        self.remote = remote
 
26
        d = remote.callRemote("takePond", self.pond)
 
27
        d.addCallback(self.ok).addErrback(self.notOk)
 
28
 
 
29
    def ok(self, response):
 
30
        print "pond arrived", response
 
31
        reactor.stop()
 
32
    def notOk(self, failure):
 
33
        print "error during takePond:"
 
34
        if failure.type == jelly.InsecureJelly:
 
35
            print " InsecureJelly"
 
36
        else:
 
37
            print failure
 
38
        reactor.stop()
 
39
        return None
 
40
 
 
41
def main():
 
42
    from copy_sender import CopyPond  # so it's not __main__.CopyPond
 
43
    pond = CopyPond()
 
44
    pond.setStuff("green", 7)
 
45
    pond.countFrogs()
 
46
    # class name:
 
47
    print ".".join([pond.__class__.__module__, pond.__class__.__name__])
 
48
 
 
49
    sender = Sender(pond)
 
50
    factory = pb.PBClientFactory()
 
51
    reactor.connectTCP("localhost", 8800, factory)
 
52
    deferred = factory.getRootObject()
 
53
    deferred.addCallback(sender.got_obj)
 
54
    reactor.run()
 
55
 
 
56
if __name__ == '__main__':
 
57
    main()