Skip to content

Commit e5457cb

Browse files
committed
Merge branch 'py3k' into 2.0
Conflicts: cassandra/cluster.py cassandra/encoder.py cassandra/marshal.py cassandra/pool.py setup.py tests/integration/long/test_large_data.py tests/integration/long/utils.py tests/integration/standard/test_metadata.py tests/integration/standard/test_prepared_statements.py tests/unit/io/test_asyncorereactor.py tests/unit/test_connection.py tests/unit/test_types.py
2 parents efc8036 + f979435 commit e5457cb

44 files changed

Lines changed: 623 additions & 427 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.travis.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ env:
44
- TOX_ENV=py26
55
- TOX_ENV=py27
66
- TOX_ENV=pypy
7+
- TOX_ENV=py33
78

89
before_install:
910
- sudo apt-get update -y
1011
- sudo apt-get install -y build-essential python-dev
1112
- sudo apt-get install -y libev4 libev-dev
13+
1214
install:
1315
- pip install tox
1416

benchmarks/base.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
from cassandra.io.libevreactor import LibevConnection
4242
have_libev = True
4343
supported_reactors.append(LibevConnection)
44-
except ImportError, exc:
44+
except ImportError as exc:
4545
pass
4646

4747
KEYSPACE = "testkeyspace"
@@ -104,7 +104,7 @@ def benchmark(thread_class):
104104
""".format(table=TABLE))
105105
values = ('key', 'a', 'b')
106106

107-
per_thread = options.num_ops / options.threads
107+
per_thread = options.num_ops // options.threads
108108
threads = []
109109

110110
log.debug("Beginning inserts...")

benchmarks/callback_full_pipeline.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
from threading import Event
1919

2020
from base import benchmark, BenchmarkThread
21-
21+
from six.moves import range
2222

2323
log = logging.getLogger(__name__)
2424

@@ -38,17 +38,17 @@ def insert_next(self, previous_result=sentinel):
3838
if previous_result is not sentinel:
3939
if isinstance(previous_result, BaseException):
4040
log.error("Error on insert: %r", previous_result)
41-
if self.num_finished.next() >= self.num_queries:
41+
if next(self.num_finished) >= self.num_queries:
4242
self.event.set()
4343

44-
if self.num_started.next() <= self.num_queries:
44+
if next(self.num_started) <= self.num_queries:
4545
future = self.session.execute_async(self.query, self.values)
4646
future.add_callbacks(self.insert_next, self.insert_next)
4747

4848
def run(self):
4949
self.start_profile()
5050

51-
for _ in xrange(min(120, self.num_queries)):
51+
for _ in range(min(120, self.num_queries)):
5252
self.insert_next()
5353

5454
self.event.wait()

benchmarks/future_batches.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
# limitations under the License.
1414

1515
import logging
16-
import Queue
17-
1816
from base import benchmark, BenchmarkThread
17+
from six.moves import queue
1918

2019
log = logging.getLogger(__name__)
2120

21+
2222
class Runner(BenchmarkThread):
2323

2424
def run(self):
25-
futures = Queue.Queue(maxsize=121)
25+
futures = queue.Queue(maxsize=121)
2626

2727
self.start_profile()
2828

@@ -32,7 +32,7 @@ def run(self):
3232
while True:
3333
try:
3434
futures.get_nowait().result()
35-
except Queue.Empty:
35+
except queue.Empty:
3636
break
3737

3838
future = self.session.execute_async(self.query, self.values)
@@ -41,7 +41,7 @@ def run(self):
4141
while True:
4242
try:
4343
futures.get_nowait().result()
44-
except Queue.Empty:
44+
except queue.Empty:
4545
break
4646

4747
self.finish_profile()

benchmarks/future_full_pipeline.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
# limitations under the License.
1414

1515
import logging
16-
import Queue
17-
1816
from base import benchmark, BenchmarkThread
17+
from six.moves import queue
1918

2019
log = logging.getLogger(__name__)
2120

21+
2222
class Runner(BenchmarkThread):
2323

2424
def run(self):
25-
futures = Queue.Queue(maxsize=121)
25+
futures = queue.Queue(maxsize=121)
2626

2727
self.start_profile()
2828

@@ -37,7 +37,7 @@ def run(self):
3737
while True:
3838
try:
3939
futures.get_nowait().result()
40-
except Queue.Empty:
40+
except queue.Empty:
4141
break
4242

4343
self.finish_profile

benchmarks/future_full_throttle.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ def run(self):
2525

2626
self.start_profile()
2727

28-
for i in range(self.num_queries):
28+
for _ in range(self.num_queries):
2929
future = self.session.execute_async(self.query, self.values)
3030
futures.append(future)
3131

benchmarks/sync.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
# limitations under the License.
1414

1515
from base import benchmark, BenchmarkThread
16+
from six.moves import range
17+
1618

1719
class Runner(BenchmarkThread):
1820

1921
def run(self):
2022
self.start_profile()
2123

22-
for i in xrange(self.num_queries):
24+
for _ in range(self.num_queries):
2325
self.session.execute(self.query, self.values)
2426

2527
self.finish_profile()

cassandra/cluster.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,11 @@
2626
import sys
2727
import time
2828
from threading import Lock, RLock, Thread, Event
29-
import Queue
29+
30+
import six
31+
from six.moves import range
32+
from six.moves import queue as Queue
33+
3034
import weakref
3135
from weakref import WeakValueDictionary
3236
try:
@@ -696,7 +700,7 @@ def on_down(self, host, is_host_addition, expect_host_to_be_down=False):
696700

697701
host.set_down()
698702

699-
log.warn("Host %s has been marked down", host)
703+
log.warning("Host %s has been marked down", host)
700704

701705
self.load_balancing_policy.on_down(host)
702706
self.control_connection.on_down(host)
@@ -742,7 +746,7 @@ def future_completed(future):
742746
return
743747

744748
if not all(futures_results):
745-
log.warn("Connection pool could not be created, not marking node %s up", host)
749+
log.warning("Connection pool could not be created, not marking node %s up", host)
746750
return
747751

748752
self._finalize_add(host)
@@ -867,7 +871,7 @@ def _prepare_all_queries(self, host):
867871
# prepare 10 statements at a time
868872
ks_statements = list(ks_statements)
869873
chunks = []
870-
for i in xrange(0, len(ks_statements), 10):
874+
for i in range(0, len(ks_statements), 10):
871875
chunks.append(ks_statements[i:i + 10])
872876

873877
for ks_chunk in chunks:
@@ -882,9 +886,9 @@ def _prepare_all_queries(self, host):
882886

883887
log.debug("Done preparing all known prepared statements against host %s", host)
884888
except OperationTimedOut as timeout:
885-
log.warn("Timed out trying to prepare all statements on host %s: %s", host, timeout)
889+
log.warning("Timed out trying to prepare all statements on host %s: %s", host, timeout)
886890
except (ConnectionException, socket.error) as exc:
887-
log.warn("Error trying to prepare all statements on host %s: %r", host, exc)
891+
log.warning("Error trying to prepare all statements on host %s: %r", host, exc)
888892
except Exception:
889893
log.exception("Error trying to prepare all statements on host %s", host)
890894
finally:
@@ -1088,7 +1092,7 @@ def _create_response_future(self, query, parameters, trace):
10881092

10891093
prepared_statement = None
10901094

1091-
if isinstance(query, basestring):
1095+
if isinstance(query, six.string_types):
10921096
query = SimpleStatement(query)
10931097
elif isinstance(query, PreparedStatement):
10941098
query = query.bind(parameters)
@@ -1235,8 +1239,8 @@ def run_add_or_renew_pool():
12351239
self.cluster.signal_connection_failure(host, conn_exc, is_host_addition)
12361240
return False
12371241
except Exception as conn_exc:
1238-
log.warn("Failed to create connection pool for new host %s: %s",
1239-
host, conn_exc)
1242+
log.warning("Failed to create connection pool for new host %s: %s",
1243+
host, conn_exc)
12401244
# the host itself will still be marked down, so we need to pass
12411245
# a special flag to make sure the reconnector is created
12421246
self.cluster.signal_connection_failure(
@@ -1456,11 +1460,11 @@ def _reconnect_internal(self):
14561460
return self._try_connect(host)
14571461
except ConnectionException as exc:
14581462
errors[host.address] = exc
1459-
log.warn("[control connection] Error connecting to %s:", host, exc_info=True)
1463+
log.warning("[control connection] Error connecting to %s:", host, exc_info=True)
14601464
self._cluster.signal_connection_failure(host, exc, is_host_addition=False)
14611465
except Exception as exc:
14621466
errors[host.address] = exc
1463-
log.warn("[control connection] Error connecting to %s:", host, exc_info=True)
1467+
log.warning("[control connection] Error connecting to %s:", host, exc_info=True)
14641468

14651469
raise NoHostAvailable("Unable to connect to any servers", errors)
14661470

@@ -1948,7 +1952,7 @@ def run(self):
19481952
def _log_if_failed(self, future):
19491953
exc = future.exception()
19501954
if exc:
1951-
log.warn(
1955+
log.warning(
19521956
"An internally scheduled tasked failed with an unhandled exception:",
19531957
exc_info=exc)
19541958

@@ -2170,8 +2174,8 @@ def _set_result(self, response):
21702174
if self._metrics is not None:
21712175
self._metrics.on_other_error()
21722176
# need to retry against a different host here
2173-
log.warn("Host %s is overloaded, retrying against a different "
2174-
"host", self._current_host)
2177+
log.warning("Host %s is overloaded, retrying against a different "
2178+
"host", self._current_host)
21752179
self._retry(reuse_connection=False, consistency_level=None)
21762180
return
21772181
elif isinstance(response, IsBootstrappingErrorMessage):

cassandra/concurrent.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import sys
1616

1717
from itertools import count, cycle
18+
from six.moves import xrange
1819
from threading import Event
1920

2021

@@ -105,7 +106,7 @@ def execute_concurrent_with_args(session, statement, parameters, *args, **kwargs
105106
parameters = [(x,) for x in range(1000)]
106107
execute_concurrent_with_args(session, statement, parameters)
107108
"""
108-
return execute_concurrent(session, zip(cycle((statement,)), parameters), *args, **kwargs)
109+
return execute_concurrent(session, list(zip(cycle((statement,)), parameters)), *args, **kwargs)
109110

