~certify-web-dev/twisted/certify-trunk

« back to all changes in this revision

Viewing changes to doc/core/howto/listings/TwistedQuotes/pbquoteclient.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-01-16 19:56:10 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20060116195610-ykmxbia4mnnod9o2
Tags: 2.1.0-0ubuntu2
debian/copyright: Include copyright for python 2.3; some 2.3 files
are included in the upstream tarball, but not in the binary packages.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
 
from sys import stdout
3
 
from twisted.python import log
4
 
log.discardLogs()
5
 
from twisted.internet import reactor
6
 
from twisted.spread import pb
7
 
 
8
 
def connected(root):
9
 
    root.callRemote('nextQuote').addCallbacks(success, failure)
10
 
 
11
 
def success(quote):
12
 
    stdout.write(quote + "\n")
13
 
    reactor.stop()
14
 
 
15
 
def failure(error):
16
 
    stdout.write("Failed to obtain quote.\n")
17
 
    reactor.stop()
18
 
 
19
 
factory = pb.PBClientFactory()
20
 
reactor.connectTCP(
21
 
    "localhost", # host name
22
 
    pb.portno, # port number
23
 
    factory, # factory
24
 
    )
25
 
 
26
 
 
27
 
 
28
 
factory.getRootObject().addCallbacks(connected, # when we get the root
29
 
                                     failure)   # when we can't
30
 
 
31
 
reactor.run() # start the main loop
32