| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
1 parent b1729b4 commit ece3ad5
1 file changed
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -49,23 +49,33 @@ def makeDebugWriter(loggerName, loglevel): | |||
| 49 | 49 | logger = logging.getLogger(loggerName) | |
| 50 | 50 | return LogWriter(logger, loglevel) | |
| 51 | 51 | ||
| 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 | + | ||
| 52 | 62 | class DBConnection: | |
| 53 | 63 | ||
| 54 | 64 | def __init__(self, name=None, debug=False, debugOutput=False, | |
| 55 | 65 | cache=True, style=None, autoCommit=True, | |
| 56 | 66 | debugThreading=False, registry=None, | |
| 57 | 67 | logger=None, loglevel=None): | |
| 58 | 68 | 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) | ||
| 62 | 72 | 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) | ||
| 65 | 75 | self.style = style | |
| 66 | 76 | self._connectionNumbers = {} | |
| 67 | 77 | self._connectionCount = 1 | |
| 68 | - self.autoCommit = autoCommit | ||
| 78 | + self.autoCommit = Boolean(autoCommit) | ||
| 69 | 79 | self.registry = registry or None | |
| 70 | 80 | classregistry.registry(self.registry).addCallback( | |
| 71 | 81 | self.soClassAdded) | |
| Back | FazBrowse Home | New Git URL |
0 commit comments