|
95 | 95 |
|
96 | 96 | Requirements: |
97 | 97 |
|
98 | | -Python >= 2.3, < 3.0. |
| 98 | +Python >= 2.6. |
99 | 99 |
|
100 | 100 |
|
101 | 101 | Ideas for improvement: |
|
116 | 116 |
|
117 | 117 | """ |
118 | 118 |
|
119 | | -__version__ = '1.1.1' |
120 | | - |
121 | | -import ThreadingLocal |
122 | 119 | from DBUtils.SteadyDB import connect |
123 | 120 |
|
| 121 | +__version__ = '1.2' |
| 122 | + |
| 123 | +try: |
| 124 | + callable |
| 125 | +except NameError: # Python 3.0 or 3.1 |
| 126 | + def callable(obj): |
| 127 | + return any('__call__' in cls.__dict__ for cls in type(obj).__mro__) |
| 128 | +try: |
| 129 | + # Prefer the pure Python version of threading.local. |
| 130 | + # The C implementation turned out to be problematic with mod_wsgi, |
| 131 | + # since it does not keep the thread-local data between requests. |
| 132 | + from _threading_local import local |
| 133 | +except ImportError: |
| 134 | + # Fall back to the default version of threading.local. |
| 135 | + from threading import local |
| 136 | + |
124 | 137 |
|
125 | 138 | class PersistentDBError(Exception): |
126 | 139 | """General PersistentDB error.""" |
127 | 140 |
|
| 141 | + |
128 | 142 | class NotSupportedError(PersistentDBError): |
129 | 143 | """DB-API module not supported by PersistentDB.""" |
130 | 144 |
|
@@ -186,12 +200,12 @@ def __init__(self, creator, |
186 | 200 | self._ping = ping |
187 | 201 | self._closeable = closeable |
188 | 202 | self._args, self._kwargs = args, kwargs |
189 | | - self.thread = (threadlocal or ThreadingLocal.local)() |
| 203 | + self.thread = (threadlocal or local)() |
190 | 204 |
|
191 | 205 | def steady_connection(self): |
192 | 206 | """Get a steady, non-persistent DB-API 2 connection.""" |
193 | | - return connect(self._creator, |
194 | | - self._maxusage, self._setsession, |
| 207 | + return connect( |
| 208 | + self._creator, self._maxusage, self._setsession, |
195 | 209 | self._failures, self._ping, self._closeable, |
196 | 210 | *self._args, **self._kwargs) |
197 | 211 |
|
|
0 commit comments