| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 1 | #!/usr/bin/python | 
 | 2 |  | 
 | 3 | import sys | 
 | 4 | sys.path.append('./gen-py') | 
 | 5 |  | 
 | 6 | import ThriftTest | 
 | 7 | from ThriftTest_types import * | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 8 | from thrift.transport import TTransport | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 9 | from thrift.transport import TSocket | 
 | 10 | from thrift.protocol import TBinaryProtocol | 
 | 11 |  | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 12 | import timing | 
 | 13 |  | 
 | 14 | transport = TTransport.TBufferedTransport(TSocket.TSocket('localhost', 9090)) | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 15 | protocol = TBinaryProtocol.TBinaryProtocol() | 
 | 16 | client = ThriftTest.Client(transport, protocol) | 
 | 17 |  | 
 | 18 | transport.open() | 
 | 19 |  | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 20 | # Start debug timing | 
 | 21 | timing.start() | 
 | 22 |  | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 23 | print "testVoid()" | 
 | 24 | print client.testVoid() | 
 | 25 |  | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 26 | print "testString('Python')" | 
 | 27 | print client.testString('Python') | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 28 |  | 
 | 29 | print "testByte(63)" | 
 | 30 | print client.testByte(63) | 
 | 31 |  | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 32 | print "testI32(-1)" | 
 | 33 | print client.testI32(-1) | 
 | 34 |  | 
| Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 35 | print "testI32(0)" | 
 | 36 | print client.testI32(0) | 
 | 37 |  | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 38 | print "testI64(-34359738368)" | 
 | 39 | print client.testI64(-34359738368) | 
 | 40 |  | 
| Mark Slee | c98d050 | 2006-09-06 02:42:25 +0000 | [diff] [blame] | 41 | print "testDouble(-5.235098235)" | 
 | 42 | print client.testDouble(-5.235098235) | 
 | 43 |  | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 44 | print "testStruct({Zero, 1, -3, -5})" | 
 | 45 | x = Xtruct() | 
 | 46 | x.string_thing = "Zero" | 
 | 47 | x.byte_thing = 1 | 
 | 48 | x.i32_thing = -3 | 
 | 49 | x.i64_thing = -5 | 
 | 50 | x = client.testStruct(x) | 
 | 51 | print "{%s, %d, %d, %d}" % (x.string_thing, x.byte_thing, x.i32_thing, x.i64_thing) | 
 | 52 |  | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 53 | print "testException('Safe')" | 
 | 54 | print client.testException('Safe') | 
 | 55 |  | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 56 | try: | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 57 |   print "textException('Xception')" | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 58 |   print client.testException('Xception') | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 59 |  | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 60 | except Xception, x: | 
| Mark Slee | c967656 | 2006-09-05 17:34:52 +0000 | [diff] [blame] | 61 |   print "Xception (%d, %s)" % (x.errorCode, x.message) | 
 | 62 |  | 
 | 63 | timing.finish() | 
 | 64 | print "Total time: %d microsecs" % timing.micro() | 
| Mark Slee | fc89d39 | 2006-09-04 00:04:39 +0000 | [diff] [blame] | 65 |  | 
 | 66 | transport.close() |