From 6320813dff643a1ca3b3710c8551e724684a7e7e Mon Sep 17 00:00:00 2001 From: vgali7 Date: Wed, 21 Jun 2023 15:53:36 -0400 Subject: [PATCH 1/5] driver-six --- cassandra/auth.py | 2 +- cassandra/cluster.py | 6 -- cassandra/compat.py | 7 +- cassandra/concurrent.py | 8 +-- cassandra/connection.py | 7 +- cassandra/cqlengine/__init__.py | 8 +-- cassandra/cqltypes.py | 71 +++++++------------- cassandra/datastax/graph/graphson.py | 21 ++---- cassandra/datastax/insights/reporter.py | 6 +- cassandra/encoder.py | 55 +++++---------- cassandra/marshal.py | 33 +++------ cassandra/protocol.py | 2 - cassandra/query.py | 2 - cassandra/segment.py | 2 - cassandra/util.py | 3 - tests/integration/advanced/graph/__init__.py | 12 ++-- tests/integration/cloud/test_cloud.py | 5 +- tests/integration/datatype_utils.py | 8 +-- tests/integration/standard/test_types.py | 27 ++------ tests/unit/advanced/cloud/test_cloud.py | 2 +- tests/unit/test_policies.py | 2 +- tests/unit/test_segment.py | 2 - 22 files changed, 84 insertions(+), 207 deletions(-) diff --git a/cassandra/auth.py b/cassandra/auth.py index 3d2f751ac0..ce4c8a49bf 100644 --- a/cassandra/auth.py +++ b/cassandra/auth.py @@ -278,7 +278,7 @@ def get_initial_challenge(self): def evaluate_challenge(self, challenge): if challenge == six.b('PLAIN-START'): data = "\x00%s\x00%s" % (self.username, self.password) - return data if six.PY2 else data.encode() + return data.encode() raise Exception('Did not receive a valid challenge response from server') diff --git a/cassandra/cluster.py b/cassandra/cluster.py index 57fc2d4e8c..1e282fb89c 100644 --- a/cassandra/cluster.py +++ b/cassandra/cluster.py @@ -107,8 +107,6 @@ except ImportError: from cassandra.util import WeakSet # NOQA -if six.PY3: - long = int def _is_eventlet_monkey_patched(): if 'eventlet.patcher' not in sys.modules: @@ -3345,10 +3343,6 @@ def user_type_registered(self, keyspace, user_type, klass): 'User type %s does not exist in keyspace %s' % (user_type, keyspace)) field_names = type_meta.field_names - if six.PY2: - # go from unicode to string to avoid decode errors from implicit - # decode when formatting non-ascii values - field_names = [fn.encode('utf-8') for fn in field_names] def encode(val): return '{ %s }' % ' , '.join('%s : %s' % ( diff --git a/cassandra/compat.py b/cassandra/compat.py index 83c1b104e5..3a165b9133 100644 --- a/cassandra/compat.py +++ b/cassandra/compat.py @@ -12,9 +12,4 @@ # See the License for the specific language governing permissions and # limitations under the License. -import six - -if six.PY2: - from collections import Mapping -elif six.PY3: - from collections.abc import Mapping +from collections.abc import Mapping diff --git a/cassandra/concurrent.py b/cassandra/concurrent.py index 0228f297fe..17b3fe44e6 100644 --- a/cassandra/concurrent.py +++ b/cassandra/concurrent.py @@ -145,7 +145,7 @@ def _execute(self, idx, statement, params): except Exception as exc: # exc_info with fail_fast to preserve stack trace info when raising on the client thread # (matches previous behavior -- not sure why we wouldn't want stack trace in the other case) - e = sys.exc_info() if self._fail_fast and six.PY2 else exc + e = exc # If we're not failing fast and all executions are raising, there is a chance of recursing # here as subsequent requests are attempted. If we hit this threshold, schedule this result/retry @@ -165,11 +165,7 @@ def _on_error(self, result, future, idx): @staticmethod def _raise(exc): - if six.PY2 and isinstance(exc, tuple): - (exc_type, value, traceback) = exc - six.reraise(exc_type, value, traceback) - else: - raise exc + raise exc class ConcurrentExecutorGenResults(_ConcurrentExecutor): diff --git a/cassandra/connection.py b/cassandra/connection.py index 0869584663..ac3c4a840c 100644 --- a/cassandra/connection.py +++ b/cassandra/connection.py @@ -605,11 +605,8 @@ def wrapper(self, *args, **kwargs): DEFAULT_CQL_VERSION = '3.0.0' -if six.PY3: - def int_from_buf_item(i): - return i -else: - int_from_buf_item = ord +def int_from_buf_item(i): + return i class _ConnectionIOBuffer(object): diff --git a/cassandra/cqlengine/__init__.py b/cassandra/cqlengine/__init__.py index e2a952d682..6489b3ed66 100644 --- a/cassandra/cqlengine/__init__.py +++ b/cassandra/cqlengine/__init__.py @@ -12,8 +12,6 @@ # See the License for the specific language governing permissions and # limitations under the License. -import six - # Caching constants. CACHING_ALL = "ALL" @@ -31,7 +29,5 @@ class ValidationError(CQLEngineException): class UnicodeMixin(object): - if six.PY3: - __str__ = lambda x: x.__unicode__() - else: - __str__ = lambda x: six.text_type(x).encode('utf-8') + __str__ = lambda x: x.__unicode__() + diff --git a/cassandra/cqltypes.py b/cassandra/cqltypes.py index 6cc89aafbb..650edd0f68 100644 --- a/cassandra/cqltypes.py +++ b/cassandra/cqltypes.py @@ -54,10 +54,9 @@ from cassandra import util _little_endian_flag = 1 # we always serialize LE -if six.PY3: - import ipaddress +import ipaddress -_ord = ord if six.PY2 else lambda x: x +lambda x: x apache_cassandra_type_prefix = 'org.apache.cassandra.db.marshal.' @@ -66,16 +65,12 @@ log = logging.getLogger(__name__) -if six.PY3: - _number_types = frozenset((int, float)) - long = int +_number_types = frozenset((int, float)) +long = int - def _name_from_hex_string(encoded_name): - bin_str = unhexlify(encoded_name) - return bin_str.decode('ascii') -else: - _number_types = frozenset((int, long, float)) - _name_from_hex_string = unhexlify +def _name_from_hex_string(encoded_name): + bin_str = unhexlify(encoded_name) + return bin_str.decode('ascii') def trim_if_startswith(s, prefix): @@ -383,8 +378,6 @@ def apply_parameters(cls, subtypes, names=None): raise ValueError("%s types require %d subtypes (%d given)" % (cls.typename, cls.num_subtypes, len(subtypes))) newname = cls.cass_parameterized_type_with(subtypes) - if six.PY2 and isinstance(newname, unicode): - newname = newname.encode('utf-8') return type(newname, (cls,), {'subtypes': subtypes, 'cassname': cls.cassname, 'fieldnames': names}) @classmethod @@ -415,16 +408,10 @@ class _UnrecognizedType(_CassandraType): num_subtypes = 'UNKNOWN' -if six.PY3: - def mkUnrecognizedType(casstypename): - return CassandraTypeType(casstypename, - (_UnrecognizedType,), - {'typename': "'%s'" % casstypename}) -else: - def mkUnrecognizedType(casstypename): # noqa - return CassandraTypeType(casstypename.encode('utf8'), - (_UnrecognizedType,), - {'typename': "'%s'" % casstypename}) +def mkUnrecognizedType(casstypename): + return CassandraTypeType(casstypename, + (_UnrecognizedType,), + {'typename': "'%s'" % casstypename}) class BytesType(_CassandraType): @@ -500,25 +487,21 @@ def serialize(byts, protocol_version): return int8_pack(byts) -if six.PY2: - class AsciiType(_CassandraType): - typename = 'ascii' - empty_binary_ok = True -else: - class AsciiType(_CassandraType): - typename = 'ascii' - empty_binary_ok = True - @staticmethod - def deserialize(byts, protocol_version): - return byts.decode('ascii') +class AsciiType(_CassandraType): + typename = 'ascii' + empty_binary_ok = True - @staticmethod - def serialize(var, protocol_version): - try: - return var.encode('ascii') - except UnicodeDecodeError: - return var + @staticmethod + def deserialize(byts, protocol_version): + return byts.decode('ascii') + + @staticmethod + def serialize(var, protocol_version): + try: + return var.encode('ascii') + except UnicodeDecodeError: + return var class FloatType(_CassandraType): @@ -603,7 +586,7 @@ def serialize(addr, protocol_version): # since we've already determined the AF return socket.inet_aton(addr) except: - if six.PY3 and isinstance(addr, (ipaddress.IPv4Address, ipaddress.IPv6Address)): + if isinstance(addr, (ipaddress.IPv4Address, ipaddress.IPv6Address)): return addr.packed raise ValueError("can't interpret %r as an inet address" % (addr,)) @@ -975,8 +958,6 @@ class UserType(TupleType): def make_udt_class(cls, keyspace, udt_name, field_names, field_types): assert len(field_names) == len(field_types) - if six.PY2 and isinstance(udt_name, unicode): - udt_name = udt_name.encode('utf-8') instance = cls._cache.get((keyspace, udt_name)) if not instance or instance.fieldnames != field_names or instance.subtypes != field_types: @@ -992,8 +973,6 @@ def make_udt_class(cls, keyspace, udt_name, field_names, field_types): @classmethod def evict_udt_class(cls, keyspace, udt_name): - if six.PY2 and isinstance(udt_name, unicode): - udt_name = udt_name.encode('utf-8') try: del cls._cache[(keyspace, udt_name)] except KeyError: diff --git a/cassandra/datastax/graph/graphson.py b/cassandra/datastax/graph/graphson.py index 4b333eb1bf..db862bf15c 100644 --- a/cassandra/datastax/graph/graphson.py +++ b/cassandra/datastax/graph/graphson.py @@ -164,9 +164,7 @@ class Int64TypeIO(IntegerTypeIO): @classmethod def deserialize(cls, value, reader=None): - if six.PY3: - return value - return long(value) + return value class FloatTypeIO(GraphSONTypeIO): @@ -274,8 +272,7 @@ class BlobTypeIO(GraphSONTypeIO): @classmethod def serialize(cls, value, writer=None): value = base64.b64encode(value) - if six.PY3: - value = value.decode('utf-8') + value = value.decode('utf-8') return value @classmethod @@ -845,12 +842,8 @@ class GraphSON1Serializer(_BaseGraphSONSerializer): GraphSON1Serializer.register(ipaddress.IPv4Address, InetTypeIO) GraphSON1Serializer.register(ipaddress.IPv6Address, InetTypeIO) -if six.PY2: - GraphSON1Serializer.register(buffer, ByteBufferTypeIO) - GraphSON1Serializer.register(unicode, TextTypeIO) -else: - GraphSON1Serializer.register(memoryview, ByteBufferTypeIO) - GraphSON1Serializer.register(bytes, ByteBufferTypeIO) +GraphSON1Serializer.register(memoryview, ByteBufferTypeIO) +GraphSON1Serializer.register(bytes, ByteBufferTypeIO) class _BaseGraphSONDeserializer(object): @@ -922,9 +915,7 @@ def deserialize_int(cls, value): @classmethod def deserialize_bigint(cls, value): - if six.PY3: - return cls.deserialize_int(value) - return long(value) + return cls.deserialize_int(value) @classmethod def deserialize_double(cls, value): @@ -1007,8 +998,6 @@ def serialize(self, value, writer=None): GraphSON2Serializer.register(int, IntegerTypeIO) -if six.PY2: - GraphSON2Serializer.register(long, IntegerTypeIO) class GraphSON2Deserializer(_BaseGraphSONDeserializer): diff --git a/cassandra/datastax/insights/reporter.py b/cassandra/datastax/insights/reporter.py index b05a88deb0..295f263f62 100644 --- a/cassandra/datastax/insights/reporter.py +++ b/cassandra/datastax/insights/reporter.py @@ -199,9 +199,9 @@ def _get_startup_data(self): }, 'platformInfo': { 'os': { - 'name': uname_info.system if six.PY3 else uname_info[0], - 'version': uname_info.release if six.PY3 else uname_info[2], - 'arch': uname_info.machine if six.PY3 else uname_info[4] + 'name': uname_info.system, + 'version': uname_info.release, + 'arch': uname_info.machine }, 'cpus': { 'length': multiprocessing.cpu_count(), diff --git a/cassandra/encoder.py b/cassandra/encoder.py index f2c3f8dfed..8122e82eeb 100644 --- a/cassandra/encoder.py +++ b/cassandra/encoder.py @@ -32,11 +32,7 @@ from cassandra.util import (OrderedDict, OrderedMap, OrderedMapSerializedKey, sortedset, Time, Date, Point, LineString, Polygon) -if six.PY3: - import ipaddress - -if six.PY3: - long = int +import ipaddress def cql_quote(term): @@ -97,21 +93,14 @@ def __init__(self): Polygon: self.cql_encode_str_quoted } - if six.PY2: - self.mapping.update({ - unicode: self.cql_encode_unicode, - buffer: self.cql_encode_bytes, - long: self.cql_encode_object, - types.NoneType: self.cql_encode_none, - }) - else: - self.mapping.update({ - memoryview: self.cql_encode_bytes, - bytes: self.cql_encode_bytes, - type(None): self.cql_encode_none, - ipaddress.IPv4Address: self.cql_encode_ipaddress, - ipaddress.IPv6Address: self.cql_encode_ipaddress - }) + + self.mapping.update({ + memoryview: self.cql_encode_bytes, + bytes: self.cql_encode_bytes, + type(None): self.cql_encode_none, + ipaddress.IPv4Address: self.cql_encode_ipaddress, + ipaddress.IPv6Address: self.cql_encode_ipaddress + }) def cql_encode_none(self, val): """ @@ -134,16 +123,9 @@ def cql_encode_str(self, val): def cql_encode_str_quoted(self, val): return "'%s'" % val - if six.PY3: - def cql_encode_bytes(self, val): - return (b'0x' + hexlify(val)).decode('utf-8') - elif sys.version_info >= (2, 7): - def cql_encode_bytes(self, val): # noqa - return b'0x' + hexlify(val) - else: - # python 2.6 requires string or read-only buffer for hexlify - def cql_encode_bytes(self, val): # noqa - return b'0x' + hexlify(buffer(val)) + def cql_encode_bytes(self, val): + return (b'0x' + hexlify(val)).decode('utf-8') + def cql_encode_object(self, val): """ @@ -240,10 +222,9 @@ def cql_encode_all_types(self, val, as_text_type=False): return encoded.decode('utf-8') return encoded - if six.PY3: - def cql_encode_ipaddress(self, val): - """ - Converts an ipaddress (IPV4Address, IPV6Address) to a CQL string. This - is suitable for ``inet`` type columns. - """ - return "'%s'" % val.compressed + def cql_encode_ipaddress(self, val): + """ + Converts an ipaddress (IPV4Address, IPV6Address) to a CQL string. This + is suitable for ``inet`` type columns. + """ + return "'%s'" % val.compressed diff --git a/cassandra/marshal.py b/cassandra/marshal.py index 43cb627b08..e5bf5b0a42 100644 --- a/cassandra/marshal.py +++ b/cassandra/marshal.py @@ -45,35 +45,22 @@ def _make_packer(format_string): v3_header_unpack = v3_header_struct.unpack -if six.PY3: - def byte2int(b): - return b +def byte2int(b): + return b - def varint_unpack(term): - val = int(''.join("%02x" % i for i in term), 16) - if (term[0] & 128) != 0: - len_term = len(term) # pulling this out of the expression to avoid overflow in cython optimized code - val -= 1 << (len_term * 8) - return val -else: - def byte2int(b): - return ord(b) - - def varint_unpack(term): # noqa - val = int(term.encode('hex'), 16) - if (ord(term[0]) & 128) != 0: - len_term = len(term) # pulling this out of the expression to avoid overflow in cython optimized code - val = val - (1 << (len_term * 8)) - return val +def varint_unpack(term): + val = int(''.join("%02x" % i for i in term), 16) + if (term[0] & 128) != 0: + len_term = len(term) # pulling this out of the expression to avoid overflow in cython optimized code + val -= 1 << (len_term * 8) + return val def bit_length(n): - if six.PY3 or isinstance(n, int): - return int.bit_length(n) - else: - return long.bit_length(n) + return int.bit_length(n) + def varint_pack(big): diff --git a/cassandra/protocol.py b/cassandra/protocol.py index 5e3610811e..a9e2aecd6a 100644 --- a/cassandra/protocol.py +++ b/cassandra/protocol.py @@ -137,8 +137,6 @@ def recv_body(cls, f, protocol_version, *args): def summary_msg(self): msg = 'Error from server: code=%04x [%s] message="%s"' \ % (self.code, self.summary, self.message) - if six.PY2 and isinstance(msg, six.text_type): - msg = msg.encode('utf-8') return msg def __str__(self): diff --git a/cassandra/query.py b/cassandra/query.py index 7e4efc2511..32c2b67028 100644 --- a/cassandra/query.py +++ b/cassandra/query.py @@ -901,8 +901,6 @@ def __str__(self): def bind_params(query, params, encoder): - if six.PY2 and isinstance(query, six.text_type): - query = query.encode('utf-8') if isinstance(params, dict): return query % dict((k, encoder.cql_encode_all_types(v)) for k, v in six.iteritems(params)) else: diff --git a/cassandra/segment.py b/cassandra/segment.py index e3881c4402..ba2aa5e20b 100644 --- a/cassandra/segment.py +++ b/cassandra/segment.py @@ -54,8 +54,6 @@ def compute_crc24(data, length): def compute_crc32(data, value): crc32 = zlib.crc32(data, value) - if six.PY2: - crc32 &= 0xffffffff return crc32 diff --git a/cassandra/util.py b/cassandra/util.py index dd5c58b01d..118e2eabcc 100644 --- a/cassandra/util.py +++ b/cassandra/util.py @@ -922,9 +922,6 @@ def _serialize_key(self, key): import datetime import time -if six.PY3: - long = int - @total_ordering class Time(object): diff --git a/tests/integration/advanced/graph/__init__.py b/tests/integration/advanced/graph/__init__.py index 6c9458dd02..f1af32fe14 100644 --- a/tests/integration/advanced/graph/__init__.py +++ b/tests/integration/advanced/graph/__init__.py @@ -460,11 +460,9 @@ def datatypes(): GraphSON1Deserializer.deserialize_duration] } - if six.PY2: - data["blob2"] = ["Blob()", buffer(b"Hello World"), GraphSON1Deserializer.deserialize_blob] - else: - data["blob3"] = ["Blob()", bytes(b"Hello World Again"), GraphSON1Deserializer.deserialize_blob] - data["blob4"] = ["Blob()", memoryview(b"And Again Hello World"), GraphSON1Deserializer.deserialize_blob] + + data["blob3"] = ["Blob()", bytes(b"Hello World Again"), GraphSON1Deserializer.deserialize_blob] + data["blob4"] = ["Blob()", memoryview(b"And Again Hello World"), GraphSON1Deserializer.deserialize_blob] if DSE_VERSION >= Version("5.1"): data["time1"] = ["Time()", datetime.time(12, 6, 12, 444), GraphSON1Deserializer.deserialize_time] @@ -965,7 +963,7 @@ def generate_tests(cls, schema=None, graphson=None, traversal=False): """Generate tests for a graph configuration""" def decorator(klass): if DSE_VERSION: - predicate = inspect.ismethod if six.PY2 else inspect.isfunction + predicate = inspect.isfunction for name, func in inspect.getmembers(klass, predicate=predicate): if not name.startswith('_test'): continue @@ -984,7 +982,7 @@ def generate_schema_tests(cls, schema=None): """Generate schema tests for a graph configuration""" def decorator(klass): if DSE_VERSION: - predicate = inspect.ismethod if six.PY2 else inspect.isfunction + predicate = inspect.isfunction for name, func in inspect.getmembers(klass, predicate=predicate): if not name.startswith('_test'): continue diff --git a/tests/integration/cloud/test_cloud.py b/tests/integration/cloud/test_cloud.py index ef4909a257..a631260e4b 100644 --- a/tests/integration/cloud/test_cloud.py +++ b/tests/integration/cloud/test_cloud.py @@ -114,10 +114,7 @@ def test_error_when_bundle_doesnt_exist(self): try: self.connect('/invalid/path/file.zip') except Exception as e: - if six.PY2: - self.assertIsInstance(e, IOError) - else: - self.assertIsInstance(e, FileNotFoundError) + self.assertIsInstance(e, FileNotFoundError) def test_load_balancing_policy_is_dcawaretokenlbp(self): self.connect(self.creds) diff --git a/tests/integration/datatype_utils.py b/tests/integration/datatype_utils.py index 8a1c813baa..e32c36dc7f 100644 --- a/tests/integration/datatype_utils.py +++ b/tests/integration/datatype_utils.py @@ -15,7 +15,7 @@ from decimal import Decimal from datetime import datetime, date, time from uuid import uuid1, uuid4 -import six +import ipaddress from cassandra.util import OrderedMap, Date, Time, sortedset, Duration @@ -92,10 +92,8 @@ def get_sample_data(): elif datatype == 'inet': sample_data[datatype] = ('123.123.123.123', '2001:db8:85a3:8d3:1319:8a2e:370:7348') - if six.PY3: - import ipaddress - sample_data[datatype] += (ipaddress.IPv4Address("123.123.123.123"), - ipaddress.IPv6Address('2001:db8:85a3:8d3:1319:8a2e:370:7348')) + sample_data[datatype] += (ipaddress.IPv4Address("123.123.123.123"), + ipaddress.IPv6Address('2001:db8:85a3:8d3:1319:8a2e:370:7348')) elif datatype == 'int': sample_data[datatype] = 2147483647 diff --git a/tests/integration/standard/test_types.py b/tests/integration/standard/test_types.py index 6e2e9f7328..aea58b80ce 100644 --- a/tests/integration/standard/test_types.py +++ b/tests/integration/standard/test_types.py @@ -13,6 +13,7 @@ # limitations under the License. import unittest +import ipaddress from datetime import datetime import math @@ -60,25 +61,7 @@ def test_can_insert_blob_type_as_string(self): params = ['key1', b'blobbyblob'] query = "INSERT INTO blobstring (a, b) VALUES (%s, %s)" - # In python2, with Cassandra > 2.0, we don't treat the 'byte str' type as a blob, so we'll encode it - # as a string literal and have the following failure. - if six.PY2 and self.cql_version >= (3, 1, 0): - # Blob values can't be specified using string notation in CQL 3.1.0 and - # above which is used by default in Cassandra 2.0. - if self.cass_version >= (2, 1, 0): - msg = r'.*Invalid STRING constant \(.*?\) for "b" of type blob.*' - else: - msg = r'.*Invalid STRING constant \(.*?\) for b of type blob.*' - self.assertRaisesRegex(InvalidRequest, msg, s.execute, query, params) - return - - # In python2, with Cassandra < 2.0, we can manually encode the 'byte str' type as hex for insertion in a blob. - if six.PY2: - cass_params = [params[0], params[1].encode('hex')] - s.execute(query, cass_params) - # In python 3, the 'bytes' type is treated as a blob, so we can correctly encode it with hex notation. - else: - s.execute(query, params) + s.execute(query, params) results = s.execute("SELECT * FROM blobstring")[0] for expected, actual in zip(params, results): @@ -176,10 +159,8 @@ def test_can_insert_primitive_datatypes(self): # verify data result = s.execute("SELECT {0} FROM alltypes WHERE zz=%s".format(single_columns_string), (key,))[0][1] compare_value = data_sample - if six.PY3: - import ipaddress - if isinstance(data_sample, ipaddress.IPv4Address) or isinstance(data_sample, ipaddress.IPv6Address): - compare_value = str(data_sample) + if isinstance(data_sample, ipaddress.IPv4Address) or isinstance(data_sample, ipaddress.IPv6Address): + compare_value = str(data_sample) self.assertEqual(result, compare_value) # try the same thing with a prepared statement diff --git a/tests/unit/advanced/cloud/test_cloud.py b/tests/unit/advanced/cloud/test_cloud.py index a7cd83a8ce..ff3bacee4a 100644 --- a/tests/unit/advanced/cloud/test_cloud.py +++ b/tests/unit/advanced/cloud/test_cloud.py @@ -96,7 +96,7 @@ def clean_tmp_dir(): } # The directory is not writtable.. we expect a permission error - exc = PermissionError if six.PY3 else OSError + exc = PermissionError with self.assertRaises(exc): cloud.get_cloud_config(config) diff --git a/tests/unit/test_policies.py b/tests/unit/test_policies.py index ec004ca9fe..152d041e77 100644 --- a/tests/unit/test_policies.py +++ b/tests/unit/test_policies.py @@ -142,7 +142,7 @@ def host_down(): # make the GIL switch after every instruction, maximizing # the chance of race conditions - check = six.PY2 or '__pypy__' in sys.builtin_module_names + check = '__pypy__' in sys.builtin_module_names if check: original_interval = sys.getcheckinterval() else: diff --git a/tests/unit/test_segment.py b/tests/unit/test_segment.py index f794b38b1d..88770353a0 100644 --- a/tests/unit/test_segment.py +++ b/tests/unit/test_segment.py @@ -22,8 +22,6 @@ def to_bits(b): - if six.PY2: - b = six.byte2int(b) return '{:08b}'.format(b) class SegmentCodecTest(unittest.TestCase): From 65a2d0012a4a55f38fe2e8c457c5236da062d4a1 Mon Sep 17 00:00:00 2001 From: vgali7 Date: Wed, 21 Jun 2023 16:15:22 -0400 Subject: [PATCH 2/5] driver-six --- cassandra/cqltypes.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/cassandra/cqltypes.py b/cassandra/cqltypes.py index 650edd0f68..3545e27120 100644 --- a/cassandra/cqltypes.py +++ b/cassandra/cqltypes.py @@ -66,7 +66,6 @@ log = logging.getLogger(__name__) _number_types = frozenset((int, float)) -long = int def _name_from_hex_string(encoded_name): bin_str = unhexlify(encoded_name) @@ -645,7 +644,7 @@ def serialize(v, protocol_version): raise TypeError('DateType arguments must be a datetime, date, or timestamp') timestamp = v - return int64_pack(long(timestamp)) + return int64_pack(int(timestamp)) class TimestampType(DateType): From 57e2eeaaff7793e6fc0e2b6f97b0e9faaaf657c5 Mon Sep 17 00:00:00 2001 From: vgali7 Date: Fri, 23 Jun 2023 10:46:05 -0400 Subject: [PATCH 3/5] driver-six --- cassandra/concurrent.py | 5 ++--- cassandra/cqltypes.py | 4 ++-- tests/integration/datatype_utils.py | 2 +- tests/integration/standard/test_types.py | 2 +- tests/unit/test_policies.py | 16 +++------------- 5 files changed, 9 insertions(+), 20 deletions(-) diff --git a/cassandra/concurrent.py b/cassandra/concurrent.py index 17b3fe44e6..b699a6f918 100644 --- a/cassandra/concurrent.py +++ b/cassandra/concurrent.py @@ -145,15 +145,14 @@ def _execute(self, idx, statement, params): except Exception as exc: # exc_info with fail_fast to preserve stack trace info when raising on the client thread # (matches previous behavior -- not sure why we wouldn't want stack trace in the other case) - e = exc # If we're not failing fast and all executions are raising, there is a chance of recursing # here as subsequent requests are attempted. If we hit this threshold, schedule this result/retry # and let the event loop thread return. if self._exec_depth < self.max_error_recursion: - self._put_result(e, idx, False) + self._put_result(exc, idx, False) else: - self.session.submit(self._put_result, e, idx, False) + self.session.submit(self._put_result, exc, idx, False) self._exec_depth -= 1 def _on_success(self, result, future, idx): diff --git a/cassandra/cqltypes.py b/cassandra/cqltypes.py index 3545e27120..202e4d2119 100644 --- a/cassandra/cqltypes.py +++ b/cassandra/cqltypes.py @@ -56,7 +56,7 @@ _little_endian_flag = 1 # we always serialize LE import ipaddress -lambda x: x +_ord = lambda x: x apache_cassandra_type_prefix = 'org.apache.cassandra.db.marshal.' @@ -644,7 +644,7 @@ def serialize(v, protocol_version): raise TypeError('DateType arguments must be a datetime, date, or timestamp') timestamp = v - return int64_pack(int(timestamp)) + return int64_pack(timestamp) class TimestampType(DateType): diff --git a/tests/integration/datatype_utils.py b/tests/integration/datatype_utils.py index e32c36dc7f..8cd359baf3 100644 --- a/tests/integration/datatype_utils.py +++ b/tests/integration/datatype_utils.py @@ -14,8 +14,8 @@ from decimal import Decimal from datetime import datetime, date, time -from uuid import uuid1, uuid4 import ipaddress +from uuid import uuid1, uuid4 from cassandra.util import OrderedMap, Date, Time, sortedset, Duration diff --git a/tests/integration/standard/test_types.py b/tests/integration/standard/test_types.py index aea58b80ce..f02d624b71 100644 --- a/tests/integration/standard/test_types.py +++ b/tests/integration/standard/test_types.py @@ -12,8 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. -import unittest import ipaddress +import unittest from datetime import datetime import math diff --git a/tests/unit/test_policies.py b/tests/unit/test_policies.py index 152d041e77..95420fa016 100644 --- a/tests/unit/test_policies.py +++ b/tests/unit/test_policies.py @@ -142,26 +142,16 @@ def host_down(): # make the GIL switch after every instruction, maximizing # the chance of race conditions - check = '__pypy__' in sys.builtin_module_names - if check: - original_interval = sys.getcheckinterval() - else: - original_interval = sys.getswitchinterval() + original_interval = sys.getswitchinterval() try: - if check: - sys.setcheckinterval(0) - else: - sys.setswitchinterval(0.0001) + sys.setswitchinterval(0.0001) for t in threads: t.start() for t in threads: t.join() finally: - if check: - sys.setcheckinterval(original_interval) - else: - sys.setswitchinterval(original_interval) + sys.setswitchinterval(original_interval) if errors: self.fail("Saw errors: %s" % (errors,)) From e8718498e080132f3139a74d7f92418df3fbc321 Mon Sep 17 00:00:00 2001 From: vgali7 Date: Wed, 5 Jul 2023 15:18:40 -0400 Subject: [PATCH 4/5] timestamp int fix --- cassandra/cqltypes.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cassandra/cqltypes.py b/cassandra/cqltypes.py index 202e4d2119..901db6700b 100644 --- a/cassandra/cqltypes.py +++ b/cassandra/cqltypes.py @@ -1,4 +1,4 @@ -# Copyright DataStax, Inc. + # Copyright DataStax, Inc. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. @@ -644,7 +644,7 @@ def serialize(v, protocol_version): raise TypeError('DateType arguments must be a datetime, date, or timestamp') timestamp = v - return int64_pack(timestamp) + return int64_pack(int(timestamp)) class TimestampType(DateType): From 06720ece1c9849fd3229c5c4ce1245acaeb40e2d Mon Sep 17 00:00:00 2001 From: vgali7 Date: Thu, 6 Jul 2023 16:13:26 -0400 Subject: [PATCH 5/5] compatibility with python 3.7 only --- appveyor.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/appveyor.yml b/appveyor.yml index d1daaa6ec6..f8a3fd7660 100644 --- a/appveyor.yml +++ b/appveyor.yml @@ -1,9 +1,6 @@ environment: matrix: - - PYTHON: "C:\\Python27-x64" - cassandra_version: 3.11.2 - ci_type: standard - - PYTHON: "C:\\Python35-x64" + - PYTHON: "C:\\Python37-x64" cassandra_version: 3.11.2 ci_type: standard os: Visual Studio 2015