~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/tutorial/listings/finger/finger10.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
# Read username, output from factory interfacing to web, drop connections
 
2
 
 
3
from twisted.internet import protocol, reactor, defer, utils
 
4
from twisted.protocols import basic
 
5
from twisted.web import client
 
6
 
 
7
class FingerProtocol(basic.LineReceiver):
 
8
    def lineReceived(self, user):
 
9
        d = self.factory.getUser(user)
 
10
 
 
11
        def onError(err):
 
12
            return 'Internal error in server'
 
13
        d.addErrback(onError)
 
14
 
 
15
        def writeResponse(message):
 
16
            self.transport.write(message + '\r\n')
 
17
            self.transport.loseConnection()
 
18
        d.addCallback(writeResponse)
 
19
 
 
20
class FingerFactory(protocol.ServerFactory):
 
21
    protocol = FingerProtocol
 
22
    
 
23
    def __init__(self, prefix):
 
24
        self.prefix=prefix
 
25
    
 
26
    def getUser(self, user):
 
27
        return client.getPage(self.prefix+user)
 
28
 
 
29
reactor.listenTCP(1079, FingerFactory(prefix='http://livejournal.com/~'))
 
30
reactor.run()