~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/finger09.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 OS, drop connections
 
2
 
 
3
from twisted.internet import protocol, reactor, defer, utils
 
4
from twisted.protocols import basic
 
5
 
 
6
class FingerProtocol(basic.LineReceiver):
 
7
    def lineReceived(self, user):
 
8
        d = self.factory.getUser(user)
 
9
 
 
10
        def onError(err):
 
11
            return 'Internal error in server'
 
12
        d.addErrback(onError)
 
13
 
 
14
        def writeResponse(message):
 
15
            self.transport.write(message + '\r\n')
 
16
            self.transport.loseConnection()
 
17
        d.addCallback(writeResponse)
 
18
 
 
19
class FingerFactory(protocol.ServerFactory):
 
20
    protocol = FingerProtocol
 
21
 
 
22
    def getUser(self, user):
 
23
        return utils.getProcessOutput("finger", [user])
 
24
 
 
25
reactor.listenTCP(1079, FingerFactory())
 
26
reactor.run()