Skip to content

Commit 6320813

Browse files
committed
driver-six
1 parent 8c41066 commit 6320813

File tree

22 files changed

+84
-207
lines changed

22 files changed

+84
-207
lines changed

cassandra/auth.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ def get_initial_challenge(self):
278278
def evaluate_challenge(self, challenge):
279279
if challenge == six.b('PLAIN-START'):
280280
data = "\x00%s\x00%s" % (self.username, self.password)
281-
return data if six.PY2 else data.encode()
281+
return data.encode()
282282
raise Exception('Did not receive a valid challenge response from server')
283283

284284

cassandra/cluster.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,6 @@
107107
except ImportError:
108108
from cassandra.util import WeakSet # NOQA
109109

110-
if six.PY3:
111-
long = int
112110

113111
def _is_eventlet_monkey_patched():
114112
if 'eventlet.patcher' not in sys.modules:
@@ -3345,10 +3343,6 @@ def user_type_registered(self, keyspace, user_type, klass):
33453343
'User type %s does not exist in keyspace %s' % (user_type, keyspace))
33463344

33473345
field_names = type_meta.field_names
3348-
if six.PY2:
3349-
# go from unicode to string to avoid decode errors from implicit
3350-
# decode when formatting non-ascii values
3351-
field_names = [fn.encode('utf-8') for fn in field_names]
33523346

