Initial import to Tizen
[profile/ivi/python-twisted.git] / doc / core / howto / tutorial / listings / finger / finger09.py
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()