110111

111112
_sentinel = object()
@@ -118,12 +119,12 @@ def _handle_error(error, result_index, event, session, statements, results, num_
118119
return
119120
else:
120121
results[result_index] = (False, error)
121-
if num_finished.next() >= to_execute:
122+
if next(num_finished) >= to_execute:
122123
event.set()
123124
return
124125

125126
try:
126-
(next_index, (statement, params)) = statements.next()
127+
(next_index, (statement, params)) = next(statements)
127128
except StopIteration:
128129
return
129130

@@ -139,21 +140,21 @@ def _handle_error(error, result_index, event, session, statements, results, num_
139140
return
140141
else:
141142
results[next_index] = (False, exc)
142-
if num_finished.next() >= to_execute:
143+
if next(num_finished) >= to_execute:
143144
event.set()
144145
return
145146

146147

147148
def _execute_next(result, result_index, event, session, statements, results, num_finished, to_execute, first_error):
148149
if result is not _sentinel:
149150
results[result_index] = (True, result)
150-
finished = num_finished.next()
151+
finished = next(num_finished)
151152
if finished >= to_execute:
152153
event.set()
153154
return
154155

155156
try:
156-
(next_index, (statement, params)) = statements.next()
157+
(next_index, (statement, params)) = next(statements)
157158
except StopIteration:
158159
return
159160

@@ -169,6 +170,6 @@ def _execute_next(result, result_index, event, session, statements, results, num
169170
return
170171
else:
171172
results[next_index] = (False, exc)
172-
if num_finished.next() >= to_execute:
173+
if next(num_finished) >= to_execute:
173174
event.set()
174175
return

0 commit comments

Comments
 (0)