THRIFT-1857 Python 3 Support
Client: Python
Patch: Thomas Bartelmess, Eevee (Alex Munroe), helgridly, Christian Verkerk, Jeroen Vlek, Nobuaki Sukegawa

This closes #213 and closes #680
diff --git a/tutorial/py.tornado/PythonClient.py b/tutorial/py.tornado/PythonClient.py
index 95d78b8..005ad3c 100755
--- a/tutorial/py.tornado/PythonClient.py
+++ b/tutorial/py.tornado/PythonClient.py
@@ -22,7 +22,7 @@
 import sys
 import glob
 sys.path.append('gen-py.tornado')
-sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
+sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
 
 import logging
 
@@ -56,21 +56,21 @@
 
     # ping
     yield gen.Task(client.ping)
-    print "ping()"
+    print("ping()")
 
     # add
     sum_ = yield gen.Task(client.add, 1, 1)
-    print "1 + 1 = {}".format(sum_)
+    print("1 + 1 = {}".format(sum_))
 
     # make a oneway call without a callback (schedule the write and continue
     # without blocking)
     client.zip()
-    print "zip() without callback"
+    print("zip() without callback")
 
     # make a oneway call with a callback (we'll wait for the stream write to
     # complete before continuing)
     yield gen.Task(client.zip)
-    print "zip() with callback"
+    print("zip() with callback")
 
     # calculate 1/0
     work = Work()
@@ -80,9 +80,9 @@
 
     try:
         quotient = yield gen.Task(client.calculate, 1, work)
-        print "Whoa? You know how to divide by zero?"
+        print("Whoa? You know how to divide by zero?")
     except InvalidOperation as io:
-        print "InvalidOperation: {}".format(io)
+        print("InvalidOperation: {}".format(io))
 
     # calculate 15-10
     work.op = Operation.SUBTRACT
@@ -90,11 +90,11 @@
     work.num2 = 10
 
     diff = yield gen.Task(client.calculate, 1, work)
-    print "15 - 10 = {}".format(diff)
+    print("15 - 10 = {}".format(diff))
 
     # getStruct
     log = yield gen.Task(client.getStruct, 1)
-    print "Check log: {}".format(log.value)
+    print("Check log: {}".format(log.value))
 
     # close the transport
     client._transport.close()
diff --git a/tutorial/py.tornado/PythonServer.py b/tutorial/py.tornado/PythonServer.py
index 7a34107..4198214 100755
--- a/tutorial/py.tornado/PythonServer.py
+++ b/tutorial/py.tornado/PythonServer.py
@@ -22,7 +22,7 @@
 import sys
 import glob
 sys.path.append('gen-py.tornado')
-sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
+sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
 
 from tutorial import Calculator
 from tutorial.ttypes import Operation, InvalidOperation
@@ -43,15 +43,15 @@
         self.log = {}
 
     def ping(self, callback):
-        print "ping()"
+        print("ping()")
         callback()
 
     def add(self, n1, n2, callback):
-        print "add({}, {})".format(n1, n2)
+        print("add({}, {})".format(n1, n2))
         callback(n1 + n2)
 
     def calculate(self, logid, work, callback):
-        print "calculate({}, {})".format(logid, work)
+        print("calculate({}, {})".format(logid, work))
 
         if work.op == Operation.ADD:
             val = work.num1 + work.num2
@@ -79,11 +79,11 @@
         callback(val)
 
     def getStruct(self, key, callback):
-        print "getStruct({})".format(key)
+        print("getStruct({})".format(key))
         callback(self.log[key])
 
     def zip(self, callback):
-        print "zip()"
+        print("zip()")
         callback()
 
 
@@ -93,11 +93,11 @@
     pfactory = TBinaryProtocol.TBinaryProtocolFactory()
     server = TTornado.TTornadoServer(processor, pfactory)
 
-    print "Starting the server..."
+    print("Starting the server...")
     server.bind(9090)
     server.start(1)
     ioloop.IOLoop.instance().start()
-    print "done."
+    print("done.")
 
 
 if __name__ == "__main__":
diff --git a/tutorial/py.twisted/PythonClient.py b/tutorial/py.twisted/PythonClient.py
index 9e086f0..e80c0fc 100755
--- a/tutorial/py.twisted/PythonClient.py
+++ b/tutorial/py.twisted/PythonClient.py
@@ -21,7 +21,7 @@
 
 import sys, glob
 sys.path.append('gen-py.twisted')
-sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
+sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
 
 from tutorial import Calculator
 from tutorial.ttypes import *
@@ -37,10 +37,10 @@
 @inlineCallbacks
 def main(client):
   yield client.ping()
-  print 'ping()'
+  print('ping()')
 
   sum = yield client.add(1,1)
-  print '1+1=%d' % (sum)
+  print(('1+1=%d' % (sum)))
 
   work = Work()
 
@@ -50,19 +50,19 @@
 
   try:
     quotient = yield client.calculate(1, work)
-    print 'Whoa? You know how to divide by zero?'
-  except InvalidOperation, io:
-    print 'InvalidOperation: %r' % io
+    print('Whoa? You know how to divide by zero?')
+  except InvalidOperation as e:
+    print(('InvalidOperation: %r' % e))
 
   work.op = Operation.SUBTRACT
   work.num1 = 15
   work.num2 = 10
 
   diff = yield client.calculate(1, work)
-  print '15-10=%d' % (diff)
+  print(('15-10=%d' % (diff)))
 
   log = yield client.getStruct(1)
