~justin-fathomdb/nova/justinsb-openstack-api-volumes

« back to all changes in this revision

Viewing changes to vendor/Twisted-10.0.0/doc/core/howto/listings/pb/copy2_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
from copy2_classes import SenderPond
 
10
 
 
11
class Sender:
 
12
    def __init__(self, pond):
 
13
        self.pond = pond
 
14
 
 
15
    def got_obj(self, obj):
 
16
        d = obj.callRemote("takePond", self.pond)
 
17
        d.addCallback(self.ok).addErrback(self.notOk)
 
18
 
 
19
    def ok(self, response):
 
20
        print "pond arrived", response
 
21
        reactor.stop()
 
22
    def notOk(self, failure):
 
23
        print "error during takePond:"
 
24
        if failure.type == jelly.InsecureJelly:
 
25
            print " InsecureJelly"
 
26
        else:
 
27
            print failure
 
28
        reactor.stop()
 
29
        return None
 
30
 
 
31
def main():
 
32
    pond = SenderPond(3, 4)
 
33
    print "count %d" % pond.count()
 
34
 
 
35
    sender = Sender(pond)
 
36
    factory = pb.PBClientFactory()
 
37
    reactor.connectTCP("localhost", 8800, factory)
 
38
    deferred = factory.getRootObject()
 
39
    deferred.addCallback(sender.got_obj)
 
40
    reactor.run()
 
41
 
 
42
if __name__ == '__main__':
 
43
    main()
 
44