]>
git.proxmox.com Git - ceph.git/blob - ceph/src/jaegertracing/thrift/tutorial/py.twisted/PythonClient.py
4 # Licensed to the Apache Software Foundation (ASF) under one
5 # or more contributor license agreements. See the NOTICE file
6 # distributed with this work for additional information
7 # regarding copyright ownership. The ASF licenses this file
8 # to you under the Apache License, Version 2.0 (the
9 # "License"); you may not use this file except in compliance
10 # with the License. You may obtain a copy of the License at
12 # http://www.apache.org/licenses/LICENSE-2.0
14 # Unless required by applicable law or agreed to in writing,
15 # software distributed under the License is distributed on an
16 # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 # KIND, either express or implied. See the License for the
18 # specific language governing permissions and limitations
24 sys
.path
.append('gen-py.twisted')
25 sys
.path
.insert(0, glob
.glob('../../lib/py/build/lib*')[0])
27 from tutorial
import Calculator
28 from tutorial
.ttypes
import InvalidOperation
, Operation
, Work
30 from twisted
.internet
.defer
import inlineCallbacks
31 from twisted
.internet
import reactor
32 from twisted
.internet
.protocol
import ClientCreator
34 from thrift
.transport
import TTwisted
35 from thrift
.protocol
import TBinaryProtocol
43 sum = yield client
.add(1, 1)
44 print(('1+1=%d' % (sum)))
48 work
.op
= Operation
.DIVIDE
53 quotient
= yield client
.calculate(1, work
)
54 print('Whoa? You know how to divide by zero?')
55 print('FYI the answer is %d' % quotient
)
56 except InvalidOperation
as e
:
57 print(('InvalidOperation: %r' % e
))
59 work
.op
= Operation
.SUBTRACT
63 diff
= yield client
.calculate(1, work
)
64 print(('15-10=%d' % (diff
)))
66 log
= yield client
.getStruct(1)
67 print(('Check log: %s' % (log
.value
)))
71 if __name__
== '__main__':
72 d
= ClientCreator(reactor
,
73 TTwisted
.ThriftClientProtocol
,
75 TBinaryProtocol
.TBinaryProtocolFactory(),
76 ).connectTCP("127.0.0.1", 9090)
77 d
.addCallback(lambda conn
: conn
.client
)