summaryrefslogtreecommitdiff
path: root/tutorial/py
diff options
context:
space:
mode:
authorMark Slee <mcslee@apache.org>2007-03-14 02:47:35 +0000
committerMark Slee <mcslee@apache.org>2007-03-14 02:47:35 +0000
commit7679196f1cb6a4b919917aeab065ca86b9b8ad91 (patch)
tree432f2d4425bcc5e627261ef459cf34b6b32ba57e /tutorial/py
parent0c2dff3f5a69726e98636c091454b9b5e3ab8898 (diff)
downloadthrift-7679196f1cb6a4b919917aeab065ca86b9b8ad91.tar.gz
Various Thrift fixes, including Application Exception support in Ruby, better errror messages across languages, etc.
Reviewed By: thrift git-svn-id: https://svn.apache.org/repos/asf/incubator/thrift/trunk@665058 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'tutorial/py')
-rwxr-xr-xtutorial/py/PythonClient.py73
1 files changed, 39 insertions, 34 deletions
diff --git a/tutorial/py/PythonClient.py b/tutorial/py/PythonClient.py
index 96ca03a91..9dcecd97c 100755
--- a/tutorial/py/PythonClient.py
+++ b/tutorial/py/PythonClient.py
@@ -6,53 +6,58 @@ sys.path.append('../gen-py')
from tutorial import Calculator
from tutorial.ttypes import *
+from thrift import Thrift
from thrift.transport import TSocket
from thrift.transport import TTransport
from thrift.protocol import TBinaryProtocol
-# Make socket
-transport = TSocket.TSocket('localhost', 9090)
-
-# Buffering is critical. Raw sockets are very slow
-transport = TTransport.TBufferedTransport(transport)
-
-# Wrap in a protocol
-protocol = TBinaryProtocol.TBinaryProtocol(transport)
+try:
-# Create a client to use the protocol encoder
-client = Calculator.Client(protocol)
+ # Make socket
+ transport = TSocket.TSocket('localhost', 9090)
-# Connect!
-transport.open()
+ # Buffering is critical. Raw sockets are very slow
+ transport = TTransport.TBufferedTransport(transport)
-client.ping()
-print 'ping()'
+ # Wrap in a protocol
+ protocol = TBinaryProtocol.TBinaryProtocol(transport)
-sum = client.add(1,1)
-print '1+1=%d' % (sum)
+ # Create a client to use the protocol encoder
+ client = Calculator.Client(protocol)
-work = Work()
+ # Connect!
+ transport.open()
-work.op = Operation.DIVIDE
-work.num1 = 1
-work.num2 = 0
+ client.ping()
+ print 'ping()'
-try:
- quotient = client.calculate(1, work)
- print 'Whoa? You know how to divide by zero?'
-except InvalidOperation, io:
- print 'InvalidOperation: %s' % (io.__str__())
+ sum = client.add(1,1)
+ print '1+1=%d' % (sum)
-work.op = Operation.SUBTRACT
-work.num1 = 15
-work.num2 = 10
+ work = Work()
+
+ work.op = Operation.DIVIDE
+ work.num1 = 1
+ work.num2 = 0
-diff = client.calculate(1, work)
-print '15-10=%d' % (diff)
+ try:
+ quotient = client.calculate(1, work)
+ print 'Whoa? You know how to divide by zero?'
+ except InvalidOperation, io:
+ print 'InvalidOperation: %s' % (io.__str__())
+
+ work.op = Operation.SUBTRACT
+ work.num1 = 15
+ work.num2 = 10
+
+ diff = client.calculate(1, work)
+ print '15-10=%d' % (diff)
-log = client.getStruct(1)
-print 'Check log: %s' % (log.value)
+ log = client.getStruct(1)
+ print 'Check log: %s' % (log.value)
-# Close!
-transport.close()
+ # Close!
+ transport.close()
+except Thrift.TException, tx:
+ print '%s' % (tx.message)