MCPcopy Create free account
hub / github.com/apache/thrift / CalculatorHandler

Class CalculatorHandler

tutorial/py/PythonServer.py:38–77  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

36
37
38class CalculatorHandler:
39 def __init__(self):
40 self.log = {}
41
42 def ping(self):
43 print('ping()')
44
45 def add(self, n1, n2):
46 print('add(%d,%d)' % (n1, n2))
47 return n1 + n2
48
49 def calculate(self, logid, work):
50 print('calculate(%d, %r)' % (logid, work))
51
52 if work.op == Operation.ADD:
53 val = work.num1 + work.num2
54 elif work.op == Operation.SUBTRACT:
55 val = work.num1 - work.num2
56 elif work.op == Operation.MULTIPLY:
57 val = work.num1 * work.num2
58 elif work.op == Operation.DIVIDE:
59 if work.num2 == 0:
60 raise InvalidOperation(work.op, 'Cannot divide by 0')
61 val = work.num1 / work.num2
62 else:
63 raise InvalidOperation(work.op, 'Invalid operation')
64
65 log = SharedStruct()
66 log.key = logid
67 log.value = '%d' % (val)
68 self.log[logid] = log
69
70 return val
71
72 def getStruct(self, key):
73 print('getStruct(%d)' % (key))
74 return self.log[key]
75
76 def zip(self):
77 print('zip()')
78
79
80if __name__ == '__main__':

Callers 1

PythonServer.pyFile · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected