Use 2.6+ "except ... as ..." syntax

This commit is contained in:
Tyler Hobbs
2013-09-17 18:26:56 -05:00
parent 445d813454
commit 54d77739d0
22 changed files with 41 additions and 42 deletions

View File

@@ -767,11 +767,11 @@ class Session(object):
else:
try:
new_pool = HostConnectionPool(host, distance, self)
except AuthenticationFailed, auth_exc:
except AuthenticationFailed as auth_exc:
conn_exc = ConnectionException(str(auth_exc), host=host)
host.monitor.signal_connection_failure(conn_exc)
return self._pools.get(host)
except Exception, conn_exc:
except Exception as conn_exc:
host.monitor.signal_connection_failure(conn_exc)
return self._pools.get(host)
@@ -927,11 +927,11 @@ class ControlConnection(object):
for host in self._balancing_policy.make_query_plan():
try:
return self._try_connect(host)
except ConnectionException, exc:
except ConnectionException as exc:
errors[host.address] = exc
host.monitor.signal_connection_failure(exc)
log.warn("[control connection] Error connecting to %s: %s", host, exc)
except Exception, exc:
except Exception as exc:
errors[host.address] = exc
log.warn("[control connection] Error connecting to %s: %s", host, exc)
@@ -1393,7 +1393,7 @@ class ResponseFuture(object):
self._current_pool = pool
self._connection = connection
return request_id
except Exception, exc:
except Exception as exc:
log.debug("Error querying host %s", host, exc_info=True)
self._errors[host] = exc
if connection:
@@ -1525,7 +1525,7 @@ class ResponseFuture(object):
exc = ConnectionException(msg, self._current_host)
self._connection.defunct(exc)
self._set_final_exception(exc)
except Exception, exc:
except Exception as exc:
# almost certainly caused by a bug, but we need to set something here
log.exception("Unexpected exception while handling result in ResponseFuture:")
self._set_final_exception(exc)

View File

@@ -100,7 +100,7 @@ def defunct_on_error(f):
def wrapper(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except Exception, exc:
except Exception as exc:
self.defunct(exc)
return wrapper
@@ -190,7 +190,7 @@ class Connection(object):
raise ProtocolError("Got negative body length: %r" % body_len)
response = decode_response(stream_id, flags, opcode, body, self.decompressor)
except Exception, exc:
except Exception as exc:
log.exception("Error decoding response from Cassandra. "
"opcode: %04x; message contents: %r" % (opcode, body))
if callback is not None:
@@ -303,10 +303,10 @@ class Connection(object):
else:
raise self.defunct(ConnectionException(
"Problem while setting keyspace: %r" % (result,), self.host))
except InvalidRequestException, ire:
except InvalidRequestException as ire:
# the keyspace probably doesn't exist
raise ire.to_exception()
except Exception, exc:
except Exception as exc:
raise self.defunct(ConnectionException(
"Problem while setting keyspace: %r" % (exc,), self.host))

View File

@@ -136,7 +136,7 @@ def lookup_casstype(casstype):
return casstype
try:
return parse_casstype_args(casstype)
except (ValueError, AssertionError, IndexError), e:
except (ValueError, AssertionError, IndexError) as e:
raise ValueError("Don't know how to parse type string %r: %s" % (casstype, e))

View File

@@ -181,7 +181,7 @@ class AsyncoreConnection(Connection, asyncore.dispatcher):
try:
sent = self.send(next_msg)
except socket.error, err:
except socket.error as err:
if (err.args[0] in NONBLOCKING):
self.deque.appendleft(next_msg)
else:
@@ -199,7 +199,7 @@ class AsyncoreConnection(Connection, asyncore.dispatcher):
def handle_read(self):
try:
buf = self.recv(self.in_buffer_size)
except socket.error, err:
except socket.error as err:
if err.args[0] not in NONBLOCKING:
self.defunct(err)
return

View File

@@ -68,7 +68,7 @@ def defunct_on_error(f):
def wrapper(self, *args, **kwargs):
try:
return f(self, *args, **kwargs)
except Exception, exc:
except Exception as exc:
self.defunct(exc)
return wrapper
@@ -180,7 +180,7 @@ class LibevConnection(Connection):
try:
sent = self._socket.send(next_msg)
except socket.error, err:
except socket.error as err:
if (err.args[0] in NONBLOCKING):
self.deque.appendleft(next_msg)
else:
@@ -196,7 +196,7 @@ class LibevConnection(Connection):
def handle_read(self, watcher, revents):
try:
buf = self._socket.recv(self.in_buffer_size)
except socket.error, err:
except socket.error as err:
if err.args[0] not in NONBLOCKING:
self.defunct(err)
return

View File

@@ -14,7 +14,7 @@ import weakref
murmur3 = None
try:
from murmur3 import murmur3
except ImportError, exc:
except ImportError:
pass
import cassandra.cqltypes as types

View File

@@ -130,7 +130,7 @@ class _ReconnectionHandler(object):
try:
self.on_reconnection(self.try_reconnect())
except Exception, exc:
except Exception as exc:
next_delay = self.schedule.next()
if self.on_exception(exc, next_delay):
self.scheduler.schedule(next_delay, self.run)
@@ -382,7 +382,7 @@ class HostConnectionPool(object):
self._connections = new_connections
self._signal_available_conn()
return True
except ConnectionException, exc:
except ConnectionException as exc:
log.exception("Failed to add new connection to pool for host %s" % (self.host,))
with self._lock:
self.open_count -= 1

View File

@@ -302,7 +302,6 @@ class InvalidParameterTypeError(TypeError):
super(InvalidParameterTypeError, self).__init__(message)
class QueryTrace(object):
"""
A trace of the duration and events that occurred when executing

View File

@@ -57,7 +57,7 @@ class doc(Command):
output = subprocess.check_output(
["sphinx-build", "-b", mode, "docs", path],
stderr=subprocess.STDOUT)
except subprocess.CalledProcessError, exc:
except subprocess.CalledProcessError as exc:
raise RuntimeError("Documentation step '%s' failed: %s: %s" % (mode, exc, exc.output))
else:
print output
@@ -110,7 +110,7 @@ On OSX, via homebrew:
def run(self):
try:
build_ext.run(self)
except DistutilsPlatformError, exc:
except DistutilsPlatformError as exc:
sys.stderr.write('%s\n' % str(exc))
warnings.warn(self.error_message % "C extensions.")
@@ -118,7 +118,7 @@ On OSX, via homebrew:
try:
build_ext.build_extension(self, ext)
except (CCompilerError, DistutilsExecError,
DistutilsPlatformError, IOError), exc:
DistutilsPlatformError, IOError) as exc:
sys.stderr.write('%s\n' % str(exc))
name = "The %s extension" % (ext.name,)
warnings.warn(self.error_message % (name,))

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
import logging
log = logging.getLogger(__name__)
@@ -11,7 +11,7 @@ from threading import Event
try:
from ccmlib.cluster import Cluster as CCMCluster
from ccmlib import common
except ImportError, e:
except ImportError as e:
raise unittest.SkipTest('ccm is a dependency for integration tests')
CLUSTER_NAME = 'test_cluster'

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from cassandra.cluster import Cluster, NoHostAvailable

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from functools import partial
from threading import Thread, Event

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from cassandra.cluster import Cluster
from cassandra.query import PreparedStatement

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from decimal import Decimal
from datetime import datetime

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
import errno
from StringIO import StringIO
@@ -20,7 +20,7 @@ from cassandra.marshal import uint8_pack, uint32_pack
try:
from cassandra.io.libevreactor import LibevConnection
except ImportError, exc:
except ImportError as exc:
raise unittest.SkipTest('libev does not appear to be installed correctly: %s' % (exc,))
@patch('socket.socket')

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from StringIO import StringIO

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from mock import Mock, ANY

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from mock import Mock, NonCallableMagicMock
from threading import Thread, Event

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
import platform
from datetime import datetime

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from cassandra.query import bind_params, ValueSequence
from cassandra.query import PreparedStatement, BoundStatement
@@ -49,8 +49,8 @@ class ParamBindingTest(unittest.TestCase):
class BoundStatementTestCase(unittest.TestCase):
def test_invalid_argument_type(self):
query = 'SELECT foo1, foo2 from bar where foo1 = ? and foo2 = ?'
keyspace = 'keyspace1'
column_family = 'cf1'
@@ -70,7 +70,7 @@ class BoundStatementTestCase(unittest.TestCase):
try:
bound_statement.bind(values)
except InvalidParameterTypeError, e:
except InvalidParameterTypeError as e:
self.assertEqual(e.col_name, 'foo1')
self.assertEqual(e.expected_type, Int32Type)
self.assertEqual(e.actual_type, str)
@@ -79,7 +79,7 @@ class BoundStatementTestCase(unittest.TestCase):
try:
bound_statement.bind(values)
except TypeError, e:
except TypeError as e:
self.assertEqual(e.col_name, 'foo1')
self.assertEqual(e.expected_type, Int32Type)
self.assertEqual(e.actual_type, str)
@@ -90,7 +90,7 @@ class BoundStatementTestCase(unittest.TestCase):
try:
bound_statement.bind(values)
except InvalidParameterTypeError, e:
except InvalidParameterTypeError as e:
self.assertEqual(e.col_name, 'foo2')
self.assertEqual(e.expected_type, Int32Type)
self.assertEqual(e.actual_type, list)

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from itertools import islice, cycle
from mock import Mock

View File

@@ -1,7 +1,7 @@
try:
import unittest2 as unittest
except ImportError:
import unittest
import unittest # noqa
from mock import Mock, MagicMock, ANY