Use 2.6+ "except ... as ..." syntax
This commit is contained in:
@@ -767,11 +767,11 @@ class Session(object):
|
|||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
new_pool = HostConnectionPool(host, distance, self)
|
new_pool = HostConnectionPool(host, distance, self)
|
||||||
except AuthenticationFailed, auth_exc:
|
except AuthenticationFailed as auth_exc:
|
||||||
conn_exc = ConnectionException(str(auth_exc), host=host)
|
conn_exc = ConnectionException(str(auth_exc), host=host)
|
||||||
host.monitor.signal_connection_failure(conn_exc)
|
host.monitor.signal_connection_failure(conn_exc)
|
||||||
return self._pools.get(host)
|
return self._pools.get(host)
|
||||||
except Exception, conn_exc:
|
except Exception as conn_exc:
|
||||||
host.monitor.signal_connection_failure(conn_exc)
|
host.monitor.signal_connection_failure(conn_exc)
|
||||||
return self._pools.get(host)
|
return self._pools.get(host)
|
||||||
|
|
||||||
@@ -927,11 +927,11 @@ class ControlConnection(object):
|
|||||||
for host in self._balancing_policy.make_query_plan():
|
for host in self._balancing_policy.make_query_plan():
|
||||||
try:
|
try:
|
||||||
return self._try_connect(host)
|
return self._try_connect(host)
|
||||||
except ConnectionException, exc:
|
except ConnectionException as exc:
|
||||||
errors[host.address] = exc
|
errors[host.address] = exc
|
||||||
host.monitor.signal_connection_failure(exc)
|
host.monitor.signal_connection_failure(exc)
|
||||||
log.warn("[control connection] Error connecting to %s: %s", host, exc)
|
log.warn("[control connection] Error connecting to %s: %s", host, exc)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
errors[host.address] = exc
|
errors[host.address] = exc
|
||||||
log.warn("[control connection] Error connecting to %s: %s", host, exc)
|
log.warn("[control connection] Error connecting to %s: %s", host, exc)
|
||||||
|
|
||||||
@@ -1393,7 +1393,7 @@ class ResponseFuture(object):
|
|||||||
self._current_pool = pool
|
self._current_pool = pool
|
||||||
self._connection = connection
|
self._connection = connection
|
||||||
return request_id
|
return request_id
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
log.debug("Error querying host %s", host, exc_info=True)
|
log.debug("Error querying host %s", host, exc_info=True)
|
||||||
self._errors[host] = exc
|
self._errors[host] = exc
|
||||||
if connection:
|
if connection:
|
||||||
@@ -1525,7 +1525,7 @@ class ResponseFuture(object):
|
|||||||
exc = ConnectionException(msg, self._current_host)
|
exc = ConnectionException(msg, self._current_host)
|
||||||
self._connection.defunct(exc)
|
self._connection.defunct(exc)
|
||||||
self._set_final_exception(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
|
# almost certainly caused by a bug, but we need to set something here
|
||||||
log.exception("Unexpected exception while handling result in ResponseFuture:")
|
log.exception("Unexpected exception while handling result in ResponseFuture:")
|
||||||
self._set_final_exception(exc)
|
self._set_final_exception(exc)
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ def defunct_on_error(f):
|
|||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return f(self, *args, **kwargs)
|
return f(self, *args, **kwargs)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.defunct(exc)
|
self.defunct(exc)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
@@ -190,7 +190,7 @@ class Connection(object):
|
|||||||
raise ProtocolError("Got negative body length: %r" % body_len)
|
raise ProtocolError("Got negative body length: %r" % body_len)
|
||||||
|
|
||||||
response = decode_response(stream_id, flags, opcode, body, self.decompressor)
|
response = decode_response(stream_id, flags, opcode, body, self.decompressor)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
log.exception("Error decoding response from Cassandra. "
|
log.exception("Error decoding response from Cassandra. "
|
||||||
"opcode: %04x; message contents: %r" % (opcode, body))
|
"opcode: %04x; message contents: %r" % (opcode, body))
|
||||||
if callback is not None:
|
if callback is not None:
|
||||||
@@ -303,10 +303,10 @@ class Connection(object):
|
|||||||
else:
|
else:
|
||||||
raise self.defunct(ConnectionException(
|
raise self.defunct(ConnectionException(
|
||||||
"Problem while setting keyspace: %r" % (result,), self.host))
|
"Problem while setting keyspace: %r" % (result,), self.host))
|
||||||
except InvalidRequestException, ire:
|
except InvalidRequestException as ire:
|
||||||
# the keyspace probably doesn't exist
|
# the keyspace probably doesn't exist
|
||||||
raise ire.to_exception()
|
raise ire.to_exception()
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
raise self.defunct(ConnectionException(
|
raise self.defunct(ConnectionException(
|
||||||
"Problem while setting keyspace: %r" % (exc,), self.host))
|
"Problem while setting keyspace: %r" % (exc,), self.host))
|
||||||
|
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ def lookup_casstype(casstype):
|
|||||||
return casstype
|
return casstype
|
||||||
try:
|
try:
|
||||||
return parse_casstype_args(casstype)
|
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))
|
raise ValueError("Don't know how to parse type string %r: %s" % (casstype, e))
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -181,7 +181,7 @@ class AsyncoreConnection(Connection, asyncore.dispatcher):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
sent = self.send(next_msg)
|
sent = self.send(next_msg)
|
||||||
except socket.error, err:
|
except socket.error as err:
|
||||||
if (err.args[0] in NONBLOCKING):
|
if (err.args[0] in NONBLOCKING):
|
||||||
self.deque.appendleft(next_msg)
|
self.deque.appendleft(next_msg)
|
||||||
else:
|
else:
|
||||||
@@ -199,7 +199,7 @@ class AsyncoreConnection(Connection, asyncore.dispatcher):
|
|||||||
def handle_read(self):
|
def handle_read(self):
|
||||||
try:
|
try:
|
||||||
buf = self.recv(self.in_buffer_size)
|
buf = self.recv(self.in_buffer_size)
|
||||||
except socket.error, err:
|
except socket.error as err:
|
||||||
if err.args[0] not in NONBLOCKING:
|
if err.args[0] not in NONBLOCKING:
|
||||||
self.defunct(err)
|
self.defunct(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -68,7 +68,7 @@ def defunct_on_error(f):
|
|||||||
def wrapper(self, *args, **kwargs):
|
def wrapper(self, *args, **kwargs):
|
||||||
try:
|
try:
|
||||||
return f(self, *args, **kwargs)
|
return f(self, *args, **kwargs)
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
self.defunct(exc)
|
self.defunct(exc)
|
||||||
|
|
||||||
return wrapper
|
return wrapper
|
||||||
@@ -180,7 +180,7 @@ class LibevConnection(Connection):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
sent = self._socket.send(next_msg)
|
sent = self._socket.send(next_msg)
|
||||||
except socket.error, err:
|
except socket.error as err:
|
||||||
if (err.args[0] in NONBLOCKING):
|
if (err.args[0] in NONBLOCKING):
|
||||||
self.deque.appendleft(next_msg)
|
self.deque.appendleft(next_msg)
|
||||||
else:
|
else:
|
||||||
@@ -196,7 +196,7 @@ class LibevConnection(Connection):
|
|||||||
def handle_read(self, watcher, revents):
|
def handle_read(self, watcher, revents):
|
||||||
try:
|
try:
|
||||||
buf = self._socket.recv(self.in_buffer_size)
|
buf = self._socket.recv(self.in_buffer_size)
|
||||||
except socket.error, err:
|
except socket.error as err:
|
||||||
if err.args[0] not in NONBLOCKING:
|
if err.args[0] not in NONBLOCKING:
|
||||||
self.defunct(err)
|
self.defunct(err)
|
||||||
return
|
return
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ import weakref
|
|||||||
murmur3 = None
|
murmur3 = None
|
||||||
try:
|
try:
|
||||||
from murmur3 import murmur3
|
from murmur3 import murmur3
|
||||||
except ImportError, exc:
|
except ImportError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
import cassandra.cqltypes as types
|
import cassandra.cqltypes as types
|
||||||
|
|||||||
@@ -130,7 +130,7 @@ class _ReconnectionHandler(object):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
self.on_reconnection(self.try_reconnect())
|
self.on_reconnection(self.try_reconnect())
|
||||||
except Exception, exc:
|
except Exception as exc:
|
||||||
next_delay = self.schedule.next()
|
next_delay = self.schedule.next()
|
||||||
if self.on_exception(exc, next_delay):
|
if self.on_exception(exc, next_delay):
|
||||||
self.scheduler.schedule(next_delay, self.run)
|
self.scheduler.schedule(next_delay, self.run)
|
||||||
@@ -382,7 +382,7 @@ class HostConnectionPool(object):
|
|||||||
self._connections = new_connections
|
self._connections = new_connections
|
||||||
self._signal_available_conn()
|
self._signal_available_conn()
|
||||||
return True
|
return True
|
||||||
except ConnectionException, exc:
|
except ConnectionException as exc:
|
||||||
log.exception("Failed to add new connection to pool for host %s" % (self.host,))
|
log.exception("Failed to add new connection to pool for host %s" % (self.host,))
|
||||||
with self._lock:
|
with self._lock:
|
||||||
self.open_count -= 1
|
self.open_count -= 1
|
||||||
|
|||||||
@@ -302,7 +302,6 @@ class InvalidParameterTypeError(TypeError):
|
|||||||
super(InvalidParameterTypeError, self).__init__(message)
|
super(InvalidParameterTypeError, self).__init__(message)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class QueryTrace(object):
|
class QueryTrace(object):
|
||||||
"""
|
"""
|
||||||
A trace of the duration and events that occurred when executing
|
A trace of the duration and events that occurred when executing
|
||||||
|
|||||||
6
setup.py
6
setup.py
@@ -57,7 +57,7 @@ class doc(Command):
|
|||||||
output = subprocess.check_output(
|
output = subprocess.check_output(
|
||||||
["sphinx-build", "-b", mode, "docs", path],
|
["sphinx-build", "-b", mode, "docs", path],
|
||||||
stderr=subprocess.STDOUT)
|
stderr=subprocess.STDOUT)
|
||||||
except subprocess.CalledProcessError, exc:
|
except subprocess.CalledProcessError as exc:
|
||||||
raise RuntimeError("Documentation step '%s' failed: %s: %s" % (mode, exc, exc.output))
|
raise RuntimeError("Documentation step '%s' failed: %s: %s" % (mode, exc, exc.output))
|
||||||
else:
|
else:
|
||||||
print output
|
print output
|
||||||
@@ -110,7 +110,7 @@ On OSX, via homebrew:
|
|||||||
def run(self):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
build_ext.run(self)
|
build_ext.run(self)
|
||||||
except DistutilsPlatformError, exc:
|
except DistutilsPlatformError as exc:
|
||||||
sys.stderr.write('%s\n' % str(exc))
|
sys.stderr.write('%s\n' % str(exc))
|
||||||
warnings.warn(self.error_message % "C extensions.")
|
warnings.warn(self.error_message % "C extensions.")
|
||||||
|
|
||||||
@@ -118,7 +118,7 @@ On OSX, via homebrew:
|
|||||||
try:
|
try:
|
||||||
build_ext.build_extension(self, ext)
|
build_ext.build_extension(self, ext)
|
||||||
except (CCompilerError, DistutilsExecError,
|
except (CCompilerError, DistutilsExecError,
|
||||||
DistutilsPlatformError, IOError), exc:
|
DistutilsPlatformError, IOError) as exc:
|
||||||
sys.stderr.write('%s\n' % str(exc))
|
sys.stderr.write('%s\n' % str(exc))
|
||||||
name = "The %s extension" % (ext.name,)
|
name = "The %s extension" % (ext.name,)
|
||||||
warnings.warn(self.error_message % (name,))
|
warnings.warn(self.error_message % (name,))
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
@@ -11,7 +11,7 @@ from threading import Event
|
|||||||
try:
|
try:
|
||||||
from ccmlib.cluster import Cluster as CCMCluster
|
from ccmlib.cluster import Cluster as CCMCluster
|
||||||
from ccmlib import common
|
from ccmlib import common
|
||||||
except ImportError, e:
|
except ImportError as e:
|
||||||
raise unittest.SkipTest('ccm is a dependency for integration tests')
|
raise unittest.SkipTest('ccm is a dependency for integration tests')
|
||||||
|
|
||||||
CLUSTER_NAME = 'test_cluster'
|
CLUSTER_NAME = 'test_cluster'
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from cassandra.cluster import Cluster, NoHostAvailable
|
from cassandra.cluster import Cluster, NoHostAvailable
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from cassandra.cluster import Cluster
|
from cassandra.cluster import Cluster
|
||||||
from cassandra.query import PreparedStatement
|
from cassandra.query import PreparedStatement
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
import errno
|
import errno
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
@@ -20,7 +20,7 @@ from cassandra.marshal import uint8_pack, uint32_pack
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
from cassandra.io.libevreactor import LibevConnection
|
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,))
|
raise unittest.SkipTest('libev does not appear to be installed correctly: %s' % (exc,))
|
||||||
|
|
||||||
@patch('socket.socket')
|
@patch('socket.socket')
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from StringIO import StringIO
|
from StringIO import StringIO
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from mock import Mock, ANY
|
from mock import Mock, ANY
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from mock import Mock, NonCallableMagicMock
|
from mock import Mock, NonCallableMagicMock
|
||||||
from threading import Thread, Event
|
from threading import Thread, Event
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
import platform
|
import platform
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from cassandra.query import bind_params, ValueSequence
|
from cassandra.query import bind_params, ValueSequence
|
||||||
from cassandra.query import PreparedStatement, BoundStatement
|
from cassandra.query import PreparedStatement, BoundStatement
|
||||||
@@ -49,8 +49,8 @@ class ParamBindingTest(unittest.TestCase):
|
|||||||
|
|
||||||
|
|
||||||
class BoundStatementTestCase(unittest.TestCase):
|
class BoundStatementTestCase(unittest.TestCase):
|
||||||
|
|
||||||
def test_invalid_argument_type(self):
|
def test_invalid_argument_type(self):
|
||||||
query = 'SELECT foo1, foo2 from bar where foo1 = ? and foo2 = ?'
|
|
||||||
keyspace = 'keyspace1'
|
keyspace = 'keyspace1'
|
||||||
column_family = 'cf1'
|
column_family = 'cf1'
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ class BoundStatementTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
bound_statement.bind(values)
|
bound_statement.bind(values)
|
||||||
except InvalidParameterTypeError, e:
|
except InvalidParameterTypeError as e:
|
||||||
self.assertEqual(e.col_name, 'foo1')
|
self.assertEqual(e.col_name, 'foo1')
|
||||||
self.assertEqual(e.expected_type, Int32Type)
|
self.assertEqual(e.expected_type, Int32Type)
|
||||||
self.assertEqual(e.actual_type, str)
|
self.assertEqual(e.actual_type, str)
|
||||||
@@ -79,7 +79,7 @@ class BoundStatementTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
bound_statement.bind(values)
|
bound_statement.bind(values)
|
||||||
except TypeError, e:
|
except TypeError as e:
|
||||||
self.assertEqual(e.col_name, 'foo1')
|
self.assertEqual(e.col_name, 'foo1')
|
||||||
self.assertEqual(e.expected_type, Int32Type)
|
self.assertEqual(e.expected_type, Int32Type)
|
||||||
self.assertEqual(e.actual_type, str)
|
self.assertEqual(e.actual_type, str)
|
||||||
@@ -90,7 +90,7 @@ class BoundStatementTestCase(unittest.TestCase):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
bound_statement.bind(values)
|
bound_statement.bind(values)
|
||||||
except InvalidParameterTypeError, e:
|
except InvalidParameterTypeError as e:
|
||||||
self.assertEqual(e.col_name, 'foo2')
|
self.assertEqual(e.col_name, 'foo2')
|
||||||
self.assertEqual(e.expected_type, Int32Type)
|
self.assertEqual(e.expected_type, Int32Type)
|
||||||
self.assertEqual(e.actual_type, list)
|
self.assertEqual(e.actual_type, list)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from itertools import islice, cycle
|
from itertools import islice, cycle
|
||||||
from mock import Mock
|
from mock import Mock
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
try:
|
try:
|
||||||
import unittest2 as unittest
|
import unittest2 as unittest
|
||||||
except ImportError:
|
except ImportError:
|
||||||
import unittest
|
import unittest # noqa
|
||||||
|
|
||||||
from mock import Mock, MagicMock, ANY
|
from mock import Mock, MagicMock, ANY
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user