Skip to content

Commit b2a0b57

Browse files
author
Gus Monod
authored
Merge pull request #51 from gusmonod/drop-2.7
Drop 2.7 support
2 parents 29b0c11 + 5a0e834 commit b2a0b57

15 files changed

Lines changed: 106 additions & 164 deletions

comdb2/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"""This package provides Python interfaces to Comdb2 databases.
1313
1414
Two different Python submodules are provided for interacting with Comdb2
15-
databases. Both submodules work from Python 2.7+ and from Python 3.5+.
15+
databases. Both submodules work from Python 3.6.
1616
1717
`comdb2.dbapi2` provides an interface that conforms to `the Python Database API
1818
Specification v2.0 <https://www.python.org/dev/peps/pep-0249/>`_. If you're

comdb2/_about.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
__all__ = ['__version__']
2-
__version__ = "1.4.1"
2+
__version__ = "1.5.0"

comdb2/_ccdb2.pyx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ from cpython.mem cimport PyMem_Malloc, PyMem_Free
2222
import datetime
2323

2424
from pytz import timezone, UTC
25-
import six
2625

2726
from ._cdb2_types import Error, Effects, DatetimeUs
2827
from . cimport _cdb2api as lib
@@ -113,7 +112,7 @@ cdef class _ParameterValue(object):
113112
self.size = 0
114113
self.data = NULL
115114
return
116-
elif isinstance(obj, six.integer_types):
115+
elif isinstance(obj, int):
117116
self.type = lib.CDB2_INTEGER
118117
self.owner = None
119118
self.size = sizeof(long long)
@@ -167,7 +166,7 @@ cdef class _ParameterValue(object):
167166
param_name,
168167
exc_desc,
169168
)
170-
six.raise_from(Error(lib.CDB2ERR_CONV_FAIL, errmsg), exc)
169+
raise Error(lib.CDB2ERR_CONV_FAIL, errmsg) from exc
171170
else:
172171
errmsg = "Can't map %s value %r for parameter '%s' to a Comdb2 type" % (
173172
type(obj).__name__,
@@ -248,7 +247,7 @@ cdef _column_value(lib.cdb2_hndl_tp *hndl, int col):
248247

249248
if exc is not None:
250249
errmsg += _describe_exception(exc)
251-
six.raise_from(Error(lib.CDB2ERR_CONV_FAIL, errmsg), exc)
250+
raise Error(lib.CDB2ERR_CONV_FAIL, errmsg) from exc
252251
else:
253252
errmsg += "Unsupported column type"
254253
raise Error(lib.CDB2ERR_NOTSUPPORTED, errmsg)
@@ -289,7 +288,7 @@ cdef class _Cursor(object):
289288
ret = self.row_class(ret)
290289
except Exception as e:
291290
errmsg = "Instantiating row failed: " + _describe_exception(e)
292-
six.raise_from(Error(lib.CDB2ERR_UNKNOWN, errmsg), e)
291+
raise Error(lib.CDB2ERR_UNKNOWN, errmsg) from e
293292
return ret
294293

295294

@@ -393,7 +392,7 @@ cdef class Handle(object):
393392
row_class = self._row_factory(self.column_names())
394393
except Exception as e:
395394
errmsg = "row_factory call failed: " + _describe_exception(e)
396-
six.raise_from(Error(lib.CDB2ERR_UNKNOWN, errmsg), e)
395+
raise Error(lib.CDB2ERR_UNKNOWN, errmsg) from e
397396

398397
cdef _Cursor ret = _Cursor.__new__(_Cursor)
399398
ret.handle = self

comdb2/_cdb2_types.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111

1212
from collections import namedtuple
1313
from datetime import datetime
14-
import six
1514

1615
__name__ = 'comdb2.cdb2'
1716

@@ -36,11 +35,11 @@ class Error(RuntimeError):
3635
after the failed call.
3736
"""
3837
def __init__(self, error_code, error_message):
39-
if not(isinstance(error_message, six.text_type)):
38+
if not(isinstance(error_message, str)):
4039
error_message = _errstr(error_message)
4140
self.error_code = error_code
4241
self.error_message = error_message
43-
super(Error, self).__init__(error_code, error_message)
42+
super().__init__(error_code, error_message)
4443

4544

