[SQL-CVS] r3575 - SQLObject/branches/0.9/sqlobject
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: <sub...@co...> - 2008-09-10 11:47:49
|
Author: dan
Date: 2008-09-10 05:47:48 -0600 (Wed, 10 Sep 2008)
New Revision: 3575
Modified:
SQLObject/branches/0.9/sqlobject/dbconnection.py
Log:
Fixed incorrect handling of boolean arguments passed to connectionForURI or via dburi parameters (backport from trunk rev 3573)
Modified: SQLObject/branches/0.9/sqlobject/dbconnection.py
===================================================================
--- SQLObject/branches/0.9/sqlobject/dbconnection.py 2008-09-10 11:46:43 UTC (rev 3574)
+++ SQLObject/branches/0.9/sqlobject/dbconnection.py 2008-09-10 11:47:48 UTC (rev 3575)
@@ -54,6 +54,16 @@
logger = logging.getLogger(loggerName)
return LogWriter(logger, loglevel)
+class Boolean(object):
+ """A bool class that also understands some special string keywords (yes/no, true/false, on/off, 1/0)"""
+ _keywords = {'1': True, 'yes': True, 'true': True, 'on': True,
+ '0': False, 'no': False, 'false': False, 'off': False}
+ def __new__(cls, value):
+ try:
+ return Boolean._keywords[value.lower()]
+ except (AttributeError, KeyError):
+ return bool(value)
+
class DBConnection:
def __init__(self, name=None, debug=False, debugOutput=False,
@@ -61,16 +71,16 @@
debugThreading=False, registry=None,
logger=None, loglevel=None):
self.name = name
- self.debug = debug
- self.debugOutput = debugOutput
- self.debugThreading = debugThreading
+ self.debug = Boolean(debug)
+ self.debugOutput = Boolean(debugOutput)
+ self.debugThreading = Boolean(debugThreading)
self.debugWriter = makeDebugWriter(logger, loglevel)
- self.cache = CacheSet(cache=cache)
- self.doCache = cache
+ self.doCache = Boolean(cache)
+ self.cache = CacheSet(cache=self.doCache)
self.style = style
self._connectionNumbers = {}
self._connectionCount = 1
- self.autoCommit = autoCommit
+ self.autoCommit = Boolean(autoCommit)
self.registry = registry or None
classregistry.registry(self.registry).addCallback(
self.soClassAdded)
|