Skip to content

Commit 2d1c787

Browse files
Lorak-mmkfruch
authored andcommitted
Drop 'six' from dependencies
As we no longer support Python 2, there is no reason to keep this dependency. This commit removes all usages of six and removes it from dependencies.
1 parent 8a4387a commit 2d1c787

File tree

106 files changed

+398
-739
lines changed

Some content is hidden

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

106 files changed

+398
-739
lines changed

benchmarks/callback_full_pipeline.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
from threading import Event
1919

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

2322
log = logging.getLogger(__name__)
2423

benchmarks/future_batches.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import logging
1616
from base import benchmark, BenchmarkThread
17-
from six.moves import queue
17+
import queue
1818

1919
log = logging.getLogger(__name__)
2020

benchmarks/future_full_pipeline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
import logging
1616
from base import benchmark, BenchmarkThread
17-
from six.moves import queue
17+
import queue
1818

1919
log = logging.getLogger(__name__)
2020

benchmarks/sync.py

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

1515
from base import benchmark, BenchmarkThread
16-
from six.moves import range
1716

1817

1918
class Runner(BenchmarkThread):

cassandra/auth.py

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232
except ImportError:
3333
SASLClient = None
3434

35-
import six
36-
3735
log = logging.getLogger(__name__)
3836

3937
# Custom payload keys related to DSE Unified Auth
@@ -270,15 +268,15 @@ def __init__(self, username, password):
270268
self.password = password
271269

272270
def get_mechanism(self):
273-
return six.b("PLAIN")
271+
return b"PLAIN"
274272

275273
def get_initial_challenge(self):
276-
return six.b("PLAIN-START")
274+
return b"PLAIN-START"
277275

278276
def evaluate_challenge(self, challenge):
279-
if challenge == six.b('PLAIN-START'):
277+
if challenge == b'PLAIN-START':
280278
data = "\x00%s\x00%s" % (self.username, self.password)
281-
return data if six.PY2 else data.encode()
279+
return data.encode()
282280
raise Exception('Did not receive a valid challenge response from server')
283281

284282

@@ -297,13 +295,13 @@ def __init__(self, host, service, qops, properties):
297295
self.sasl = SASLClient(host, service, 'GSSAPI', qops=qops, **properties)
298296

299297
def get_mechanism(self):
300-
return six.b("GSSAPI")
298+
return b"GSSAPI"
301299

302300
def get_initial_challenge(self):
303-
return six.b("GSSAPI-START")
301+
return b"GSSAPI-START"
304302

305303
def evaluate_challenge(self, challenge):
306-
if challenge == six.b('GSSAPI-START'):
304+
if challenge == b'GSSAPI-START':
307305
return self.sasl.process()
308306
else:
309307
return self.sasl.process(challenge)

cassandra/cluster.py

Lines changed: 12 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import atexit
2222
from binascii import hexlify
2323
from collections import defaultdict
24+
from collections.abc import Mapping
2425
from concurrent.futures import ThreadPoolExecutor, FIRST_COMPLETED, wait as wait_futures
2526
from copy import copy
2627
from functools import partial, wraps
@@ -30,8 +31,7 @@
3031
from warnings import warn
3132
from random import random
3233
import re
33-
import six
34-
from six.moves import filter, range, queue as Queue
34+
import queue
3535
import socket
3636
import sys
3737
import time
@@ -82,7 +82,6 @@
8282
from cassandra.marshal import int64_pack
8383
from cassandra.tablets import Tablet, Tablets
8484
from cassandra.timestamps import MonotonicTimestampGenerator
85-
from cassandra.compat import Mapping
8685
from cassandra.util import _resolve_contact_points_to_string_map, Version
8786

8887
from cassandra.datastax.insights.reporter import MonitorReporter
@@ -113,9 +112,6 @@
113112
except ImportError:
114113
from cassandra.util import WeakSet # NOQA
115114

