Skip to content

Commit b120dd8

Browse files
committed
Cease support for Python 2 and 3.5, minor optimizations
1 parent 9101cd1 commit b120dd8

28 files changed

+131
-172
lines changed

.bumpversion.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[bumpversion]
2-
current_version = 2.0.3
2+
current_version = 3.0.0
33

44
[bumpversion:file:setup.py]
55
search = __version__ = '{current_version}'

.github/workflows/publish_on_pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
python: ['3.9', '2.7']
13+
python: ['3.9']
1414

1515
steps:
1616
- uses: actions/checkout@v2

.github/workflows/test_with_tox.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ jobs:
77
runs-on: ubuntu-latest
88
strategy:
99
matrix:
10-
python: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']
10+
python: ['3.6', '3.7', '3.8', '3.9', '3.10']
1111

1212
steps:
1313
- uses: actions/checkout@v2

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ to a database that can be used in all kinds of multi-threaded environments.
77
The suite supports DB-API 2 compliant database interfaces
88
and the classic PyGreSQL interface.
99

10-
The current version 2.0.3 of DBUtils supports Python versions 2.7 and 3.5 to 3.10.
10+
The current version 3.0.0 of DBUtils supports Python versions 3.6 to 3.10.
1111

12-
**Please have a look at the [changelog](https://webwareforpython.github.io/DBUtils/changelog.html), because there are some breaking changes in version 2.0.**
12+
**Please have a look at the [changelog](https://webwareforpython.github.io/DBUtils/changelog.html), because there were some breaking changes in version 2.0.**
1313

1414
The DBUtils home page can be found at https://webwareforpython.github.io/DBUtils/

dbutils/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@
55
'simple_pooled_pg', 'steady_pg', 'pooled_pg', 'persistent_pg',
66
'simple_pooled_db', 'steady_db', 'pooled_db', 'persistent_db']
77

8-
__version__ = '2.0.3'
8+
__version__ = '3.0.0'

dbutils/pooled_db.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -422,8 +422,7 @@ def __getattr__(self, name):
422422
"""Proxy all members of the class."""
423423
if self._con:
424424
return getattr(self._con, name)
425-
else:
426-
raise InvalidConnection
425+
raise InvalidConnection
427426

428427
def __del__(self):
429428
"""Delete the pooled connection."""
@@ -455,14 +454,12 @@ def __init__(self, con):
455454
def __lt__(self, other):
456455
if self.con._transaction == other.con._transaction:
457456
return self.shared < other.shared
458-
else:
459-
return not self.con._transaction
457+
return not self.con._transaction
460458

461459
def __le__(self, other):
462460
if self.con._transaction == other.con._transaction:
463461
return self.shared <= other.shared
464-
else:
465-
return not self.con._transaction
462+
return not self.con._transaction
466463

467464
def __eq__(self, other):
468465
return (self.con._transaction == other.con._transaction
@@ -517,8 +514,7 @@ def __getattr__(self, name):
517514
"""Proxy all members of the class."""
518515
if self._con:
519516
return getattr(self._con, name)
520-
else:
521-
raise InvalidConnection
517+
raise InvalidConnection
522518

523519
def __del__(self):
524520
"""Delete the pooled connection."""

dbutils/pooled_pg.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,7 @@
112112
Licensed under the MIT license.
113113
"""
114114

115-
try:
116-
from Queue import Queue, Empty, Full
117-
except ImportError: # Python 3
118-
from queue import Queue, Empty, Full
115+
from queue import Queue, Empty, Full
119116

120117
from . import __version__
121118
from .steady_pg import SteadyPgConnection
@@ -289,8 +286,7 @@ def __getattr__(self, name):
289286
"""Proxy all members of the class."""
290287
if self._con:
291288
return getattr(self._con, name)
292-
else:
293-
raise InvalidConnection
289+
raise InvalidConnection
294290

295291
def __del__(self):
296292
"""Delete the pooled connection."""

dbutils/simple_pooled_db.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -134,14 +134,11 @@ def __init__(self, dbapi, maxconnections, *args, **kwargs):
134134
if threadsafety == 0:
135135
raise NotSupportedError(
136136
"Database module does not support any level of threading.")
137-
elif threadsafety == 1:
137+
if threadsafety == 1:
138138
# If there is no connection level safety, build
139139
# the pool using the synchronized queue class
140140
# that implements all the required locking semantics.
141-
try:
142-
from Queue import Queue
143-
except ImportError: # Python 3
144-
from queue import Queue
141+
from queue import Queue
145142
self._queue = Queue(maxconnections) # create the queue
146143
self.connection = self._unthreadsafe_get_connection
147144
self.addConnection = self._unthreadsafe_add_connection
@@ -197,12 +194,12 @@ def _unthreadsafe_return_connection(self, con):
197194
def _threadsafe_get_connection(self):
198195
"""Get a connection from the pool."""
199196
with self._lock:
200-
next = self._nextConnection
201-
con = PooledDBConnection(self, self._connections[next])
202-
next += 1
203-
if next >= len(self._connections):
204-
next = 0
205-
self._nextConnection = next
197+
next_con = self._nextConnection
198+
con = PooledDBConnection(self, self._connections[next_con])
199+
next_con += 1
200+
if next_con >= len(self._connections):
201+
next_con = 0
202+
self._nextConnection = next_con
206203
return con
207204

208205
def _threadsafe_add_connection(self, con):

dbutils/simple_pooled_pg.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -118,10 +118,7 @@ def __init__(self, maxconnections, *args, **kwargs):
118118
# Since there is no connection level safety, we
119119
# build the pool using the synchronized queue class
120120
# that implements all the required locking semantics.
121-
try:
122-
from Queue import Queue
123-
except ImportError: # Python 3
124-
from queue import Queue
121+
from queue import Queue
125122
self._queue = Queue(maxconnections)
126123
# Establish all database connections (it would be better to
127124
# only establish a part of them now, and the rest on demand).

dbutils/steady_db.py

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,6 @@
9393

9494
from . import __version__
9595

96-
try:
97-
baseint = (int, long)
98-
except NameError: # Python 3
99-
baseint = int
100-
10196

10297
class SteadyDBError(Exception):
10398
"""General SteadyDB error."""
@@ -173,10 +168,10 @@ def __init__(
173168
except AttributeError:
174169
self._threadsafety = None
175170
if not callable(self._creator):
176-
raise TypeError("%r is not a connection provider." % (creator,))
171+
raise TypeError(f"{creator!r} is not a connection provider.")
177172
if maxusage is None:
178173
maxusage = 0
179-
if not isinstance(maxusage, baseint):
174+
if not isinstance(maxusage, int):
180175
raise TypeError("'maxusage' must be an integer value.")
181176
self._maxusage = maxusage
182177
self._setsession_sql = setsession
@@ -531,7 +526,7 @@ def __init__(self, con, *args, **kwargs):
531526
try:
532527
self._cursor = con._cursor(*args, **kwargs)
533528
except AttributeError:
534-
raise TypeError("%r is not a SteadyDBConnection." % (con,))
529+
raise TypeError(f"{con!r} is not a SteadyDBConnection.")
535530
self._closed = False
536531

537532
def __enter__(self):
@@ -688,10 +683,8 @@ def __getattr__(self, name):
688683
if name.startswith(('execute', 'call')):
689684
# make execution methods "tough"
690685
return self._get_tough_method(name)
691-
else:
692-
return getattr(self._cursor, name)
693-
else:
694-
raise InvalidCursor
686+
return getattr(self._cursor, name)
687+
raise InvalidCursor
695688

696689
def __del__(self):
697690
"""Delete the steady cursor."""

dbutils/steady_pg.py

Lines changed: 9 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -73,11 +73,6 @@
7373

7474
from . import __version__
7575

76-
try:
77-
baseint = (int, long)
78-
except NameError: # Python 3
79-
baseint = int
80-
8176

8277
class SteadyPgError(Exception):
8378
"""General SteadyPg error."""
@@ -122,7 +117,7 @@ def __init__(
122117
# proper initialization of the connection
123118
if maxusage is None:
124119
maxusage = 0
125-
if not isinstance(maxusage, baseint):
120+
if not isinstance(maxusage, int):
126121
raise TypeError("'maxusage' must be an integer value.")
127122
self._maxusage = maxusage
128123
self._setsession_sql = setsession
@@ -229,10 +224,7 @@ def begin(self, sql=None):
229224
return self._con.query(sql or 'begin')
230225
else:
231226
# use existing method if available
232-
if sql:
233-
return begin(sql=sql)
234-
else:
235-
return begin()
227+
return begin(sql=sql) if sql else begin()
236228

237229
def end(self, sql=None):
238230
"""Commit the current transaction."""
@@ -242,10 +234,7 @@ def end(self, sql=None):
242234
except AttributeError:
243235
return self._con.query(sql or 'end')
244236
else:
245-
if sql:
246-
return end(sql=sql)
247-
else:
248-
return end()
237+
return end(sql=sql) if sql else end()
249238

250239
def commit(self, sql=None):
251240
"""Commit the current transaction."""
@@ -255,10 +244,7 @@ def commit(self, sql=None):
255244
except AttributeError:
256245
return self._con.query(sql or 'commit')
257246
else:
258-
if sql:
259-
return commit(sql=sql)
260-
else:
261-
return commit()
247+
return commit(sql=sql) if sql else commit()
262248

263249
def rollback(self, sql=None):
264250
"""Rollback the current transaction."""
@@ -268,10 +254,7 @@ def rollback(self, sql=None):
268254
except AttributeError:
269255
return self._con.query(sql or 'rollback')
270256
else:
271-
if sql:
272-
return rollback(sql=sql)
273-
else:
274-
return rollback()
257+
return rollback(sql=sql) if sql else rollback()
275258

276259
def _get_tough_method(self, method):
277260
"""Return a "tough" version of a connection class method.
@@ -297,11 +280,10 @@ def tough_method(*args, **kwargs):
297280
if transaction: # inside a transaction
298281
self._transaction = False
299282
raise # propagate the error
300-
elif self._con.db.status: # if it was not a connection problem
283+
if self._con.db.status: # if it was not a connection problem
301284
raise # then propagate the error
302-
else: # otherwise
303-
self.reset() # reset the connection
304-
result = method(*args, **kwargs) # and try one more time
285+
self.reset() # reset the connection
286+
result = method(*args, **kwargs) # and try one more time
305287
self._usage += 1
306288
return result
307289
return tough_method
@@ -317,8 +299,7 @@ def __getattr__(self, name):
317299
or name.startswith('get_')):
318300
attr = self._get_tough_method(attr)
319301
return attr
320-
else:
321-
raise InvalidConnection
302+
raise InvalidConnection
322303

323304
def __del__(self):
324305
"""Delete the steady connection."""

0 commit comments

Comments
 (0)