~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/pb2client.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
 
7
from twisted.internet import reactor
 
8
 
 
9
def main():
 
10
    foo = Foo()
 
11
    factory = pb.PBClientFactory()
 
12
    reactor.connectTCP("localhost", 8800, factory)
 
13
    factory.getRootObject().addCallback(foo.step1)
 
14
    reactor.run()
 
15
 
 
16
# keeping globals around is starting to get ugly, so we use a simple class
 
17
# instead. Instead of hooking one function to the next, we hook one method
 
18
# to the next.
 
19
 
 
20
class Foo:
 
21
    def __init__(self):
 
22
        self.oneRef = None
 
23
 
 
24
    def step1(self, obj):
 
25
        print "got one object:", obj
 
26
        self.oneRef = obj
 
27
        print "asking it to getTwo"
 
28
        self.oneRef.callRemote("getTwo").addCallback(self.step2)
 
29
 
 
30
    def step2(self, two):
 
31
        print "got two object:", two
 
32
        print "giving it back to one"
 
33
        print "one is", self.oneRef
 
34
        self.oneRef.callRemote("checkTwo", two)
 
35
 
 
36
main()