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

Method calculate

tutorial/py/PythonServer.py:49–70  ·  view source on GitHub ↗
(self, logid, work)

Source from the content-addressed store, hash-verified

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))

Callers 1

mainFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected