equal
deleted
inserted
replaced
162 |
162 |
163 def __exit__(self, exctype, exc, traceback): |
163 def __exit__(self, exctype, exc, traceback): |
164 super_exit = super(_session_hooks_control, self).__exit__ |
164 super_exit = super(_session_hooks_control, self).__exit__ |
165 ret = super_exit(exctype, exc, traceback) |
165 ret = super_exit(exctype, exc, traceback) |
166 if self.cnx.ctx_count == 0: |
166 if self.cnx.ctx_count == 0: |
167 self.session._clear_thread_storage(self.cnx) |
167 self.session.close_cnx(self.cnx) |
168 return ret |
168 return ret |
169 |
169 |
170 @deprecated('[3.17] use <object>.security_enabled instead') |
170 @deprecated('[3.17] use <object>.security_enabled instead') |
171 def security_enabled(obj, *args, **kwargs): |
171 def security_enabled(obj, *args, **kwargs): |
172 return obj.security_enabled(*args, **kwargs) |
172 return obj.security_enabled(*args, **kwargs) |
217 |
217 |
218 def __exit__(self, exctype, exc, traceback): |
218 def __exit__(self, exctype, exc, traceback): |
219 super_exit = super(_session_security_enabled, self).__exit__ |
219 super_exit = super(_session_security_enabled, self).__exit__ |
220 ret = super_exit(exctype, exc, traceback) |
220 ret = super_exit(exctype, exc, traceback) |
221 if self.cnx.ctx_count == 0: |
221 if self.cnx.ctx_count == 0: |
222 self.session._clear_thread_storage(self.cnx) |
222 self.session.close_cnx(self.cnx) |
223 return ret |
223 return ret |
224 |
224 |
225 HOOKS_ALLOW_ALL = object() |
225 HOOKS_ALLOW_ALL = object() |
226 HOOKS_DENY_ALL = object() |
226 HOOKS_DENY_ALL = object() |
227 DEFAULT_SECURITY = object() # evaluated to true by design |
227 DEFAULT_SECURITY = object() # evaluated to true by design |
1306 return cnx |
1306 return cnx |
1307 |
1307 |
1308 def close_cnx(self, cnx): |
1308 def close_cnx(self, cnx): |
1309 """Close a Connection related to a session""" |
1309 """Close a Connection related to a session""" |
1310 cnx.free_cnxset(ignoremode=True) |
1310 cnx.free_cnxset(ignoremode=True) |
1311 self._clear_thread_storage(cnx) |
1311 self._cnxs.pop(cnx.connectionid, None) |
|
1312 try: |
|
1313 if self.__threaddata.cnx is cnx: |
|
1314 del self.__threaddata.cnx |
|
1315 except AttributeError: |
|
1316 pass |
1312 cnx.clear() |
1317 cnx.clear() |
1313 |
1318 |
1314 def set_cnx(self, cnxid=None): |
1319 def set_cnx(self, cnxid=None): |
1315 """set the default connection of the current thread to <cnxid> |
1320 """set the default connection of the current thread to <cnxid> |
1316 |
1321 |
1507 pass |
1512 pass |
1508 else: |
1513 else: |
1509 if free_cnxset: |
1514 if free_cnxset: |
1510 self.free_cnxset() |
1515 self.free_cnxset() |
1511 if cnx.ctx_count == 0: |
1516 if cnx.ctx_count == 0: |
1512 self._clear_thread_storage(cnx) |
1517 self.close_cnx(cnx) |
1513 else: |
1518 else: |
1514 cnx.clear() |
1519 cnx.clear() |
1515 else: |
1520 else: |
1516 cnx.clear() |
1521 cnx.clear() |
1517 |
|
1518 def _clear_thread_storage(self, cnx): |
|
1519 self._cnxs.pop(cnx.connectionid, None) |
|
1520 try: |
|
1521 if self.__threaddata.cnx is cnx: |
|
1522 del self.__threaddata.cnx |
|
1523 except AttributeError: |
|
1524 pass |
|
1525 |
|
1526 |
1522 |
1527 def commit(self, free_cnxset=True, reset_pool=None): |
1523 def commit(self, free_cnxset=True, reset_pool=None): |
1528 """commit the current session's transaction""" |
1524 """commit the current session's transaction""" |
1529 cstate = self._cnx.commit_state |
1525 cstate = self._cnx.commit_state |
1530 if cstate == 'uncommitable': |
1526 if cstate == 'uncommitable': |