4645
class Effects(namedtuple('Effects',
@@ -94,13 +93,13 @@ def fromdatetime(cls, dt):
9493
dt.tzinfo, **kwargs)
9594

9695
def __add__(self, other):
97-
ret = super(DatetimeUs, self).__add__(other)
96+
ret = super().__add__(other)
9897
if isinstance(ret, datetime):
9998
return DatetimeUs.fromdatetime(ret)
10099
return ret # must be a timedelta
101100

102101
def __sub__(self, other):
103-
ret = super(DatetimeUs, self).__sub__(other)
102+
ret = super().__sub__(other)
104103
if isinstance(ret, datetime):
105104
return DatetimeUs.fromdatetime(ret)
106105
return ret # must be a timedelta
@@ -110,20 +109,20 @@ def __radd__(self, other):
110109

111110
@classmethod
112111
def now(cls, tz=None):
113-
ret = super(DatetimeUs, cls).now(tz)
112+
ret = super().now(tz)
114113
return DatetimeUs.fromdatetime(ret)
115114

116115
@classmethod
117116
def fromtimestamp(cls, timestamp, tz=None):
118-
ret = super(DatetimeUs, cls).fromtimestamp(timestamp, tz)
117+
ret = super().fromtimestamp(timestamp, tz)
119118
return DatetimeUs.fromdatetime(ret)
120119

121120
def astimezone(self, *args, **kwargs):
122-
ret = super(DatetimeUs, self).astimezone(*args, **kwargs)
121+
ret = super().astimezone(*args, **kwargs)
123122
return DatetimeUs.fromdatetime(ret)
124123

125124
def replace(self, *args, **kwargs):
126125
# Before Python 3.7, it is effectively implementation dependent whether
127126
# this returns a DatetimeUs or a datetime.
128-
dt = super(DatetimeUs, self).replace(*args, **kwargs)
127+
dt = super().replace(*args, **kwargs)
129128
return self.fromdatetime(dt)

comdb2/cdb2.py

Lines changed: 51 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@
112112
NULL ``None``
113113
integer `int`
114114
real `float`
115-
blob `six.binary_type` (aka `bytes` in Python 3, ``str`` in Python 2)
116-
text `six.text_type` (aka `str` in Python 3, ``unicode`` in Python 2)
115+
blob `bytes`
116+
text `str`
117117
datetime `datetime.datetime`
118118
datetimeus `DatetimeUs`
119119
============ ================================================================
@@ -127,7 +127,6 @@
127127
problems for new users.
128128
Make sure to carefully read :ref:`String and Blob Types` on that page.
129129
"""
130-
from __future__ import absolute_import, unicode_literals
131130

132131
from ._cdb2_types import Error, Effects, DatetimeUs
133132
from ._ccdb2 import Handle as CHandle
@@ -136,40 +135,40 @@
136135
'ERROR_CODE', 'TYPE', 'HANDLE_FLAGS']
137136

138137
# Pull all comdb2 error codes from cdb2api.h into our namespace
139-
ERROR_CODE = {u'CONNECT_ERROR' : -1,
140-
u'NOTCONNECTED' : -2,
141-
u'PREPARE_ERROR' : -3,
142-
u'IO_ERROR' : -4,
143-
u'INTERNAL' : -5,
144-
u'NOSTATEMENT' : -6,
145-
u'BADCOLUMN' : -7,
146-
u'BADSTATE' : -8,
147-
u'ASYNCERR' : -9,
148-
u'INVALID_ID' : -12,
149-
u'RECORD_OUT_OF_RANGE' : -13,
150-
u'REJECTED' : -15,
151-
u'STOPPED' : -16,
152-
u'BADREQ' : -17,
153-
u'DBCREATE_FAILED' : -18,
154-
u'THREADPOOL_INTERNAL' : -20,
155-
u'READONLY' : -21,
156-
u'NOMASTER' : -101,
157-
u'UNTAGGED_DATABASE' : -102,
158-
u'CONSTRAINTS' : -103,
159-
u'DEADLOCK' : 203,
160-
u'TRAN_IO_ERROR' : -105,
161-
u'ACCESS' : -106,
162-
u'TRAN_MODE_UNSUPPORTED' : -107,
163-
u'VERIFY_ERROR' : 2,
164-
u'FKEY_VIOLATION' : 3,
165-
u'NULL_CONSTRAINT' : 4,
166-
u'CONV_FAIL' : 113,
167-
u'NONKLESS' : 114,
168-
u'MALLOC' : 115,
169-
u'NOTSUPPORTED' : 116,
170-
u'DUPLICATE' : 299,
171-
u'TZNAME_FAIL' : 401,
172-
u'UNKNOWN' : 300,
138+
ERROR_CODE = {'CONNECT_ERROR' : -1,
139+
'NOTCONNECTED' : -2,
140+
'PREPARE_ERROR' : -3,
141+
'IO_ERROR' : -4,
142+
'INTERNAL' : -5,
143+
'NOSTATEMENT' : -6,
144+
'BADCOLUMN' : -7,
145+
'BADSTATE' : -8,
146+
'ASYNCERR' : -9,
147+
'INVALID_ID' : -12,
148+
'RECORD_OUT_OF_RANGE' : -13,
149+
'REJECTED' : -15,
150+
'STOPPED' : -16,
151+
'BADREQ' : -17,
152+
'DBCREATE_FAILED' : -18,
153+
'THREADPOOL_INTERNAL' : -20,
154+
'READONLY' : -21,
155+
'NOMASTER' : -101,
156+
'UNTAGGED_DATABASE' : -102,
157+
'CONSTRAINTS' : -103,
158+
'DEADLOCK' : 203,
159+
'TRAN_IO_ERROR' : -105,
160+
'ACCESS' : -106,
161+
'TRAN_MODE_UNSUPPORTED' : -107,
162+
'VERIFY_ERROR' : 2,
163+
'FKEY_VIOLATION' : 3,
164+
'NULL_CONSTRAINT' : 4,
165+
'CONV_FAIL' : 113,
166+
'NONKLESS' : 114,
167+
'MALLOC' : 115,
168+
'NOTSUPPORTED' : 116,
169+
'DUPLICATE' : 299,
170+
'TZNAME_FAIL' : 401,
171+
'UNKNOWN' : 300,
173172
}
174173
"""This dict maps all known Comdb2 error names to their respective values.
175174
@@ -180,15 +179,15 @@
180179
"""
181180

182181
# Pull comdb2 column types from cdb2api.h into our namespace
183-
TYPE = {u'INTEGER' : 1,
184-
u'REAL' : 2,
185-
u'CSTRING' : 3,
186-
u'BLOB' : 4,
187-
u'DATETIME' : 6,
188-
u'INTERVALYM' : 7,
189-
u'INTERVALDS' : 8,
190-
u'DATETIMEUS' : 9,
191-
u'INTERVALDSUS' : 10,
182+
TYPE = {'INTEGER' : 1,
183+
'REAL' : 2,
184+
'CSTRING' : 3,
185+
'BLOB' : 4,
186+
'DATETIME' : 6,
187+
'INTERVALYM' : 7,
188+
'INTERVALDS' : 8,
189+
'DATETIMEUS' : 9,
190+
'INTERVALDSUS' : 10,
192191
}
193192
"""This dict maps all known Comdb2 types to their enumeration value.
194193
@@ -198,11 +197,11 @@
198197
"""
199198

200199
# Pull comdb2 handle flags from cdb2api.h into our namespace
201-
HANDLE_FLAGS = {u'READ_INTRANS_RESULTS' : 2,
202-
u'DIRECT_CPU' : 4,
203-
u'RANDOM' : 8,
204-
u'RANDOMROOM' : 16,
205-
u'ROOM' : 32,
200+
HANDLE_FLAGS = {'READ_INTRANS_RESULTS' : 2,
201+
'DIRECT_CPU' : 4,
202+
'RANDOM' : 8,
203+
'RANDOMROOM' : 16,
204+
'ROOM' : 32,
206205
}
207206
"""This dict maps all known Comdb2 flags to their enumeration value.
208207
@@ -211,7 +210,7 @@
211210
"""
212211

213212

214-
class Handle(object):
213+
class Handle:
215214
"""Represents a connection to a database.
216215
217216
By default, the connection will be made to the cluster configured as the

comdb2/dbapi2.py

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@
138138
NULL ``None``
139139
integer `int`
140140
real `float`
141-
blob `six.binary_type` (aka `bytes` in Python 3, ``str`` in Python 2)
142-
text `six.text_type` (aka `str` in Python 3, ``unicode`` in Python 2)
141+
blob `bytes`
142+
text `str`
143143
datetime `datetime.datetime`
144144
datetimeus `DatetimeUs`
145145
============ ================================================================
@@ -239,14 +239,12 @@
239239
`Connection.cursor` is called, we call `Cursor.close` on any existing, open
240240
cursor for that connection.
241241
"""
242-
from __future__ import absolute_import, unicode_literals
243242

244243
import functools
245244
import itertools
246245
import weakref
247246
import datetime
248247
import re
249-
import six
250248

251249
from . import cdb2
252250

@@ -298,13 +296,13 @@
298296
\s* # then skip over any whitespace
299297
(\w+) # and capture the first word
300298
""",
301-
re.VERBOSE | re.DOTALL | (0 if six.PY2 else re.ASCII),
299+
re.VERBOSE | re.DOTALL | re.ASCII,
302300
)
303301
_VALID_SP_NAME = re.compile(r'^[A-Za-z0-9_.]+$')
304302

305303

306304
@functools.total_ordering
307-
class _TypeObject(object):
305+
class _TypeObject:
308306
def __init__(self, *value_names):
309307
self.value_names = value_names
310308
self.values = [cdb2.TYPE[v] for v in value_names]
@@ -320,7 +318,7 @@ def __repr__(self):
320318

321319

322320
def _binary(string):
323-
if isinstance(string, six.text_type):
321+
if isinstance(string, str):
324322
return string.encode('utf-8')
325323
return bytes(string)
326324

@@ -350,10 +348,7 @@ def _binary(string):
350348
TimestampFromTicks = Timestamp.fromtimestamp
351349
TimestampUsFromTicks = TimestampUs.fromtimestamp
352350

353-
try:
354-
UserException = StandardError # Python 2
355-
except NameError:
356-
UserException = Exception # Python 3
351+
UserException = Exception
357352

358353

359354
class Error(UserException):
@@ -526,8 +521,8 @@ def _raise_wrapped_exception(exc):
526521
code = exc.error_code
527522
msg = '%s (cdb2api rc %d)' % (exc.error_message, code)
528523
if "null constraint violation" in msg:
529-
six.raise_from(NonNullConstraintError(msg), exc) # DRQS 86013831
530-
six.raise_from(_EXCEPTION_BY_RC.get(code, OperationalError)(msg), exc)
524+
raise NonNullConstraintError(msg) from exc # DRQS 86013831
525+
raise _EXCEPTION_BY_RC.get(code, OperationalError)(msg) from exc
531526

532527

533528
def _sql_operation(sql):
@@ -566,7 +561,7 @@ def connect(*args, **kwargs):
566561
return Connection(*args, **kwargs)
567562

568563

569-
class Connection(object):
564+
class Connection:
570565
"""Represents a connection to a Comdb2 database.
571566
572567
By default, the connection will be made to the cluster configured as the
@@ -774,7 +769,7 @@ def cursor(self):
774769
NotSupportedError = NotSupportedError
775770

776771

777-
class Cursor(object):
772+
class Cursor:
778773
"""Class used to send requests through a database connection.
779774
780775
This class is not meant to be instantiated directly; it should always be
@@ -1028,10 +1023,10 @@ def _execute(self, operation, sql, parameters=None):
10281023
sql = sql % {name: "@" + name for name in parameters}
10291024
except KeyError as keyerr:
10301025
msg = "No value provided for parameter %s" % keyerr
1031-
six.raise_from(InterfaceError(msg), keyerr)
1026+
raise InterfaceError(msg) from keyerr
10321027
except Exception as exc:
10331028
msg = "Invalid Python format string for query"
1034-
six.raise_from(InterfaceError(msg), exc)
1029+
raise InterfaceError(msg) from exc
10351030

10361031
if _operation_ends_transaction(operation):
10371032
self._conn._in_transaction = False # txn ends, even on failure

comdb2/factories.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
A factory function will be called with a list of column names, and must return
2222
a callable that will be called once per row with a list of column values.
2323
"""
24-
from __future__ import unicode_literals
2524
from collections import namedtuple
2625
from collections import Counter
2726

0 commit comments

Comments
 (0)