1 from twisted.protocols import amp
3 class Sum(amp.Command):
4 arguments = [('a', amp.Integer()),
6 response = [('total', amp.Integer())]
9 class Divide(amp.Command):
10 arguments = [('numerator', amp.Integer()),
11 ('denominator', amp.Integer())]
12 response = [('result', amp.Float())]
13 errors = {ZeroDivisionError: 'ZERO_DIVISION'}
19 print 'Did a sum: %d + %d = %d' % (a, b, total)
20 return {'total': total}
23 def divide(self, numerator, denominator):
24 result = float(numerator) / denominator
25 print 'Divided: %d / %d = %f' % (numerator, denominator, result)
26 return {'result': result}
27 Divide.responder(divide)
31 from twisted.internet import reactor
32 from twisted.internet.protocol import Factory
35 reactor.listenTCP(1234, pf)
39 if __name__ == '__main__':