FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Fixed incorrect handling of boolean arguments passed to connectionFor… · sqlobject/sqlobject@ece3ad5 · GitHub

Commit ece3ad5

Browse files
committed
Fixed incorrect handling of boolean arguments passed to connectionForURI or via dburi parameters
git-svn-id: http://svn.colorstudy.com/SQLObject/trunk@3573 95a46c32-92d2-0310-94a5-8d71aeb3d4b3
1 parent b1729b4 commit ece3ad5

1 file changed

Lines changed: 16 additions & 6 deletions

File tree

‎sqlobject/dbconnection.py‎

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,33 @@ def makeDebugWriter(loggerName, loglevel):
4949
logger = logging.getLogger(loggerName)
5050
return LogWriter(logger, loglevel)
5151

52+
class Boolean(object):
53+
"""A bool class that also understands some special string keywords (yes/no, true/false, on/off, 1/0)"""
54+
_keywords = {'1': True, 'yes': True, 'true': True, 'on': True,
55+
'0': False, 'no': False, 'false': False, 'off': False}
56+
def __new__(cls, value):
57+
try:
58+
return Boolean._keywords[value.lower()]
59+
except (AttributeError, KeyError):
60+
return bool(value)
61+
5262
class DBConnection:
5363

5464
def __init__(self, name=None, debug=False, debugOutput=False,
5565
cache=True, style=None, autoCommit=True,
5666
debugThreading=False, registry=None,
5767
logger=None, loglevel=None):
5868
self.name = name
59-
self.debug = debug
60-
self.debugOutput = debugOutput
61-
self.debugThreading = debugThreading
69+
self.debug = Boolean(debug)
70+
self.debugOutput = Boolean(debugOutput)
71+
self.debugThreading = Boolean(debugThreading)
6272
self.debugWriter = makeDebugWriter(logger, loglevel)
63-
self.cache = CacheSet(cache=cache)
64-
self.doCache = cache
73+
self.doCache = Boolean(cache)
74+
self.cache = CacheSet(cache=self.doCache)
6575
self.style = style
6676
self._connectionNumbers = {}
6777
self._connectionCount = 1
68-
self.autoCommit = autoCommit
78+
self.autoCommit = Boolean(autoCommit)
6979
self.registry = registry or None
7080
classregistry.registry(self.registry).addCallback(
7181
self.soClassAdded)

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL