SQLAlchemy 2.0.45__cp314-cp314-win32.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (274) hide show
  1. sqlalchemy/__init__.py +283 -0
  2. sqlalchemy/connectors/__init__.py +18 -0
  3. sqlalchemy/connectors/aioodbc.py +184 -0
  4. sqlalchemy/connectors/asyncio.py +429 -0
  5. sqlalchemy/connectors/pyodbc.py +250 -0
  6. sqlalchemy/cyextension/__init__.py +6 -0
  7. sqlalchemy/cyextension/collections.cp314-win32.pyd +0 -0
  8. sqlalchemy/cyextension/collections.pyx +409 -0
  9. sqlalchemy/cyextension/immutabledict.cp314-win32.pyd +0 -0
  10. sqlalchemy/cyextension/immutabledict.pxd +8 -0
  11. sqlalchemy/cyextension/immutabledict.pyx +133 -0
  12. sqlalchemy/cyextension/processors.cp314-win32.pyd +0 -0
  13. sqlalchemy/cyextension/processors.pyx +68 -0
  14. sqlalchemy/cyextension/resultproxy.cp314-win32.pyd +0 -0
  15. sqlalchemy/cyextension/resultproxy.pyx +102 -0
  16. sqlalchemy/cyextension/util.cp314-win32.pyd +0 -0
  17. sqlalchemy/cyextension/util.pyx +90 -0
  18. sqlalchemy/dialects/__init__.py +62 -0
  19. sqlalchemy/dialects/_typing.py +30 -0
  20. sqlalchemy/dialects/mssql/__init__.py +88 -0
  21. sqlalchemy/dialects/mssql/aioodbc.py +63 -0
  22. sqlalchemy/dialects/mssql/base.py +4089 -0
  23. sqlalchemy/dialects/mssql/information_schema.py +285 -0
  24. sqlalchemy/dialects/mssql/json.py +129 -0
  25. sqlalchemy/dialects/mssql/provision.py +168 -0
  26. sqlalchemy/dialects/mssql/pymssql.py +126 -0
  27. sqlalchemy/dialects/mssql/pyodbc.py +760 -0
  28. sqlalchemy/dialects/mysql/__init__.py +104 -0
  29. sqlalchemy/dialects/mysql/aiomysql.py +250 -0
  30. sqlalchemy/dialects/mysql/asyncmy.py +231 -0
  31. sqlalchemy/dialects/mysql/base.py +3933 -0
  32. sqlalchemy/dialects/mysql/cymysql.py +106 -0
  33. sqlalchemy/dialects/mysql/dml.py +225 -0
  34. sqlalchemy/dialects/mysql/enumerated.py +282 -0
  35. sqlalchemy/dialects/mysql/expression.py +146 -0
  36. sqlalchemy/dialects/mysql/json.py +91 -0
  37. sqlalchemy/dialects/mysql/mariadb.py +73 -0
  38. sqlalchemy/dialects/mysql/mariadbconnector.py +322 -0
  39. sqlalchemy/dialects/mysql/mysqlconnector.py +302 -0
  40. sqlalchemy/dialects/mysql/mysqldb.py +314 -0
  41. sqlalchemy/dialects/mysql/provision.py +147 -0
  42. sqlalchemy/dialects/mysql/pymysql.py +158 -0
  43. sqlalchemy/dialects/mysql/pyodbc.py +157 -0
  44. sqlalchemy/dialects/mysql/reflection.py +727 -0
  45. sqlalchemy/dialects/mysql/reserved_words.py +570 -0
  46. sqlalchemy/dialects/mysql/types.py +835 -0
  47. sqlalchemy/dialects/oracle/__init__.py +81 -0
  48. sqlalchemy/dialects/oracle/base.py +3802 -0
  49. sqlalchemy/dialects/oracle/cx_oracle.py +1555 -0
  50. sqlalchemy/dialects/oracle/dictionary.py +507 -0
  51. sqlalchemy/dialects/oracle/oracledb.py +941 -0
  52. sqlalchemy/dialects/oracle/provision.py +297 -0
  53. sqlalchemy/dialects/oracle/types.py +316 -0
  54. sqlalchemy/dialects/oracle/vector.py +365 -0
  55. sqlalchemy/dialects/postgresql/__init__.py +167 -0
  56. sqlalchemy/dialects/postgresql/_psycopg_common.py +189 -0
  57. sqlalchemy/dialects/postgresql/array.py +519 -0
  58. sqlalchemy/dialects/postgresql/asyncpg.py +1284 -0
  59. sqlalchemy/dialects/postgresql/base.py +5328 -0
  60. sqlalchemy/dialects/postgresql/dml.py +339 -0
  61. sqlalchemy/dialects/postgresql/ext.py +540 -0
  62. sqlalchemy/dialects/postgresql/hstore.py +406 -0
  63. sqlalchemy/dialects/postgresql/json.py +395 -0
  64. sqlalchemy/dialects/postgresql/named_types.py +524 -0
  65. sqlalchemy/dialects/postgresql/operators.py +129 -0
  66. sqlalchemy/dialects/postgresql/pg8000.py +669 -0
  67. sqlalchemy/dialects/postgresql/pg_catalog.py +326 -0
  68. sqlalchemy/dialects/postgresql/provision.py +175 -0
  69. sqlalchemy/dialects/postgresql/psycopg.py +862 -0
  70. sqlalchemy/dialects/postgresql/psycopg2.py +892 -0
  71. sqlalchemy/dialects/postgresql/psycopg2cffi.py +61 -0
  72. sqlalchemy/dialects/postgresql/ranges.py +1031 -0
  73. sqlalchemy/dialects/postgresql/types.py +313 -0
  74. sqlalchemy/dialects/sqlite/__init__.py +57 -0
  75. sqlalchemy/dialects/sqlite/aiosqlite.py +446 -0
  76. sqlalchemy/dialects/sqlite/base.py +3045 -0
  77. sqlalchemy/dialects/sqlite/dml.py +263 -0
  78. sqlalchemy/dialects/sqlite/json.py +92 -0
  79. sqlalchemy/dialects/sqlite/provision.py +223 -0
  80. sqlalchemy/dialects/sqlite/pysqlcipher.py +157 -0
  81. sqlalchemy/dialects/sqlite/pysqlite.py +756 -0
  82. sqlalchemy/dialects/type_migration_guidelines.txt +145 -0
  83. sqlalchemy/engine/__init__.py +62 -0
  84. sqlalchemy/engine/_py_processors.py +136 -0
  85. sqlalchemy/engine/_py_row.py +128 -0
  86. sqlalchemy/engine/_py_util.py +74 -0
  87. sqlalchemy/engine/base.py +3382 -0
  88. sqlalchemy/engine/characteristics.py +155 -0
  89. sqlalchemy/engine/create.py +893 -0
  90. sqlalchemy/engine/cursor.py +2298 -0
  91. sqlalchemy/engine/default.py +2394 -0
  92. sqlalchemy/engine/events.py +965 -0
  93. sqlalchemy/engine/interfaces.py +3471 -0
  94. sqlalchemy/engine/mock.py +134 -0
  95. sqlalchemy/engine/processors.py +61 -0
  96. sqlalchemy/engine/reflection.py +2102 -0
  97. sqlalchemy/engine/result.py +2387 -0
  98. sqlalchemy/engine/row.py +400 -0
  99. sqlalchemy/engine/strategies.py +16 -0
  100. sqlalchemy/engine/url.py +924 -0
  101. sqlalchemy/engine/util.py +167 -0
  102. sqlalchemy/event/__init__.py +26 -0
  103. sqlalchemy/event/api.py +220 -0
  104. sqlalchemy/event/attr.py +676 -0
  105. sqlalchemy/event/base.py +472 -0
  106. sqlalchemy/event/legacy.py +258 -0
  107. sqlalchemy/event/registry.py +390 -0
  108. sqlalchemy/events.py +17 -0
  109. sqlalchemy/exc.py +832 -0
  110. sqlalchemy/ext/__init__.py +11 -0
  111. sqlalchemy/ext/associationproxy.py +2027 -0
  112. sqlalchemy/ext/asyncio/__init__.py +25 -0
  113. sqlalchemy/ext/asyncio/base.py +281 -0
  114. sqlalchemy/ext/asyncio/engine.py +1471 -0
  115. sqlalchemy/ext/asyncio/exc.py +21 -0
  116. sqlalchemy/ext/asyncio/result.py +965 -0
  117. sqlalchemy/ext/asyncio/scoping.py +1599 -0
  118. sqlalchemy/ext/asyncio/session.py +1947 -0
  119. sqlalchemy/ext/automap.py +1701 -0
  120. sqlalchemy/ext/baked.py +570 -0
  121. sqlalchemy/ext/compiler.py +600 -0
  122. sqlalchemy/ext/declarative/__init__.py +65 -0
  123. sqlalchemy/ext/declarative/extensions.py +564 -0
  124. sqlalchemy/ext/horizontal_shard.py +478 -0
  125. sqlalchemy/ext/hybrid.py +1535 -0
  126. sqlalchemy/ext/indexable.py +364 -0
  127. sqlalchemy/ext/instrumentation.py +450 -0
  128. sqlalchemy/ext/mutable.py +1085 -0
  129. sqlalchemy/ext/mypy/__init__.py +6 -0
  130. sqlalchemy/ext/mypy/apply.py +324 -0
  131. sqlalchemy/ext/mypy/decl_class.py +515 -0
  132. sqlalchemy/ext/mypy/infer.py +590 -0
  133. sqlalchemy/ext/mypy/names.py +335 -0
  134. sqlalchemy/ext/mypy/plugin.py +303 -0
  135. sqlalchemy/ext/mypy/util.py +357 -0
  136. sqlalchemy/ext/orderinglist.py +439 -0
  137. sqlalchemy/ext/serializer.py +185 -0
  138. sqlalchemy/future/__init__.py +16 -0
  139. sqlalchemy/future/engine.py +15 -0
  140. sqlalchemy/inspection.py +174 -0
  141. sqlalchemy/log.py +288 -0
  142. sqlalchemy/orm/__init__.py +171 -0
  143. sqlalchemy/orm/_orm_constructors.py +2661 -0
  144. sqlalchemy/orm/_typing.py +179 -0
  145. sqlalchemy/orm/attributes.py +2845 -0
  146. sqlalchemy/orm/base.py +971 -0
  147. sqlalchemy/orm/bulk_persistence.py +2135 -0
  148. sqlalchemy/orm/clsregistry.py +571 -0
  149. sqlalchemy/orm/collections.py +1627 -0
  150. sqlalchemy/orm/context.py +3334 -0
  151. sqlalchemy/orm/decl_api.py +2004 -0
  152. sqlalchemy/orm/decl_base.py +2192 -0
  153. sqlalchemy/orm/dependency.py +1302 -0
  154. sqlalchemy/orm/descriptor_props.py +1092 -0
  155. sqlalchemy/orm/dynamic.py +300 -0
  156. sqlalchemy/orm/evaluator.py +379 -0
  157. sqlalchemy/orm/events.py +3252 -0
  158. sqlalchemy/orm/exc.py +237 -0
  159. sqlalchemy/orm/identity.py +302 -0
  160. sqlalchemy/orm/instrumentation.py +754 -0
  161. sqlalchemy/orm/interfaces.py +1496 -0
  162. sqlalchemy/orm/loading.py +1686 -0
  163. sqlalchemy/orm/mapped_collection.py +557 -0
  164. sqlalchemy/orm/mapper.py +4444 -0
  165. sqlalchemy/orm/path_registry.py +809 -0
  166. sqlalchemy/orm/persistence.py +1788 -0
  167. sqlalchemy/orm/properties.py +935 -0
  168. sqlalchemy/orm/query.py +3459 -0
  169. sqlalchemy/orm/relationships.py +3508 -0
  170. sqlalchemy/orm/scoping.py +2148 -0
  171. sqlalchemy/orm/session.py +5280 -0
  172. sqlalchemy/orm/state.py +1168 -0
  173. sqlalchemy/orm/state_changes.py +196 -0
  174. sqlalchemy/orm/strategies.py +3470 -0
  175. sqlalchemy/orm/strategy_options.py +2568 -0
  176. sqlalchemy/orm/sync.py +164 -0
  177. sqlalchemy/orm/unitofwork.py +796 -0
  178. sqlalchemy/orm/util.py +2403 -0
  179. sqlalchemy/orm/writeonly.py +674 -0
  180. sqlalchemy/pool/__init__.py +44 -0
  181. sqlalchemy/pool/base.py +1516 -0
  182. sqlalchemy/pool/events.py +372 -0
  183. sqlalchemy/pool/impl.py +588 -0
  184. sqlalchemy/py.typed +0 -0
  185. sqlalchemy/schema.py +69 -0
  186. sqlalchemy/sql/__init__.py +145 -0
  187. sqlalchemy/sql/_dml_constructors.py +132 -0
  188. sqlalchemy/sql/_elements_constructors.py +1872 -0
  189. sqlalchemy/sql/_orm_types.py +20 -0
  190. sqlalchemy/sql/_py_util.py +75 -0
  191. sqlalchemy/sql/_selectable_constructors.py +763 -0
  192. sqlalchemy/sql/_typing.py +481 -0
  193. sqlalchemy/sql/annotation.py +587 -0
  194. sqlalchemy/sql/base.py +2219 -0
  195. sqlalchemy/sql/cache_key.py +1057 -0
  196. sqlalchemy/sql/coercions.py +1404 -0
  197. sqlalchemy/sql/compiler.py +8034 -0
  198. sqlalchemy/sql/crud.py +1744 -0
  199. sqlalchemy/sql/ddl.py +1444 -0
  200. sqlalchemy/sql/default_comparator.py +551 -0
  201. sqlalchemy/sql/dml.py +1850 -0
  202. sqlalchemy/sql/elements.py +5589 -0
  203. sqlalchemy/sql/events.py +458 -0
  204. sqlalchemy/sql/expression.py +159 -0
  205. sqlalchemy/sql/functions.py +2139 -0
  206. sqlalchemy/sql/lambdas.py +1442 -0
  207. sqlalchemy/sql/naming.py +209 -0
  208. sqlalchemy/sql/operators.py +2623 -0
  209. sqlalchemy/sql/roles.py +323 -0
  210. sqlalchemy/sql/schema.py +6222 -0
  211. sqlalchemy/sql/selectable.py +7265 -0
  212. sqlalchemy/sql/sqltypes.py +3930 -0
  213. sqlalchemy/sql/traversals.py +1024 -0
  214. sqlalchemy/sql/type_api.py +2368 -0
  215. sqlalchemy/sql/util.py +1485 -0
  216. sqlalchemy/sql/visitors.py +1164 -0
  217. sqlalchemy/testing/__init__.py +96 -0
  218. sqlalchemy/testing/assertions.py +994 -0
  219. sqlalchemy/testing/assertsql.py +520 -0
  220. sqlalchemy/testing/asyncio.py +135 -0
  221. sqlalchemy/testing/config.py +434 -0
  222. sqlalchemy/testing/engines.py +478 -0
  223. sqlalchemy/testing/entities.py +117 -0
  224. sqlalchemy/testing/exclusions.py +476 -0
  225. sqlalchemy/testing/fixtures/__init__.py +28 -0
  226. sqlalchemy/testing/fixtures/base.py +366 -0
  227. sqlalchemy/testing/fixtures/mypy.py +332 -0
  228. sqlalchemy/testing/fixtures/orm.py +227 -0
  229. sqlalchemy/testing/fixtures/sql.py +482 -0
  230. sqlalchemy/testing/pickleable.py +155 -0
  231. sqlalchemy/testing/plugin/__init__.py +6 -0
  232. sqlalchemy/testing/plugin/bootstrap.py +51 -0
  233. sqlalchemy/testing/plugin/plugin_base.py +828 -0
  234. sqlalchemy/testing/plugin/pytestplugin.py +892 -0
  235. sqlalchemy/testing/profiling.py +327 -0
  236. sqlalchemy/testing/provision.py +597 -0
  237. sqlalchemy/testing/requirements.py +1940 -0
  238. sqlalchemy/testing/schema.py +198 -0
  239. sqlalchemy/testing/suite/__init__.py +19 -0
  240. sqlalchemy/testing/suite/test_cte.py +237 -0
  241. sqlalchemy/testing/suite/test_ddl.py +389 -0
  242. sqlalchemy/testing/suite/test_deprecations.py +153 -0
  243. sqlalchemy/testing/suite/test_dialect.py +776 -0
  244. sqlalchemy/testing/suite/test_insert.py +630 -0
  245. sqlalchemy/testing/suite/test_reflection.py +3557 -0
  246. sqlalchemy/testing/suite/test_results.py +504 -0
  247. sqlalchemy/testing/suite/test_rowcount.py +258 -0
  248. sqlalchemy/testing/suite/test_select.py +2010 -0
  249. sqlalchemy/testing/suite/test_sequence.py +317 -0
  250. sqlalchemy/testing/suite/test_types.py +2147 -0
  251. sqlalchemy/testing/suite/test_unicode_ddl.py +189 -0
  252. sqlalchemy/testing/suite/test_update_delete.py +139 -0
  253. sqlalchemy/testing/util.py +535 -0
  254. sqlalchemy/testing/warnings.py +52 -0
  255. sqlalchemy/types.py +74 -0
  256. sqlalchemy/util/__init__.py +162 -0
  257. sqlalchemy/util/_collections.py +717 -0
  258. sqlalchemy/util/_concurrency_py3k.py +288 -0
  259. sqlalchemy/util/_has_cy.py +40 -0
  260. sqlalchemy/util/_py_collections.py +541 -0
  261. sqlalchemy/util/compat.py +316 -0
  262. sqlalchemy/util/concurrency.py +110 -0
  263. sqlalchemy/util/deprecations.py +401 -0
  264. sqlalchemy/util/langhelpers.py +2306 -0
  265. sqlalchemy/util/preloaded.py +150 -0
  266. sqlalchemy/util/queue.py +322 -0
  267. sqlalchemy/util/tool_support.py +201 -0
  268. sqlalchemy/util/topological.py +120 -0
  269. sqlalchemy/util/typing.py +734 -0
  270. sqlalchemy-2.0.45.dist-info/METADATA +243 -0
  271. sqlalchemy-2.0.45.dist-info/RECORD +274 -0
  272. sqlalchemy-2.0.45.dist-info/WHEEL +5 -0
  273. sqlalchemy-2.0.45.dist-info/licenses/LICENSE +19 -0
  274. sqlalchemy-2.0.45.dist-info/top_level.txt +1 -0
@@ -0,0 +1,372 @@
1
+ # pool/events.py
2
+ # Copyright (C) 2005-2025 the SQLAlchemy authors and contributors
3
+ # <see AUTHORS file>
4
+ #
5
+ # This module is part of SQLAlchemy and is released under
6
+ # the MIT License: https://www.opensource.org/licenses/mit-license.php
7
+ from __future__ import annotations
8
+
9
+ import typing
10
+ from typing import Any
11
+ from typing import Optional
12
+ from typing import Type
13
+ from typing import Union
14
+
15
+ from .base import ConnectionPoolEntry
16
+ from .base import Pool
17
+ from .base import PoolProxiedConnection
18
+ from .base import PoolResetState
19
+ from .. import event
20
+ from .. import util
21
+
22
+ if typing.TYPE_CHECKING:
23
+ from ..engine import Engine
24
+ from ..engine.interfaces import DBAPIConnection
25
+
26
+
27
+ class PoolEvents(event.Events[Pool]):
28
+ """Available events for :class:`_pool.Pool`.
29
+
30
+ The methods here define the name of an event as well
31
+ as the names of members that are passed to listener
32
+ functions.
33
+
34
+ e.g.::
35
+
36
+ from sqlalchemy import event
37
+
38
+
39
+ def my_on_checkout(dbapi_conn, connection_rec, connection_proxy):
40
+ "handle an on checkout event"
41
+
42
+
43
+ event.listen(Pool, "checkout", my_on_checkout)
44
+
45
+ In addition to accepting the :class:`_pool.Pool` class and
46
+ :class:`_pool.Pool` instances, :class:`_events.PoolEvents` also accepts
47
+ :class:`_engine.Engine` objects and the :class:`_engine.Engine` class as
48
+ targets, which will be resolved to the ``.pool`` attribute of the
49
+ given engine or the :class:`_pool.Pool` class::
50
+
51
+ engine = create_engine("postgresql+psycopg2://scott:tiger@localhost/test")
52
+
53
+ # will associate with engine.pool
54
+ event.listen(engine, "checkout", my_on_checkout)
55
+
56
+ """ # noqa: E501
57
+
58
+ _target_class_doc = "SomeEngineOrPool"
59
+ _dispatch_target = Pool
60
+
61
+ @util.preload_module("sqlalchemy.engine")
62
+ @classmethod
63
+ def _accept_with(
64
+ cls,
65
+ target: Union[Pool, Type[Pool], Engine, Type[Engine]],
66
+ identifier: str,
67
+ ) -> Optional[Union[Pool, Type[Pool]]]:
68
+ if not typing.TYPE_CHECKING:
69
+ Engine = util.preloaded.engine.Engine
70
+
71
+ if isinstance(target, type):
72
+ if issubclass(target, Engine):
73
+ return Pool
74
+ else:
75
+ assert issubclass(target, Pool)
76
+ return target
77
+ elif isinstance(target, Engine):
78
+ return target.pool
79
+ elif isinstance(target, Pool):
80
+ return target
81
+ elif hasattr(target, "_no_async_engine_events"):
82
+ target._no_async_engine_events()
83
+ else:
84
+ return None
85
+
86
+ @classmethod
87
+ def _listen(
88
+ cls,
89
+ event_key: event._EventKey[Pool],
90
+ **kw: Any,
91
+ ) -> None:
92
+ target = event_key.dispatch_target
93
+
94
+ kw.setdefault("asyncio", target._is_asyncio)
95
+
96
+ event_key.base_listen(**kw)
97
+
98
+ def connect(
99
+ self,
100
+ dbapi_connection: DBAPIConnection,
101
+ connection_record: ConnectionPoolEntry,
102
+ ) -> None:
103
+ """Called at the moment a particular DBAPI connection is first
104
+ created for a given :class:`_pool.Pool`.
105
+
106
+ This event allows one to capture the point directly after which
107
+ the DBAPI module-level ``.connect()`` method has been used in order
108
+ to produce a new DBAPI connection.
109
+
110
+ :param dbapi_connection: a DBAPI connection.
111
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
112
+
113
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
114
+ the DBAPI connection.
115
+
116
+ """
117
+
118
+ def first_connect(
119
+ self,
120
+ dbapi_connection: DBAPIConnection,
121
+ connection_record: ConnectionPoolEntry,
122
+ ) -> None:
123
+ """Called exactly once for the first time a DBAPI connection is
124
+ checked out from a particular :class:`_pool.Pool`.
125
+
126
+ The rationale for :meth:`_events.PoolEvents.first_connect`
127
+ is to determine
128
+ information about a particular series of database connections based
129
+ on the settings used for all connections. Since a particular
130
+ :class:`_pool.Pool`
131
+ refers to a single "creator" function (which in terms
132
+ of a :class:`_engine.Engine`
133
+ refers to the URL and connection options used),
134
+ it is typically valid to make observations about a single connection
135
+ that can be safely assumed to be valid about all subsequent
136
+ connections, such as the database version, the server and client
137
+ encoding settings, collation settings, and many others.
138
+
139
+ :param dbapi_connection: a DBAPI connection.
140
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
141
+
142
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
143
+ the DBAPI connection.
144
+
145
+ """
146
+
147
+ def checkout(
148
+ self,
149
+ dbapi_connection: DBAPIConnection,
150
+ connection_record: ConnectionPoolEntry,
151
+ connection_proxy: PoolProxiedConnection,
152
+ ) -> None:
153
+ """Called when a connection is retrieved from the Pool.
154
+
155
+ :param dbapi_connection: a DBAPI connection.
156
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
157
+
158
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
159
+ the DBAPI connection.
160
+
161
+ :param connection_proxy: the :class:`.PoolProxiedConnection` object
162
+ which will proxy the public interface of the DBAPI connection for the
163
+ lifespan of the checkout.
164
+
165
+ If you raise a :class:`~sqlalchemy.exc.DisconnectionError`, the current
166
+ connection will be disposed and a fresh connection retrieved.
167
+ Processing of all checkout listeners will abort and restart
168
+ using the new connection.
169
+
170
+ .. seealso:: :meth:`_events.ConnectionEvents.engine_connect`
171
+ - a similar event
172
+ which occurs upon creation of a new :class:`_engine.Connection`.
173
+
174
+ """
175
+
176
+ def checkin(
177
+ self,
178
+ dbapi_connection: Optional[DBAPIConnection],
179
+ connection_record: ConnectionPoolEntry,
180
+ ) -> None:
181
+ """Called when a connection returns to the pool.
182
+
183
+ Note that the connection may be closed, and may be None if the
184
+ connection has been invalidated. ``checkin`` will not be called
185
+ for detached connections. (They do not return to the pool.)
186
+
187
+ :param dbapi_connection: a DBAPI connection.
188
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
189
+
190
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
191
+ the DBAPI connection.
192
+
193
+ """
194
+
195
+ @event._legacy_signature(
196
+ "2.0",
197
+ ["dbapi_connection", "connection_record"],
198
+ lambda dbapi_connection, connection_record, reset_state: (
199
+ dbapi_connection,
200
+ connection_record,
201
+ ),
202
+ )
203
+ def reset(
204
+ self,
205
+ dbapi_connection: DBAPIConnection,
206
+ connection_record: ConnectionPoolEntry,
207
+ reset_state: PoolResetState,
208
+ ) -> None:
209
+ """Called before the "reset" action occurs for a pooled connection.
210
+
211
+ This event represents
212
+ when the ``rollback()`` method is called on the DBAPI connection
213
+ before it is returned to the pool or discarded.
214
+ A custom "reset" strategy may be implemented using this event hook,
215
+ which may also be combined with disabling the default "reset"
216
+ behavior using the :paramref:`_pool.Pool.reset_on_return` parameter.
217
+
218
+ The primary difference between the :meth:`_events.PoolEvents.reset` and
219
+ :meth:`_events.PoolEvents.checkin` events are that
220
+ :meth:`_events.PoolEvents.reset` is called not just for pooled
221
+ connections that are being returned to the pool, but also for
222
+ connections that were detached using the
223
+ :meth:`_engine.Connection.detach` method as well as asyncio connections
224
+ that are being discarded due to garbage collection taking place on
225
+ connections before the connection was checked in.
226
+
227
+ Note that the event **is not** invoked for connections that were
228
+ invalidated using :meth:`_engine.Connection.invalidate`. These
229
+ events may be intercepted using the :meth:`.PoolEvents.soft_invalidate`
230
+ and :meth:`.PoolEvents.invalidate` event hooks, and all "connection
231
+ close" events may be intercepted using :meth:`.PoolEvents.close`.
232
+
233
+ The :meth:`_events.PoolEvents.reset` event is usually followed by the
234
+ :meth:`_events.PoolEvents.checkin` event, except in those
235
+ cases where the connection is discarded immediately after reset.
236
+
237
+ :param dbapi_connection: a DBAPI connection.
238
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
239
+
240
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
241
+ the DBAPI connection.
242
+
243
+ :param reset_state: :class:`.PoolResetState` instance which provides
244
+ information about the circumstances under which the connection
245
+ is being reset.
246
+
247
+ .. versionadded:: 2.0
248
+
249
+ .. seealso::
250
+
251
+ :ref:`pool_reset_on_return`
252
+
253
+ :meth:`_events.ConnectionEvents.rollback`
254
+
255
+ :meth:`_events.ConnectionEvents.commit`
256
+
257
+ """
258
+
259
+ def invalidate(
260
+ self,
261
+ dbapi_connection: DBAPIConnection,
262
+ connection_record: ConnectionPoolEntry,
263
+ exception: Optional[BaseException],
264
+ ) -> None:
265
+ """Called when a DBAPI connection is to be "invalidated".
266
+
267
+ This event is called any time the
268
+ :meth:`.ConnectionPoolEntry.invalidate` method is invoked, either from
269
+ API usage or via "auto-invalidation", without the ``soft`` flag.
270
+
271
+ The event occurs before a final attempt to call ``.close()`` on the
272
+ connection occurs.
273
+
274
+ :param dbapi_connection: a DBAPI connection.
275
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
276
+
277
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
278
+ the DBAPI connection.
279
+
280
+ :param exception: the exception object corresponding to the reason
281
+ for this invalidation, if any. May be ``None``.
282
+
283
+ .. seealso::
284
+
285
+ :ref:`pool_connection_invalidation`
286
+
287
+ """
288
+
289
+ def soft_invalidate(
290
+ self,
291
+ dbapi_connection: DBAPIConnection,
292
+ connection_record: ConnectionPoolEntry,
293
+ exception: Optional[BaseException],
294
+ ) -> None:
295
+ """Called when a DBAPI connection is to be "soft invalidated".
296
+
297
+ This event is called any time the
298
+ :meth:`.ConnectionPoolEntry.invalidate`
299
+ method is invoked with the ``soft`` flag.
300
+
301
+ Soft invalidation refers to when the connection record that tracks
302
+ this connection will force a reconnect after the current connection
303
+ is checked in. It does not actively close the dbapi_connection
304
+ at the point at which it is called.
305
+
306
+ :param dbapi_connection: a DBAPI connection.
307
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
308
+
309
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
310
+ the DBAPI connection.
311
+
312
+ :param exception: the exception object corresponding to the reason
313
+ for this invalidation, if any. May be ``None``.
314
+
315
+ """
316
+
317
+ def close(
318
+ self,
319
+ dbapi_connection: DBAPIConnection,
320
+ connection_record: ConnectionPoolEntry,
321
+ ) -> None:
322
+ """Called when a DBAPI connection is closed.
323
+
324
+ The event is emitted before the close occurs.
325
+
326
+ The close of a connection can fail; typically this is because
327
+ the connection is already closed. If the close operation fails,
328
+ the connection is discarded.
329
+
330
+ The :meth:`.close` event corresponds to a connection that's still
331
+ associated with the pool. To intercept close events for detached
332
+ connections use :meth:`.close_detached`.
333
+
334
+ :param dbapi_connection: a DBAPI connection.
335
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
336
+
337
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
338
+ the DBAPI connection.
339
+
340
+ """
341
+
342
+ def detach(
343
+ self,
344
+ dbapi_connection: DBAPIConnection,
345
+ connection_record: ConnectionPoolEntry,
346
+ ) -> None:
347
+ """Called when a DBAPI connection is "detached" from a pool.
348
+
349
+ This event is emitted after the detach occurs. The connection
350
+ is no longer associated with the given connection record.
351
+
352
+ :param dbapi_connection: a DBAPI connection.
353
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
354
+
355
+ :param connection_record: the :class:`.ConnectionPoolEntry` managing
356
+ the DBAPI connection.
357
+
358
+ """
359
+
360
+ def close_detached(self, dbapi_connection: DBAPIConnection) -> None:
361
+ """Called when a detached DBAPI connection is closed.
362
+
363
+ The event is emitted before the close occurs.
364
+
365
+ The close of a connection can fail; typically this is because
366
+ the connection is already closed. If the close operation fails,
367
+ the connection is discarded.
368
+
369
+ :param dbapi_connection: a DBAPI connection.
370
+ The :attr:`.ConnectionPoolEntry.dbapi_connection` attribute.
371
+
372
+ """