33533347
def encode(val):
33543348
return '{ %s }' % ' , '.join('%s : %s' % (

cassandra/compat.py

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

15-
import six
16-
17-
if six.PY2:
18-
from collections import Mapping
19-
elif six.PY3:
20-
from collections.abc import Mapping
15+
from collections.abc import Mapping

cassandra/concurrent.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ def _execute(self, idx, statement, params):
145145
except Exception as exc:
146146
# exc_info with fail_fast to preserve stack trace info when raising on the client thread
147147
# (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
148+
e = exc
149149

150150
# If we're not failing fast and all executions are raising, there is a chance of recursing
151151
# 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):
165165

166166
@staticmethod
167167
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
168+
raise exc
173169

174170

175171
class ConcurrentExecutorGenResults(_ConcurrentExecutor):

cassandra/connection.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -605,11 +605,8 @@ def wrapper(self, *args, **kwargs):
605605

606606
DEFAULT_CQL_VERSION = '3.0.0'
607607

608-
if six.PY3:
609-
def int_from_buf_item(i):
610-
return i
611-
else:
612-
int_from_buf_item = ord
608+
def int_from_buf_item(i):
609+
return i
613610

614611

615612
class _ConnectionIOBuffer(object):

cassandra/cqlengine/__init__.py

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

15-
import six
16-
1715

1816
# Caching constants.
1917
CACHING_ALL = "ALL"
@@ -31,7 +29,5 @@ class ValidationError(CQLEngineException):
3129

3230

3331
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')
32+
__str__ = lambda x: x.__unicode__()
33+

cassandra/cqltypes.py

Lines changed: 25 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,9 @@
5454
from cassandra import util
5555

5656
_little_endian_flag = 1 # we always serialize LE
57-
if six.PY3:
58-
import ipaddress
57+
import ipaddress
5958

60-
_ord = ord if six.PY2 else lambda x: x
59+
lambda x: x
6160

6261
apache_cassandra_type_prefix = 'org.apache.cassandra.db.marshal.'
6362

@@ -66,16 +65,12 @@
6665

6766
log = logging.getLogger(__name__)
6867

69-
if six.PY3:
70-
_number_types = frozenset((int, float))
71-
long = int
68+
_number_types = frozenset((int, float))
69+
long = int
7270

73-
def _name_from_hex_string(encoded_name):
74-
bin_str = unhexlify(encoded_name)
75-
return bin_str.decode('ascii')
76-
else:
77-
_number_types = frozenset((int, long, float))
78-
_name_from_hex_string = unhexlify
71+
def _name_from_hex_string(encoded_name):
72+
bin_str = unhexlify(encoded_name)
73+
return bin_str.decode('ascii')
7974

8075

8176
def trim_if_startswith(s, prefix):
@@ -383,8 +378,6 @@ def apply_parameters(cls, subtypes, names=None):
383378
raise ValueError("%s types require %d subtypes (%d given)"
384379
% (cls.typename, cls.num_subtypes, len(subtypes)))
385380
newname = cls.cass_parameterized_type_with(subtypes)
386-
if six.PY2 and isinstance(newname, unicode):
387-
newname = newname.encode('utf-8')
388381
return type(newname, (cls,), {'subtypes': subtypes, 'cassname': cls.cassname, 'fieldnames': names})
389382

390383
@classmethod
@@ -415,16 +408,10 @@ class _UnrecognizedType(_CassandraType):
415408
num_subtypes = 'UNKNOWN'
416409

417410

418-
if six.PY3:
419-
def mkUnrecognizedType(casstypename):
420-
return CassandraTypeType(casstypename,
421-
(_UnrecognizedType,),
422-
{'typename': "'%s'" % casstypename})
423-
else:
424-
def mkUnrecognizedType(casstypename): # noqa
425-
return CassandraTypeType(casstypename.encode('utf8'),
426-
(_UnrecognizedType,),
427-
{'typename': "'%s'" % casstypename})
411+
def mkUnrecognizedType(casstypename):
412+
return CassandraTypeType(casstypename,
413+
(_UnrecognizedType,),
414+
{'typename': "'%s'" % casstypename})
428415

429416

430417
class BytesType(_CassandraType):
@@ -500,25 +487,21 @@ def serialize(byts, protocol_version):
500487
return int8_pack(byts)
501488

502489

503-
if six.PY2:
504-
class AsciiType(_CassandraType):
505-
typename = 'ascii'
506-
empty_binary_ok = True
507-
else:
508-
class AsciiType(_CassandraType):
509-
typename = 'ascii'
510-
empty_binary_ok = True
511490

512-
@staticmethod
513-
def deserialize(byts, protocol_version):
514-
return byts.decode('ascii')
491+
class AsciiType(_CassandraType):
492+
typename = 'ascii'
493+
empty_binary_ok = True
515494

516-
@staticmethod
517-
def serialize(var, protocol_version):
518-
try:
519-
return var.encode('ascii')
520-
except UnicodeDecodeError:
521-
return var
495+
@staticmethod
496+
def deserialize(byts, protocol_version):
497+
return byts.decode('ascii')
498+
499+
@staticmethod
500+
def serialize(var, protocol_version):
501+
try:
502+
return var.encode('ascii')
503+
except UnicodeDecodeError:
504+
return var
522505

523506

524507
class FloatType(_CassandraType):
@@ -603,7 +586,7 @@ def serialize(addr, protocol_version):
603586
# since we've already determined the AF
604587
return socket.inet_aton(addr)
605588
except:
606-
if six.PY3 and isinstance(addr, (ipaddress.IPv4Address, ipaddress.IPv6Address)):
589+
if isinstance(addr, (ipaddress.IPv4Address, ipaddress.IPv6Address)):
607590
return addr.packed
608591
raise ValueError("can't interpret %r as an inet address" % (addr,))
609592

@@ -975,8 +958,6 @@ class UserType(TupleType):
975958
def make_udt_class(cls, keyspace, udt_name, field_names, field_types):
976959
assert len(field_names) == len(field_types)
977960

978-
if six.PY2 and isinstance(udt_name, unicode):
979-
udt_name = udt_name.encode('utf-8')
980961

981962
instance = cls._cache.get((keyspace, udt_name))
982963
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):
992973

993974
@classmethod
994975
def evict_udt_class(cls, keyspace, udt_name):
995-
if six.PY2 and isinstance(udt_name, unicode):
996-
udt_name = udt_name.encode('utf-8')
997976
try:
998977
del cls._cache[(keyspace, udt_name)]
999978
except KeyError:

cassandra/datastax/graph/graphson.py

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,7 @@ class Int64TypeIO(IntegerTypeIO):
164164

165165
@classmethod
166166
def deserialize(cls, value, reader=None):
167-
if six.PY3:
168-
return value
169-
return long(value)
167+
return value
170168

171169

172170
class FloatTypeIO(GraphSONTypeIO):
@@ -274,8 +272,7 @@ class BlobTypeIO(GraphSONTypeIO):
274272
@classmethod
275273
def serialize(cls, value, writer=None):
276274
value = base64.b64encode(value)
277-
if six.PY3:
278-
value = value.decode('utf-8')
275+
value = value.decode('utf-8')
279276
return value
280277

281278
@classmethod
@@ -845,12 +842,8 @@ class GraphSON1Serializer(_BaseGraphSONSerializer):
845842
GraphSON1Serializer.register(ipaddress.IPv4Address, InetTypeIO)
846843
GraphSON1Serializer.register(ipaddress.IPv6Address, InetTypeIO)
847844

848-
if six.PY2:
849-
GraphSON1Serializer.register(buffer, ByteBufferTypeIO)
850-
GraphSON1Serializer.register(unicode, TextTypeIO)
851-
else:
852-
GraphSON1Serializer.register(memoryview, ByteBufferTypeIO)
853-
GraphSON1Serializer.register(bytes, ByteBufferTypeIO)
845+
GraphSON1Serializer.register(memoryview, ByteBufferTypeIO)
846+
GraphSON1Serializer.register(bytes, ByteBufferTypeIO)
854847

855848

856849
class _BaseGraphSONDeserializer(object):
@@ -922,9 +915,7 @@ def deserialize_int(cls, value):
922915

923916
@classmethod
924917
def deserialize_bigint(cls, value):
925-
if six.PY3:
926-
return cls.deserialize_int(value)
927-
return long(value)
918+
return cls.deserialize_int(value)
928919

929920
@classmethod
930921
def deserialize_double(cls, value):
@@ -1007,8 +998,6 @@ def serialize(self, value, writer=None):
1007998

1008999

10091000
GraphSON2Serializer.register(int, IntegerTypeIO)
1010-
if six.PY2:
1011-
GraphSON2Serializer.register(long, IntegerTypeIO)
10121001

10131002

10141003
class GraphSON2Deserializer(_BaseGraphSONDeserializer):

cassandra/datastax/insights/reporter.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -199,9 +199,9 @@ def _get_startup_data(self):
199199
},
200200
'platformInfo': {
201201
'os': {
202-
'name': uname_info.system if six.PY3 else uname_info[0],
203-
'version': uname_info.release if six.PY3 else uname_info[2],
204-
'arch': uname_info.machine if six.PY3 else uname_info[4]
202+
'name': uname_info.system,
203+
'version': uname_info.release,
204+
'arch': uname_info.machine
205205
},
206206
'cpus': {
207207
'length': multiprocessing.cpu_count(),

cassandra/encoder.py

Lines changed: 18 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,7 @@
3232
from cassandra.util import (OrderedDict, OrderedMap, OrderedMapSerializedKey,
3333
sortedset, Time, Date, Point, LineString, Polygon)
3434

35-
if six.PY3:
36-
import ipaddress
37-
38-
if six.PY3:
39-
long = int
35+
import ipaddress
4036

4137

4238
def cql_quote(term):
@@ -97,21 +93,14 @@ def __init__(self):
9793
Polygon: self.cql_encode_str_quoted
9894
}
9995

100-
if six.PY2:
101-
self.mapping.update({
102-
unicode: self.cql_encode_unicode,
103-
buffer: self.cql_encode_bytes,
104-
long: self.cql_encode_object,
105-
types.NoneType: self.cql_encode_none,
106-
})
107-
else:
108-
self.mapping.update({
109-
memoryview: self.cql_encode_bytes,
110-
bytes: self.cql_encode_bytes,
111-
type(None): self.cql_encode_none,
112-
ipaddress.IPv4Address: self.cql_encode_ipaddress,
113-
ipaddress.IPv6Address: self.cql_encode_ipaddress
114-
})
96+
97+
self.mapping.update({
98+
memoryview: self.cql_encode_bytes,
99+
bytes: self.cql_encode_bytes,
100+
type(None): self.cql_encode_none,
101+
ipaddress.IPv4Address: self.cql_encode_ipaddress,
102+
ipaddress.IPv6Address: self.cql_encode_ipaddress
103+
})
115104

116105
def cql_encode_none(self, val):
117106
"""
@@ -134,16 +123,9 @@ def cql_encode_str(self, val):
134123
def cql_encode_str_quoted(self, val):
135124
return "'%s'" % val
136125

137-
if six.PY3:
138-
def cql_encode_bytes(self, val):
139-
return (b'0x' + hexlify(val)).decode('utf-8')
140-
elif sys.version_info >= (2, 7):
141-
def cql_encode_bytes(self, val): # noqa
142-
return b'0x' + hexlify(val)
143-
else:
144-
# python 2.6 requires string or read-only buffer for hexlify
145-
def cql_encode_bytes(self, val): # noqa
146-
return b'0x' + hexlify(buffer(val))
126+
def cql_encode_bytes(self, val):
127+
return (b'0x' + hexlify(val)).decode('utf-8')
128+
147129

148130
def cql_encode_object(self, val):
149131
"""
@@ -240,10 +222,9 @@ def cql_encode_all_types(self, val, as_text_type=False):
240222
return encoded.decode('utf-8')
241223
return encoded
242224

243-
if six.PY3:
244-
def cql_encode_ipaddress(self, val):
245-
"""
246-
Converts an ipaddress (IPV4Address, IPV6Address) to a CQL string. This
247-
is suitable for ``inet`` type columns.
248-
"""
249-
return "'%s'" % val.compressed
225+
def cql_encode_ipaddress(self, val):
226+
"""
227+
Converts an ipaddress (IPV4Address, IPV6Address) to a CQL string. This
228+
is suitable for ``inet`` type columns.
229+
"""
230+
return "'%s'" % val.compressed

0 commit comments

Comments
 (0)