Skip to content

Commit 678ea14

Browse files
committed
The values True and False are already defined in Python 2.2, so we should use them where appropriate.
1 parent 3dfcc52 commit 678ea14

18 files changed

Lines changed: 126 additions & 123 deletions

DBUtils/Docs/UsersGuide.de.txt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -275,8 +275,8 @@ Parameter angeben müssen:
275275
bei denen die Ausfallsicherung zum Tragen kommen soll, falls die Vorgabe
276276
(OperationalError, InternalError) nicht geeignet sein sollte
277277

278-
* ``closeable``: wenn dies auf einen wahren Wert gesetzt wird, dann wird das
279-
Schließen von Verbindungen erlaubt, normalerweise wird es jedoch ignoriert
278+
* ``closeable``: wenn dies auf ``True`` gesetzt wird, dann wird das Schließen
279+
von Verbindungen erlaubt, normalerweise wird es jedoch ignoriert
280280

281281
* Die als ``creator`` angegebene Funktion oder die Funktion ``connect``
282282
des DB-API-2-Datenbankadapter-Moduls erhalten alle weiteren Parameter,
@@ -336,10 +336,11 @@ Parameter angeben müssen:
336336
die insgesamt überhaupt erlaubt werden sollen (der Standardwert ``0``
337337
bedeutet unbegrenzte Anzahl von Datenbankverbindungen)
338338

339-
* ``blocking``: bestimmt das Verhalten, wenn diese Obergrenze überschritten
340-
wird (der Standardwert ``0`` oder ein nicht wahrer Wert bedeutet, dass eine
341-
Fehlermeldung ausgegeben wird, andernfalls wird blockiert und gewartet,
342-
bis die Anzahl an Datenbankverbindungen wieder abnimmt)
339+
* ``blocking``: bestimmt das Verhalten bei Überschreitung dieser Obergrenze
340+
341+
Wenn dies auf ``True`` gesetzt wird, dann wird so lange gewartet, bis die
342+
Anzahl an Datenbankverbindungen wieder abnimmt, normalerweise wird jedoch
343+
sofort eine Fehlermeldung ausgegeben.
343344

344345
* ``maxusage``: Obergrenze dafür, wie oft eine einzelne Verbindung
345346
wiederverwendet werden darf (der Standardwert ``0`` oder ``None``

DBUtils/Docs/UsersGuide.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,8 +310,9 @@ following parameters:
310310
(the default value of ``0`` means any number of connections)
311311

312312
* ``blocking``: determines behavior when exceeding the maximum
313-
(the default of ``0`` or any false value means report an error;
314-
otherwise block and wait until the number of connections decreases)
313+
314+
If this is set to true, block and wait until the number of
315+
connections decreases, but by default an error will be reported.
315316

316317
* ``maxusage``: maximum number of reuses of a single connection
317318
(the default of ``0`` or ``None`` means unlimited reuse)

DBUtils/Examples/DBUtilsExample.py

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ def postAction(self, actionName):
106106
def output(self, s):
107107
self._output.append(s)
108108

109-
def outputMsg(self, msg, error=0):
109+
def outputMsg(self, msg, error=False):
110110
self._output.append('<p style="color:%s">%s</p>'
111111
% (error and 'red' or 'green', msg))
112112

113-
def connection(self, shareable=1):
113+
def connection(self, shareable=True):
114114
if self.dbstatus:
115115
error = self.dbstatus
116116
else:
@@ -123,7 +123,7 @@ def connection(self, shareable=1):
123123
error = str(error)
124124
except Exception:
125125
error = 'Cannot connect to the database.'
126-
self.outputMsg(error, 1)
126+
self.outputMsg(error, True)
127127

128128
def sqlEncode(self, s):
129129
if s is None:
@@ -132,7 +132,7 @@ def sqlEncode(self, s):
132132
return "'%s'" % s
133133

134134
def createTables(self):
135-
db = self.connection(0)
135+
db = self.connection(False)
136136
if not db:
137137
return
138138
for table in tables:
@@ -148,7 +148,7 @@ def createTables(self):
148148
except self.dbapi.Error, error:
149149
if self.dbapi_name != 'pg':
150150
db.rollback()
151-
self.outputMsg(error, 1)
151+
self.outputMsg(error, True)
152152
else:
153153
self.outputMsg('The table was successfully created.')
154154
db.close()
@@ -160,7 +160,7 @@ def listSeminars(self):
160160
id = [id]
161161
cmd = ','.join(map(self.sqlEncode, id))
162162
cmd = 'delete from seminars where id in (%s)' % cmd
163-
db = self.connection(0)
163+
db = self.connection(False)
164164
if not db:
165165
return
166166
try:
@@ -179,7 +179,7 @@ def listSeminars(self):
179179
db.rollback()
180180
except Exception:
181181
pass
182-
self.outputMsg(error, 1)
182+
self.outputMsg(error, True)
183183
return
184184
else:
185185
self.outputMsg('Entries deleted: %d' % len(id))
@@ -197,10 +197,10 @@ def listSeminars(self):
197197
result = cursor.fetchall()
198198
cursor.close()
199199
except self.dbapi.Error, error:
200-
self.outputMsg(error, 1)
200+
self.outputMsg(error, True)
201201
return
202202
if not result:
203-
self.outputMsg('There are no seminars in the database.', 1)
203+
self.outputMsg('There are no seminars in the database.', True)
204204
return
205205
wr = self.output
206206
button = self._buttons[1].replace('List seminars', 'Delete')
@@ -236,7 +236,7 @@ def listAttendees(self):
236236
for i, n in places.items():
237237
cmds.append("update seminars set places_left=places_left+%d "
238238
"where id=%s" % (n, self.sqlEncode(i)))
239-
db = self.connection(0)
239+
db = self.connection(False)
240240
if not db:
241241
return
242242
try:
@@ -254,7 +254,7 @@ def listAttendees(self):
254254
db.query('end')
255255
else:
256256
db.rollback()
257-
self.outputMsg(error, 1)
257+
self.outputMsg(error, True)
258258
return
259259
else:
260260
self.outputMsg('Entries deleted: %d' % len(id))
@@ -274,10 +274,10 @@ def listAttendees(self):
274274
result = cursor.fetchall()
275275
cursor.close()
276276
except self.dbapi.Error, error:
277-
self.outputMsg(error, 1)
277+
self.outputMsg(error, True)
278278
return
279279
if not result:
280-
self.outputMsg('There are no attendees in the database.', 1)
280+
self.outputMsg('There are no attendees in the database.', True)
281281
return
282282
wr = self.output
283283
button = self._buttons[2].replace('List attendees', 'Delete')
@@ -338,7 +338,7 @@ def newSeminar(self):
338338
db.query('end')
339339
else:
340340
db.rollback()
341-
self.outputMsg(error, 1)
341+
self.outputMsg(error, True)
342342
else:
343343
self.outputMsg('"%s" added to seminars.' % values[1])
344344
db.close()
@@ -358,7 +358,7 @@ def newAttendee(self):
358358
result = cursor.fetchall()
359359
cursor.close()
360360
except self.dbapi.Error, error:
361-
self.outputMsg(error, 1)
361+
self.outputMsg(error, True)
362362
return
363363
if not result:
364364
self.outputMsg('You have to define seminars first.')
@@ -425,7 +425,7 @@ def newAttendee(self):
425425
db.query('end')
426426
else:
427427
db.rollback()
428-
self.outputMsg(error, 1)
428+
self.outputMsg(error, True)
429429
else:
430430
self.outputMsg('%s added to attendees.' % values[0])
431431
db.close()

DBUtils/PersistentDB.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ class PersistentDB:
115115
version = __version__
116116

117117
def __init__(self, creator,
118-
maxusage=0, setsession=None, failures=None, closeable=0,
118+
maxusage=None, setsession=None, failures=None, closeable=False,
119119
*args, **kwargs):
120120
"""Set up the persistent DB-API 2 connection generator.
121121
@@ -159,7 +159,7 @@ def steady_connection(self):
159159
self._failures, self._closeable,
160160
*self._args, **self._kwargs)
161161

162-
def connection(self, shareable=0):
162+
def connection(self, shareable=False):
163163
"""Get a steady, persistent DB-API 2 connection.
164164
165165
The shareable parameter exists only for compatibility with the

DBUtils/PersistentPg.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class PersistentPg:
106106

107107
version = __version__
108108

109-
def __init__(self, maxusage=0, setsession=None, closeable=0,
109+
def __init__(self, maxusage=None, setsession=None, closeable=False,
110110
*args, **kwargs):
111111
"""Set up the persistent PostgreSQL connection generator.
112112

DBUtils/PooledDB.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@
4040
maxconnections: maximum number of connections generally allowed
4141
(the default value of 0 means any number of connections)
4242
blocking: determines behavior when exceeding the maximum
43-
(the default of 0 or false means report an error; otherwise
44-
block and wait until the number of connections decreases)
43+
(if this is set to true, block and wait until the number of
44+
connections decreases, but by default an error will be reported)
4545
maxusage: maximum number of reuses of a single connection
4646
(the default of 0 or None means unlimited reuse)
4747
When this maximum usage number of the connection is reached,
@@ -149,8 +149,8 @@ class PooledDB:
149149

150150
def __init__(self, creator,
151151
mincached=0, maxcached=0,
152-
maxshared=0, maxconnections=0, blocking=0,
153-
maxusage=0, setsession=None, failures=None,
152+
maxshared=0, maxconnections=0, blocking=False,
153+
maxusage=None, setsession=None, failures=None,
154154
*args, **kwargs):
155155
"""Set up the DB-API 2 connection pool.
156156
@@ -167,8 +167,8 @@ def __init__(self, creator,
167167
maxconnections: maximum number of connections generally allowed
168168
(0 means an arbitrary number of connections)
169169
blocking: determines behavior when exceeding the maximum
170-
(0 or any false value means report an error; otherwise
171-
block and wait until the number of connections decreases)
170+
(if this is set to true, block and wait until the number of
171+
connections decreases, otherwise an error will be reported)
172172
maxusage: maximum number of reuses of a single connection
173173
(0 or None means unlimited reuse)
174174
When this maximum usage number of the connection is reached,
@@ -228,10 +228,10 @@ def wait():
228228
def steady_connection(self):
229229
"""Get a steady, unpooled DB-API 2 connection."""
230230
return connect(self._creator,
231-
self._maxusage, self._setsession, self._failures, 1,
231+
self._maxusage, self._setsession, self._failures, True,
232232
*self._args, **self._kwargs)
233233

234-
def connection(self, shareable=1):
234+
def connection(self, shareable=True):
235235
""""Get a steady, cached DB-API 2 connection from the pool.
236236
237237
If shareable is set and the underlying DB-API 2 allows it,

DBUtils/PooledPg.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@
3535
maxconnections: maximum number of connections generally allowed
3636
(the default value of 0 means any number of connections)
3737
blocking: determines behavior when exceeding the maximum
38-
(the default of 0 or false means report an error; otherwise
39-
block and wait until the number of connections decreases)
38+
(if this is set to true, block and wait until the number of
39+
connections decreases, but by default an error will be reported)
4040
maxusage: maximum number of reuses of a single connection
4141
(the default of 0 or None means unlimited reuse)
4242
When this maximum usage number of the connection is reached,
@@ -130,8 +130,8 @@ class PooledPg:
130130

131131
def __init__(self,
132132
mincached=0, maxcached=0,
133-
maxconnections=0, blocking=0,
134-
maxusage=0, setsession=None,
133+
maxconnections=0, blocking=False,
134+
maxusage=None, setsession=None,
135135
*args, **kwargs):
136136
"""Set up the PostgreSQL connection pool.
137137
@@ -142,8 +142,8 @@ def __init__(self,
142142
maxconnections: maximum number of connections generally allowed
143143
(0 means an arbitrary number of connections)
144144
blocking: determines behavior when exceeding the maximum
145-
(0 or any false value means report an error; otherwise
146-
block and wait until the number of connections decreases)
145+
(if this is set to true, block and wait until the number of
146+
connections decreases, otherwise an error will be reported)
147147
maxusage: maximum number of reuses of a single connection
148148
(0 or None means unlimited reuse)
149149
When this maximum usage number of the connection is reached,
@@ -175,7 +175,7 @@ def __init__(self,
175175

176176
def steady_connection(self):
177177
"""Get a steady, unpooled PostgreSQL connection."""
178-
return SteadyPgConnection(self._maxusage, self._setsession, 1,
178+
return SteadyPgConnection(self._maxusage, self._setsession, True,
179179
*self._args, **self._kwargs)
180180

181181
def connection(self):

DBUtils/SteadyDB.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@
9393
import sys
9494

9595

96-
def connect(creator, maxusage=0, setsession=None, failures=None,
97-
closeable=1, *args, **kwargs):
96+
def connect(creator, maxusage=None, setsession=None, failures=None,
97+
closeable=True, *args, **kwargs):
9898
"""A tough version of the connection constructor of a DB-API 2 module.
9999
100100
creator: either an arbitrary function returning new DB-API 2 compliant
@@ -123,10 +123,10 @@ class SteadyDBConnection:
123123

124124
version = __version__
125125

126-
_closed = 1
126+
_closed = True
127127

128-
def __init__(self, creator, maxusage=0, setsession=None, failures=None,
129-
closeable=1, *args, **kwargs):
128+
def __init__(self, creator, maxusage=None, setsession=None, failures=None,
129+
closeable=True, *args, **kwargs):
130130
""""Create a "tough" DB-API 2 connection."""
131131
try:
132132
self._creator = creator.connect
@@ -194,7 +194,7 @@ def _setsession(self, con=None):
194194
def _store(self, con):
195195
"""Store a database connection for subsequent use."""
196196
self._con = con
197-
self._closed = 0
197+
self._closed = False
198198
self._usage = 0
199199

200200
def _close(self):
@@ -209,7 +209,7 @@ def _close(self):
209209
self._con.close()
210210
except Exception:
211211
pass
212-
self._closed = 1
212+
self._closed = True
213213

214214
def dbapi(self):
215215
"""Return the underlying DB-API 2 module of the connection."""
@@ -287,15 +287,15 @@ def __del__(self):
287287
class SteadyDBCursor:
288288
"""A "tough" version of DB-API 2 cursors."""
289289

290-
_closed = 1
290+
_closed = True
291291

292292
def __init__(self, con, *args, **kwargs):
293293
""""Create a "tough" DB-API 2 cursor."""
294294
self._con = con
295295
self._args, self._kwargs = args, kwargs
296296
self._clearsizes()
297297
self._cursor = con._cursor(*args, **kwargs)
298-
self._closed = 0
298+
self._closed = False
299299

300300
def setinputsizes(self, sizes):
301301
"""Store input sizes in case cursor needs to be reopened."""
@@ -336,7 +336,7 @@ def close(self):
336336
self._cursor.close()
337337
except Exception:
338338
pass
339-
self._closed = 1
339+
self._closed = True
340340

341341
def _get_tough_method(self, name):
342342
"""Return a "tough" version of the method."""

DBUtils/SteadyPg.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,9 +89,9 @@ class SteadyPgConnection:
8989

9090
version = __version__
9191

92-
_closed = 1
92+
_closed = True
9393

94-
def __init__(self, maxusage=0, setsession=None, closeable=1,
94+
def __init__(self, maxusage=None, setsession=None, closeable=True,
9595
*args, **kwargs):
9696
"""Create a "tough" PostgreSQL connection.
9797
@@ -112,7 +112,7 @@ def __init__(self, maxusage=0, setsession=None, closeable=1,
112112
self._setsession_sql = setsession
113113
self._closeable = closeable
114114
self._con = PgConnection(*args, **kwargs)
115-
self._closed = 0
115+
self._closed = False
116116
self._setsession()
117117
self._usage = 0
118118

@@ -134,7 +134,7 @@ def _close(self):
134134
self._con.close()
135135
except Exception:
136136
pass
137-
self._closed = 1
137+
self._closed = True
138138

139139
def close(self):
140140
"""Close the tough connection.
@@ -161,7 +161,7 @@ def reopen(self):
161161
except Exception:
162162
pass
163163
else:
164-
self._closed = 0
164+
self._closed = False
165165
self._setsession()
166166
self._usage = 0
167167

0 commit comments

Comments
 (0)