Thrift-1784: pep-3110 exception handling
Client: py
Patch: jfarrell
Updates python lib for pep-3110
diff --git a/lib/py/src/server/THttpServer.py b/lib/py/src/server/THttpServer.py
index be54bab..6f92173 100644
--- a/lib/py/src/server/THttpServer.py
+++ b/lib/py/src/server/THttpServer.py
@@ -73,7 +73,7 @@
oprot = thttpserver.outputProtocolFactory.getProtocol(otrans)
try:
thttpserver.processor.process(iprot, oprot)
- except ResponseException, exn:
+ except ResponseException as exn:
exn.handler(self)
else:
self.send_response(200)
diff --git a/lib/py/src/server/TProcessPoolServer.py b/lib/py/src/server/TProcessPoolServer.py
index eefb623..ae7fe1c 100644
--- a/lib/py/src/server/TProcessPoolServer.py
+++ b/lib/py/src/server/TProcessPoolServer.py
@@ -63,7 +63,7 @@
self.serveClient(client)
except (KeyboardInterrupt, SystemExit):
return 0
- except Exception, x:
+ except Exception as x:
logger.exception(x)
def serveClient(self, client):
@@ -76,9 +76,9 @@
try:
while True:
self.processor.process(iprot, oprot)
- except TTransportException, tx:
+ except TTransportException as tx:
pass
- except Exception, x:
+ except Exception as x:
logger.exception(x)
itrans.close()
@@ -99,7 +99,7 @@
w.daemon = True
w.start()
self.workers.append(w)
- except Exception, x:
+ except Exception as x:
logger.exception(x)
# wait until the condition is set by stop()
@@ -110,7 +110,7 @@
break
except (SystemExit, KeyboardInterrupt):
break
- except Exception, x:
+ except Exception as x:
logger.exception(x)
self.isRunning.value = False
diff --git a/lib/py/src/server/TServer.py b/lib/py/src/server/TServer.py
index 00fd8cf..8c58e39 100644
--- a/lib/py/src/server/TServer.py
+++ b/lib/py/src/server/TServer.py
@@ -86,9 +86,9 @@
try:
while True:
self.processor.process(iprot, oprot)
- except TTransport.TTransportException, tx:
+ except TTransport.TTransportException as tx:
pass
- except Exception, x:
+ except Exception as x:
logger.exception(x)
itrans.close()
@@ -114,7 +114,7 @@
t.start()
except KeyboardInterrupt:
raise
- except Exception, x:
+ except Exception as x:
logger.exception(x)
def handle(self, client):
@@ -125,9 +125,9 @@
try:
while True:
self.processor.process(iprot, oprot)
- except TTransport.TTransportException, tx:
+ except TTransport.TTransportException as tx:
pass
- except Exception, x:
+ except Exception as x:
logger.exception(x)
itrans.close()
@@ -153,7 +153,7 @@
try:
client = self.clients.get()
self.serveClient(client)
- except Exception, x:
+ except Exception as x:
logger.exception(x)
def serveClient(self, client):
@@ -165,9 +165,9 @@
try:
while True:
self.processor.process(iprot, oprot)
- except TTransport.TTransportException, tx:
+ except TTransport.TTransportException as tx:
pass
- except Exception, x:
+ except Exception as x:
logger.exception(x)
itrans.close()
@@ -180,7 +180,7 @@
t = threading.Thread(target=self.serveThread)
t.setDaemon(self.daemon)
t.start()
- except Exception, x:
+ except Exception as x:
logger.exception(x)
# Pump the socket for clients
@@ -191,7 +191,7 @@
if not client:
continue
self.clients.put(client)
- except Exception, x:
+ except Exception as x:
logger.exception(x)
@@ -216,7 +216,7 @@
def try_close(file):
try:
file.close()
- except IOError, e:
+ except IOError as e:
logger.warning(e, exc_info=True)
self.serverTransport.listen()
@@ -250,9 +250,9 @@
try:
while True:
self.processor.process(iprot, oprot)
- except TTransport.TTransportException, tx:
+ except TTransport.TTransportException as tx:
pass
- except Exception, e:
+ except Exception as e:
logger.exception(e)
ecode = 1
finally:
@@ -261,9 +261,9 @@
os._exit(ecode)
- except TTransport.TTransportException, tx:
+ except TTransport.TTransportException as tx:
pass
- except Exception, x:
+ except Exception as x:
logger.exception(x)
def collect_children(self):
diff --git a/lib/py/src/transport/TSSLSocket.py b/lib/py/src/transport/TSSLSocket.py
index c01886d..6ad8d50 100644
--- a/lib/py/src/transport/TSSLSocket.py
+++ b/lib/py/src/transport/TSSLSocket.py
@@ -102,13 +102,13 @@
self.handle.settimeout(self._timeout)
try:
self.handle.connect(ip_port)
- except socket.error, e:
+ except socket.error as e:
if res is not res0[-1]:
continue
else:
raise e
break
- except socket.error, e:
+ except socket.error as e:
if self._unix_socket:
message = 'Could not connect to secure socket %s: %s' \
% (self._unix_socket, e)
@@ -213,7 +213,7 @@
client = ssl.wrap_socket(plain_client, certfile=self.certfile,
server_side=True, ssl_version=self.SSL_VERSION,
ciphers=self.ciphers)
- except ssl.SSLError, ssl_exc:
+ except ssl.SSLError as ssl_exc:
# failed handshake/ssl wrap, close socket to client
plain_client.close()
# raise ssl_exc
diff --git a/lib/py/src/transport/TSocket.py b/lib/py/src/transport/TSocket.py
index 0175bdc..7b564aa 100644
--- a/lib/py/src/transport/TSocket.py
+++ b/lib/py/src/transport/TSocket.py
@@ -86,13 +86,13 @@
self.handle.settimeout(self._timeout)
try:
self.handle.connect(res[4])
- except socket.error, e:
+ except socket.error as e:
if res is not res0[-1]:
continue
else:
raise e
break
- except socket.error, e:
+ except socket.error as e:
if self._unix_socket:
message = 'Could not connect to socket %s' % self._unix_socket
else:
@@ -103,7 +103,7 @@
def read(self, sz):
try:
buff = self.handle.recv(sz)
- except socket.error, e:
+ except socket.error as e:
if (e.args[0] == errno.ECONNRESET and
(sys.platform == 'darwin' or sys.platform.startswith('freebsd'))):
# freebsd and Mach don't follow POSIX semantic of recv
@@ -161,7 +161,7 @@
tmp = socket.socket(res[0], res[1])
try:
tmp.connect(res[4])
- except socket.error, err:
+ except socket.error as err:
eno, message = err.args
if eno == errno.ECONNREFUSED:
os.unlink(res[4])