-  print 'Check log: %s' % (log.value)
+  print(('Check log: %s' % (log.value)))
   reactor.stop()
 
 if __name__ == '__main__':
diff --git a/tutorial/py.twisted/PythonServer.py b/tutorial/py.twisted/PythonServer.py
index 227f6d4..c578321 100755
--- a/tutorial/py.twisted/PythonServer.py
+++ b/tutorial/py.twisted/PythonServer.py
@@ -21,7 +21,7 @@
 
 import sys, glob
 sys.path.append('gen-py.twisted')
-sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
+sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
 
 from tutorial import Calculator
 from tutorial.ttypes import *
@@ -36,19 +36,19 @@
 from thrift.server import TServer
 
 class CalculatorHandler:
-  implements(Calculator.Iface)  
+  implements(Calculator.Iface)
   def __init__(self):
     self.log = {}
 
   def ping(self):
-    print 'ping()'
+    print('ping()')
 
   def add(self, n1, n2):
-    print 'add(%d,%d)' % (n1, n2)
+    print('add(%d,%d)' % (n1, n2))
     return n1+n2
 
   def calculate(self, logid, work):
-    print 'calculate(%d, %r)' % (logid, work)
+    print('calculate(%d, %r)' % (logid, work))
 
     if work.op == Operation.ADD:
       val = work.num1 + work.num2
@@ -77,11 +77,11 @@
     return val
 
   def getStruct(self, key):
-    print 'getStruct(%d)' % (key)
+    print('getStruct(%d)' % (key))
     return self.log[key]
 
   def zip(self):
-    print 'zip()'
+    print('zip()')
 
 if __name__ == '__main__':
     handler = CalculatorHandler()
diff --git a/tutorial/py.twisted/PythonServer.tac b/tutorial/py.twisted/PythonServer.tac
index 1d0b6c4..08493ff 100755
--- a/tutorial/py.twisted/PythonServer.tac
+++ b/tutorial/py.twisted/PythonServer.tac
@@ -24,7 +24,7 @@
 
 import sys, glob
 sys.path.append('gen-py.twisted')
-sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
+sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
 from tutorial import Calculator
 from tutorial.ttypes import *
 from PythonServer import CalculatorHandler
diff --git a/tutorial/py/PythonClient.py b/tutorial/py/PythonClient.py
index 0554ee1..c4559ff 100755
--- a/tutorial/py/PythonClient.py
+++ b/tutorial/py/PythonClient.py
@@ -21,7 +21,7 @@
 
 import sys, glob
 sys.path.append('gen-py')
-sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
+sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
 
 from tutorial import Calculator
 from tutorial.ttypes import *
@@ -49,10 +49,10 @@
   transport.open()
 
   client.ping()
-  print 'ping()'
+  print('ping()')
 
   sum = client.add(1,1)
-  print '1+1=%d' % (sum)
+  print(('1+1=%d' % (sum)))
 
   work = Work()
 
@@ -62,22 +62,22 @@
 
   try:
     quotient = client.calculate(1, work)
-    print 'Whoa? You know how to divide by zero?'
-  except InvalidOperation, io:
-    print 'InvalidOperation: %r' % io
+    print('Whoa? You know how to divide by zero?')
+  except InvalidOperation as e:
+    print(('InvalidOperation: %r' % e))
 
   work.op = Operation.SUBTRACT
   work.num1 = 15
   work.num2 = 10
 
   diff = client.calculate(1, work)
-  print '15-10=%d' % (diff)
+  print(('15-10=%d' % (diff)))
 
   log = client.getStruct(1)
-  print 'Check log: %s' % (log.value)
+  print(('Check log: %s' % (log.value)))
 
   # Close!
   transport.close()
 
-except Thrift.TException, tx:
-  print '%s' % (tx.message)
+except Thrift.TException as tx:
+  print(('%s' % (tx.message)))
diff --git a/tutorial/py/PythonServer.py b/tutorial/py/PythonServer.py
index 533b0ea..8ef231b 100755
--- a/tutorial/py/PythonServer.py
+++ b/tutorial/py/PythonServer.py
@@ -21,7 +21,7 @@
 
 import sys, glob
 sys.path.append('gen-py')
-sys.path.insert(0, glob.glob('../../lib/py/build/lib.*')[0])
+sys.path.insert(0, glob.glob('../../lib/py/build/lib*')[0])
 
 from tutorial import Calculator
 from tutorial.ttypes import *
@@ -38,14 +38,14 @@
     self.log = {}
 
   def ping(self):
-    print 'ping()'
+    print('ping()')
 
   def add(self, n1, n2):
-    print 'add(%d,%d)' % (n1, n2)
+    print('add(%d,%d)' % (n1, n2))
     return n1+n2
 
   def calculate(self, logid, work):
-    print 'calculate(%d, %r)' % (logid, work)
+    print('calculate(%d, %r)' % (logid, work))
 
     if work.op == Operation.ADD:
       val = work.num1 + work.num2
@@ -74,11 +74,11 @@
     return val
 
   def getStruct(self, key):
-    print 'getStruct(%d)' % (key)
+    print('getStruct(%d)' % (key))
     return self.log[key]
 
   def zip(self):
-    print 'zip()'
+    print('zip()')
 
 handler = CalculatorHandler()
 processor = Calculator.Processor(handler)
@@ -92,6 +92,6 @@
 #server = TServer.TThreadedServer(processor, transport, tfactory, pfactory)
 #server = TServer.TThreadPoolServer(processor, transport, tfactory, pfactory)
 
-print 'Starting the server...'
+print('Starting the server...')
 server.serve()
-print 'done.'
+print('done.')