1 # -*- test-case-name: calculus.test.test_remote_1 -*-
3 from twisted.protocols import basic
4 from twisted.internet import protocol
5 from twisted.python import log
6 from calculus.base_3 import Calculation
10 class CalculationProxy(object):
12 self.calc = Calculation()
13 for m in ['add', 'subtract', 'multiply', 'divide']:
14 setattr(self, 'remote_%s' % m, getattr(self.calc, m))
18 class RemoteCalculationProtocol(basic.LineReceiver):
20 self.proxy = CalculationProxy()
23 def lineReceived(self, line):
24 op, a, b = line.split()
25 op = getattr(self.proxy, 'remote_%s' % (op,))
30 self.sendLine("error")
32 self.sendLine(str(result))
36 class RemoteCalculationFactory(protocol.Factory):
37 protocol = RemoteCalculationProtocol
42 from twisted.internet import reactor
43 from twisted.python import log
45 log.startLogging(sys.stdout)
46 reactor.listenTCP(0, RemoteCalculationFactory())
50 if __name__ == "__main__":