116-
if six.PY3:
117-
long = int
118-
119115
def _is_eventlet_monkey_patched():
120116
if 'eventlet.patcher' not in sys.modules:
121117
return False
@@ -1219,7 +1215,7 @@ def __init__(self,
12191215
else:
12201216
self._contact_points_explicit = True
12211217

1222-
if isinstance(contact_points, six.string_types):
1218+
if isinstance(contact_points, str):
12231219
raise TypeError("contact_points should not be a string, it should be a sequence (e.g. list) of strings")
12241220

12251221
if None in contact_points:
@@ -1882,8 +1878,8 @@ def _new_session(self, keyspace):
18821878
return session
18831879

18841880
def _session_register_user_types(self, session):
1885-
for keyspace, type_map in six.iteritems(self._user_types):
1886-
for udt_name, klass in six.iteritems(type_map):
1881+
for keyspace, type_map in self._user_types.items():
1882+
for udt_name, klass in type_map.items():
18871883
session.user_type_registered(keyspace, udt_name, klass)
18881884

18891885
def _cleanup_failed_on_up_handling(self, host):
@@ -2767,7 +2763,7 @@ def execute_async(self, query, parameters=None, trace=False, custom_payload=None
27672763
"""
27682764
custom_payload = custom_payload if custom_payload else {}
27692765
if execute_as:
2770-
custom_payload[_proxy_execute_key] = six.b(execute_as)
2766+
custom_payload[_proxy_execute_key] = execute_as.encode()
27712767

27722768
future = self._create_response_future(
27732769
query, parameters, trace, custom_payload, timeout,
@@ -2831,8 +2827,8 @@ def execute_graph_async(self, query, parameters=None, trace=False, execution_pro
28312827

28322828
custom_payload = execution_profile.graph_options.get_options_map()
28332829
if execute_as:
2834-
custom_payload[_proxy_execute_key] = six.b(execute_as)
2835-
custom_payload[_request_timeout_key] = int64_pack(long(execution_profile.request_timeout * 1000))
2830+
custom_payload[_proxy_execute_key] = execute_as.encode()
2831+
custom_payload[_request_timeout_key] = int64_pack(int(execution_profile.request_timeout * 1000))
28362832

28372833
future = self._create_response_future(query, parameters=None, trace=trace, custom_payload=custom_payload,
28382834
timeout=_NOT_SET, execution_profile=execution_profile)
@@ -2969,7 +2965,7 @@ def _create_response_future(self, query, parameters, trace, custom_payload,
29692965

29702966
prepared_statement = None
29712967

2972-
if isinstance(query, six.string_types):
2968+
if isinstance(query, str):
29732969
query = SimpleStatement(query)
29742970
elif isinstance(query, PreparedStatement):
29752971
query = query.bind(parameters)
@@ -3437,10 +3433,6 @@ def user_type_registered(self, keyspace, user_type, klass):
34373433
'User type %s does not exist in keyspace %s' % (user_type, keyspace))
34383434

34393435
field_names = type_meta.field_names
3440-
if six.PY2:
3441-
# go from unicode to string to avoid decode errors from implicit
3442-
# decode when formatting non-ascii values
3443-
field_names = [fn.encode('utf-8') for fn in field_names]
34443436

34453437
def encode(val):
34463438
return '{ %s }' % ' , '.join('%s : %s' % (
@@ -4208,7 +4200,7 @@ def _get_schema_mismatches(self, peers_result, local_result, local_address):
42084200
log.debug("[control connection] Schemas match")
42094201
return None
42104202

4211-
return dict((version, list(nodes)) for version, nodes in six.iteritems(versions))
4203+
return dict((version, list(nodes)) for version, nodes in versions.items())
42124204

42134205
def _get_peers_query(self, peers_query_type, connection=None):
42144206
"""
@@ -4327,7 +4319,7 @@ class _Scheduler(Thread):
43274319
is_shutdown = False
43284320

43294321
def __init__(self, executor):
4330-
self._queue = Queue.PriorityQueue()
4322+
self._queue = queue.PriorityQueue()
43314323
self._scheduled_tasks = set()
43324324
self._count = count()
43334325
self._executor = executor
@@ -4385,7 +4377,7 @@ def run(self):
43854377
else:
43864378
self._queue.put_nowait((run_at, i, task))
43874379
break
4388-
except Queue.Empty:
4380+
except queue.Empty:
43894381
pass
43904382

43914383
time.sleep(0.1)

cassandra/compat.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

cassandra/concurrent.py

Lines changed: 6 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@
1616
from collections import namedtuple
1717
from heapq import heappush, heappop
1818
from itertools import cycle
19-
import six
20-
from six.moves import xrange, zip
2119
from threading import Condition
2220
import sys
2321

@@ -119,7 +117,7 @@ def execute(self, concurrency, fail_fast):
119117
self._current = 0
120118
self._exec_count = 0
121119
with self._condition:
122-
for n in xrange(concurrency):
120+
for n in range(concurrency):
123121
if not self._execute_next():
124122
break
125123
return self._results()
@@ -143,17 +141,13 @@ def _execute(self, idx, statement, params):
143141
callback=self._on_success, callback_args=args,
144142
errback=self._on_error, errback_args=args)
145143
except Exception as exc:
146-
# exc_info with fail_fast to preserve stack trace info when raising on the client thread
147-
# (matches previous behavior -- not sure why we wouldn't want stack trace in the other case)
148-
e = sys.exc_info() if self._fail_fast and six.PY2 else exc
149-
150144
# If we're not failing fast and all executions are raising, there is a chance of recursing
151145
# here as subsequent requests are attempted. If we hit this threshold, schedule this result/retry
152146
# and let the event loop thread return.
153147
if self._exec_depth < self.max_error_recursion:
154-
self._put_result(e, idx, False)
148+
self._put_result(exc, idx, False)
155149
else:
156-
self.session.submit(self._put_result, e, idx, False)
150+
self.session.submit(self._put_result, exc, idx, False)
157151
self._exec_depth -= 1
158152

159153
def _on_success(self, result, future, idx):
@@ -163,14 +157,6 @@ def _on_success(self, result, future, idx):
163157
def _on_error(self, result, future, idx):
164158
self._put_result(result, idx, False)
165159

166-
@staticmethod
167-
def _raise(exc):
168-
if six.PY2 and isinstance(exc, tuple):
169-
(exc_type, value, traceback) = exc
170-
six.reraise(exc_type, value, traceback)
171-
else:
172-
raise exc
173-
174160

175161
class ConcurrentExecutorGenResults(_ConcurrentExecutor):
176162

@@ -190,7 +176,7 @@ def _results(self):
190176
try:
191177
self._condition.release()
192178
if self._fail_fast and not res[0]:
193-
self._raise(res[1])
179+
raise res[1]
194180
yield res
195181
finally:
196182
self._condition.acquire()
@@ -221,9 +207,9 @@ def _results(self):
221207
while self._current < self._exec_count:
222208
self._condition.wait()
223209
if self._exception and self._fail_fast:
224-
self._raise(self._exception)
210+
raise self._exception
225211
if self._exception and self._fail_fast: # raise the exception even if there was no wait
226-
self._raise(self._exception)
212+
raise self._exception
227213
return [r[1] for r in sorted(self._results_queue)]
228214

229215

cassandra/connection.py

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
from heapq import heappush, heappop
2020
import io
2121
import logging
22-
import six
23-
from six.moves import range
2422
import socket
2523
import struct
2624
import sys
@@ -36,7 +34,7 @@
3634
if 'gevent.monkey' in sys.modules:
3735
from gevent.queue import Queue, Empty
3836
else:
39-
from six.moves.queue import Queue, Empty # noqa
37+
from queue import Queue, Empty # noqa
4038

4139
from cassandra import ConsistencyLevel, AuthenticationFailed, OperationTimedOut, ProtocolVersion
4240
from cassandra.marshal import int32_pack
@@ -613,12 +611,6 @@ def wrapper(self, *args, **kwargs):
613611

614612
DEFAULT_CQL_VERSION = '3.0.0'
615613

616-
if six.PY3:
617-
def int_from_buf_item(i):
618-
return i
619-
else:
620-
int_from_buf_item = ord
621-
622614

623615
class _ConnectionIOBuffer(object):
624616
"""
@@ -1164,7 +1156,7 @@ def _read_frame_header(self):
11641156
buf = self._io_buffer.cql_frame_buffer.getvalue()
11651157
pos = len(buf)
11661158
if pos:
1167-
version = int_from_buf_item(buf[0]) & PROTOCOL_VERSION_MASK
1159+
version = buf[0] & PROTOCOL_VERSION_MASK
11681160
if version not in ProtocolVersion.SUPPORTED_VERSIONS:
11691161
raise ProtocolError("This version of the driver does not support protocol version %d" % version)
11701162
frame_header = frame_header_v3 if version >= 3 else frame_header_v1_v2
@@ -1367,7 +1359,7 @@ def _handle_options_response(self, options_response):
13671359
remote_supported_compressions)
13681360
else:
13691361
compression_type = None
1370-
if isinstance(self.compression, six.string_types):
1362+
if isinstance(self.compression, str):
13711363
# the user picked a specific compression type ('snappy' or 'lz4')
13721364
if self.compression not in remote_supported_compressions:
13731365
raise ProtocolError(

cassandra/cqlengine/__init__.py

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,6 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
import six
16-
17-
1815
# Caching constants.
1916
CACHING_ALL = "ALL"
2017
CACHING_KEYS_ONLY = "KEYS_ONLY"
@@ -31,7 +28,4 @@ class ValidationError(CQLEngineException):
3128

3229

3330
class UnicodeMixin(object):
34-
if six.PY3:
35-
__str__ = lambda x: x.__unicode__()
36-
else:
37-
__str__ = lambda x: six.text_type(x).encode('utf-8')
31+
__str__ = lambda x: x.__unicode__()

0 commit comments

Comments
 (0)