|
22 | 22 | from uuid import UUID |
23 | 23 | import warnings |
24 | 24 |
|
25 | | -try: |
26 | | - from cStringIO import StringIO |
27 | | -except ImportError: |
28 | | - from StringIO import StringIO # NOQA |
| 25 | +import six |
| 26 | +from six.moves import cStringIO as StringIO |
| 27 | +from six.moves import xrange |
29 | 28 |
|
30 | 29 | from cassandra.marshal import (int8_pack, int8_unpack, uint16_pack, uint16_unpack, |
31 | 30 | int32_pack, int32_unpack, int64_pack, int64_unpack, |
|
35 | 34 |
|
36 | 35 | apache_cassandra_type_prefix = 'org.apache.cassandra.db.marshal.' |
37 | 36 |
|
38 | | -_number_types = frozenset((int, long, float)) |
| 37 | +## Python 3 support ######### |
| 38 | +if six.PY3: |
| 39 | + _number_types = frozenset((int, float)) |
| 40 | +else: |
| 41 | + _number_types = frozenset((int, long, float)) |
| 42 | +############################# |
39 | 43 |
|
40 | 44 | try: |
41 | 45 | from blist import sortedset |
@@ -482,7 +486,7 @@ class DateType(_CassandraType): |
482 | 486 |
|
483 | 487 | @classmethod |
484 | 488 | def validate(cls, date): |
485 | | - if isinstance(date, basestring): |
| 489 | + if isinstance(date, six.string_types): |
486 | 490 | date = cls.interpret_datestring(date) |
487 | 491 | return date |
488 | 492 |
|
@@ -624,7 +628,7 @@ def deserialize_safe(cls, byts): |
624 | 628 |
|
625 | 629 | @classmethod |
626 | 630 | def serialize_safe(cls, items): |
627 | | - if isinstance(items, basestring): |
| 631 | + if isinstance(items, six.string_types): |
628 | 632 | raise TypeError("Received a string for a type that expects a sequence") |
629 | 633 |
|
630 | 634 | subtype, = cls.subtypes |
@@ -733,7 +737,7 @@ def serialize_safe(cls, val): |
733 | 737 |
|
734 | 738 |
|
735 | 739 | def is_counter_type(t): |
736 | | - if isinstance(t, basestring): |
| 740 | + if isinstance(t, six.string_types): |
737 | 741 | t = lookup_casstype(t) |
738 | 742 | return issubclass(t, CounterColumnType) |
739 | 743 |
|
|
0 commit comments