zmc
2023-10-12 ed135d79df12a2466b52dae1a82326941211dcc9
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
U
¸ý°dqÒã
@s”UdZddlmZddlmZddlZddlmZddlZddl    Z    ddl
Z
ddl
m Z ddl
m Z ddl
m Z dd    l
mZdd
l
mZdd l
mZdd l
mZdd l
mZddl
mZddl
mZddlZddlmZddlmZddlmZddlmZddlmZddlmZerlddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$ddl%m&Z&ej'ddGd d!„d!ƒƒZ(Gd"d#„d#eƒZ)ee)ed$fZ*e+e)ƒ\Z,Z-Z.Gd%d&„d&ƒZ/Gd'd(„d(e/ƒZ0Gd)d*„d*eƒZ1Gd+d,„d,eƒZ2Gd-d.„d.ej3ej4ƒZ5Gd/d0„d0ƒZ6Gd1d2„d2e6ƒZ7Gd3d4„d4e7ƒZ8dHd6d7d.d8d9d:d;d<d=œd>d?„Z9iZ:d@e;dA<GdBdC„dCe6ƒZ<GdDdE„dEe<ƒZ=GdFdG„dGe<ƒZ>dS)Iz'Base constructs for connection pools.
 
é)Ú annotations)ÚdequeN)ÚEnum)ÚAny)ÚCallable)Úcast)ÚDeque)ÚDict)ÚList)ÚOptional)ÚTuple)Ú TYPE_CHECKING)ÚUnioné)Úevent)Úexc)Úlog)Úutil)ÚLiteral)ÚProtocol)ÚDBAPIConnection)Ú DBAPICursor)ÚDialect)Ú_DispatchCommon)Ú_ListenerFnType)Ú
dispatcher)Ú    _InfoTypeT)Úfrozenc@s.eZdZUdZdZded<ded<ded<dS)ÚPoolResetStatez describes the state of a DBAPI connection as it is being passed to
    the :meth:`.PoolEvents.reset` connection pool event.
 
    .. versionadded:: 2.0.0b3
 
    ©Útransaction_was_resetÚterminate_onlyÚ asyncio_safeÚboolr r!r"N)Ú__name__Ú
__module__Ú __qualname__Ú__doc__Ú    __slots__Ú__annotations__©r*r*úKd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/pool/base.pyr2s
  rc@seZdZdZdZdZdZdS)Ú
ResetStylez1Describe options for "reset on return" behaviors.rérN)r$r%r&r'Úreset_rollbackÚ reset_commitÚ
reset_noner*r*r*r+r,_sr,)TNFÚcommitÚrollbackc@sxeZdZdZdZdZdddœdd„Zdddœdd    „Zd
ddœd d „Zd
ddœd d„Z    d
ddœdd„Z
d
ddœdd„Z dS)Ú _ConnDialectzýpartial implementation of :class:`.Dialect`
    which provides DBAPI connection methods.
 
    When a :class:`_pool.Pool` is combined with an :class:`_engine.Engine`,
    the :class:`_engine.Engine` replaces this with its own
    :class:`.Dialect`.
 
    FÚPoolProxiedConnectionÚNone)Údbapi_connectionÚreturncCs | ¡dS©N)r2©Úselfr6r*r*r+Ú do_rollback{sz_ConnDialect.do_rollbackcCs | ¡dSr8)r1r9r*r*r+Ú    do_commit~sz_ConnDialect.do_commitrcCs | ¡dSr8©Úcloser9r*r*r+Ú do_terminatesz_ConnDialect.do_terminatecCs | ¡dSr8r=r9r*r*r+Údo_close„sz_ConnDialect.do_closer#cCs tdƒ‚dS)NzJThe ping feature requires that a dialect is passed to the connection pool.©ÚNotImplementedErrorr9r*r*r+Ú_do_ping_w_event‡sÿz_ConnDialect._do_ping_w_eventr)Ú
connectionr7cCs|Sr8r*)r:rDr*r*r+Úget_driver_connectionsz"_ConnDialect.get_driver_connectionN) r$r%r&r'Úis_asyncÚ has_terminater;r<r?r@rCrEr*r*r*r+r3ns    r3c@seZdZdZdS)Ú_AsyncConnDialectTN)r$r%r&rFr*r*r*r+rH‘srHc@seZdZddœdd„ZdS)Ú_CreatorFnTyper©r7cCsdSr8r*©r:r*r*r+Ú__call__–sz_CreatorFnType.__call__N©r$r%r&rLr*r*r*r+rI•srIc@seZdZdddœdd„ZdS)Ú_CreatorWRecFnTypeÚConnectionPoolEntryr)Úrecr7cCsdSr8r*©r:rPr*r*r+rL›sz_CreatorWRecFnType.__call__NrMr*r*r*r+rNšsrNc @sreZdZUdZded<ded<ded<eƒZded    <d
ed <d ed <ded<dEd
dddddddddœ    dd„Zej    ddœdd„ƒZ
e d
dœd d!„ƒZ e j d
d"d#œd$d!„ƒZ e jd"dœd%d!„ƒZ d
d d#œd&d'„Zdd(œd)dd"d*œd+d,„Zd-dœd.d/„ZdFd0d1dd"d2œd3d4„Zddœd5d6„Zd"dœd7d8„Zd0dœd9d:„Zd-d"d;œd<d=„Zd-dœd>d?„Zd-d"d;œd@dA„ZdBdœdCdD„ZdS)GÚPoolz)Abstract base class for connection pools.zdispatcher[Pool]Údispatchúlog._EchoFlagTypeÚechoz Optional[str]Ú_orig_logging_namezUnion[_ConnDialect, Dialect]Ú_dialectz)Union[_CreatorFnType, _CreatorWRecFnType]Ú _creator_argrNÚ_invoke_creatorÚfloatÚ_invalidate_timeéÿÿÿÿNTFÚintÚ_ResetStyleArgTypez+Optional[List[Tuple[_ListenerFnType, str]]]z&Optional[Union[_ConnDialect, Dialect]]r#zOptional[_DispatchCommon[Pool]])    ÚcreatorÚrecyclerUÚ logging_nameÚreset_on_returnÚeventsÚdialectÚpre_pingÚ    _dispatchc
    Cs´|r||_|_nd|_tj||d||_||_d|_||_t     |t
j ddgt
j dddgt
j dgid    ¡|_||_|    r†|jj|    dd
|r||_|r°|D]\}
} t || |
¡q˜dS) a4
        Construct a Pool.
 
        :param creator: a callable function that returns a DB-API
          connection object.  The function will be called with
          parameters.
 
        :param recycle: If set to a value other than -1, number of
          seconds between connection recycling, which means upon
          checkout, if this timeout is surpassed the connection will be
          closed and replaced with a newly opened connection. Defaults to -1.
 
        :param logging_name:  String identifier which will be used within
          the "name" field of logging records generated within the
          "sqlalchemy.pool" logger. Defaults to a hexstring of the object's
          id.
 
        :param echo: if True, the connection pool will log
         informational output such as when connections are invalidated
         as well as when connections are recycled to the default log handler,
         which defaults to ``sys.stdout`` for output..   If set to the string
         ``"debug"``, the logging will include pool checkouts and checkins.
 
         The :paramref:`_pool.Pool.echo` parameter can also be set from the
         :func:`_sa.create_engine` call by using the
         :paramref:`_sa.create_engine.echo_pool` parameter.
 
         .. seealso::
 
             :ref:`dbengine_logging` - further detail on how to configure
             logging.
 
        :param reset_on_return: Determine steps to take on
         connections as they are returned to the pool, which were
         not otherwise handled by a :class:`_engine.Connection`.
         Available from :func:`_sa.create_engine` via the
         :paramref:`_sa.create_engine.pool_reset_on_return` parameter.
 
         :paramref:`_pool.Pool.reset_on_return` can have any of these values:
 
         * ``"rollback"`` - call rollback() on the connection,
           to release locks and transaction resources.
           This is the default value.  The vast majority
           of use cases should leave this value set.
         * ``"commit"`` - call commit() on the connection,
           to release locks and transaction resources.
           A commit here may be desirable for databases that
           cache query plans if a commit is emitted,
           such as Microsoft SQL Server.  However, this
           value is more dangerous than 'rollback' because
           any data changes present on the transaction
           are committed unconditionally.
         * ``None`` - don't do anything on the connection.
           This setting may be appropriate if the database / DBAPI
           works in pure "autocommit" mode at all times, or if
           a custom reset handler is established using the
           :meth:`.PoolEvents.reset` event handler.
 
         * ``True`` - same as 'rollback', this is here for
           backwards compatibility.
         * ``False`` - same as None, this is here for
           backwards compatibility.
 
         For further customization of reset on return, the
         :meth:`.PoolEvents.reset` event hook may be used which can perform
         any connection activity desired on reset.
 
         .. seealso::
 
            :ref:`pool_reset_on_return`
 
            :meth:`.PoolEvents.reset`
 
        :param events: a list of 2-tuples, each of the form
         ``(callable, target)`` which will be passed to :func:`.event.listen`
         upon construction.   Provided here so that event listeners
         can be assigned via :func:`_sa.create_engine` before dialect-level
         listeners are applied.
 
        :param dialect: a :class:`.Dialect` that will handle the job
         of calling rollback(), close(), or commit() on DBAPI connections.
         If omitted, a built-in "stub" dialect is used.   Applications that
         make use of :func:`_sa.create_engine` should not use this parameter
         as it is handled by the engine creation strategy.
 
        :param pre_ping: if True, the pool will emit a "ping" (typically
         "SELECT 1", but is dialect-specific) on the connection
         upon checkout, to test if the connection is alive or not.   If not,
         the connection is transparently re-connected and upon success, all
         other pooled connections established prior to that timestamp are
         invalidated.     Requires that a dialect is passed as well to
         interpret the disconnection error.
 
         .. versionadded:: 1.2
 
        N)Zechoflagrr2TÚnoneFr1rb)Zonly_propagate)rarVrZinstance_loggerÚ_creatorÚ_recycler[Ú    _pre_pingrZparse_user_argument_for_enumr,r.r0r/Ú_reset_on_returnrUrSÚ_updaterWrÚlisten) r:r_r`rUrarbrcrdrerfÚfnÚtargetr*r*r+Ú__init__¬s6lýù
 z Pool.__init__rJcCs|jjSr8)rWrFrKr*r*r+Ú _is_asyncio6szPool._is_asynciocCs|jSr8)rXrKr*r*r+rh:sz Pool._creatorr5)r_r7cCs||_| |¡|_dSr8)rXÚ_should_wrap_creatorrY)r:r_r*r*r+rh>scCs |`|`dSr8)rXrYrKr*r*r+rhHscsºztj|jdd}Wn*tk
r>tt|ƒ‰‡fdd„YSX|jdk    rVt|jƒ}nd}t|dƒ|}|d|dfdgd    fkrŽtt|ƒS|d
kr tt|ƒStt|ƒ‰‡fd d„SdS) zlDetect if creator accepts a single argument, or is sent
        as a legacy style no-arg function.
 
        T)Zno_selfcsˆƒSr8r*©rP©Z
creator_fnr*r+Ú<lambda>Zóz+Pool._should_wrap_creator.<locals>.<lambda>NréÚconnection_recordr8r-csˆƒSr8r*rsrtr*r+rumrv)    rZget_callable_argspecrhÚ    TypeErrorrrIÚdefaultsÚlenrN)r:r_ZargspecZ    defaultedZ positionalsr*rtr+rrNs
 
 
 
 
zPool._should_wrap_creator©Ú    terminater)rDr}r7c
Cs|j d|rdnd|¡z"|r,|j |¡n |j |¡WnPtk
rŠ}z2|jjd|r\dnd›d|dd    t|tƒsz‚W5d}~XYnXdS)
Nz%s connection %rz Hard-closingZClosingz
Exception Z terminatingÚclosingz connection %rT©Úexc_info)    ÚloggerÚdebugrWr?r@Ú BaseExceptionÚerrorÚ
isinstanceÚ    Exception)r:rDr}Úer*r*r+Ú_close_connectionos"
ýü
zPool._close_connectionrOcCst|ƒS)z6Called by subclasses to create a new ConnectionRecord.)Ú_ConnectionRecordrKr*r*r+Ú_create_connection†szPool._create_connectionr4úOptional[BaseException])rDÚ    exceptionÚ_checkinr7cCsDt|ddƒ}|r|j|jkr&t ¡|_|r@t|ddƒr@| |¡dS)ašMark all connections established within the generation
        of the given connection as invalidated.
 
        If this pool's last invalidate time is before when the given
        connection was created, update the timestamp til now.  Otherwise,
        no action is performed.
 
        Connections with a start time prior to this pool's invalidation
        time will be recycled upon next checkout.
        Ú_connection_recordNÚis_validF)Úgetattrr[Ú    starttimeÚtimeÚ
invalidate)r:rDrŒrrPr*r*r+Ú _invalidate‹s
 
zPool._invalidatecCs
tƒ‚dS)a"Return a new :class:`_pool.Pool`, of the same class as this one
        and configured with identical creation arguments.
 
        This method is used in conjunction with :meth:`dispose`
        to close out an entire :class:`_pool.Pool` and create a new one in
        its place.
 
        NrArKr*r*r+Úrecreate¡s
z Pool.recreatecCs
tƒ‚dS)zùDispose of this pool.
 
        This method leaves the possibility of checked-out connections
        remaining open, as it only affects connections that are
        idle in the pool.
 
        .. seealso::
 
            :meth:`Pool.recreate`
 
        NrArKr*r*r+Údispose­s z Pool.disposecCs
t |¡S)zÈReturn a DBAPI connection from the pool.
 
        The connection is instrumented such that when its
        ``close()`` method is called, the connection will be returned to
        the pool.
 
        )Ú_ConnectionFairyÚ    _checkoutrKr*r*r+Úconnect¼sz Pool.connect)Úrecordr7cCs| |¡dS)zºGiven a _ConnectionRecord, return it to the :class:`_pool.Pool`.
 
        This method is called when an instrumented DBAPI connection
        has its ``close()`` method called.
 
        N)Ú_do_return_conn©r:ršr*r*r+Ú _return_connÆszPool._return_conncCs
tƒ‚dS)z7Implementation for :meth:`get`, supplied by subclasses.NrArKr*r*r+Ú_do_getÏsz Pool._do_getcCs
tƒ‚dS)z?Implementation for :meth:`return_conn`, supplied by subclasses.NrArœr*r*r+r›ÔszPool._do_return_connÚstrcCs
tƒ‚dSr8rArKr*r*r+ÚstatusÙsz Pool.status)r\NNTNNFN)NT)r$r%r&r'r)r3rWrprZhybridpropertyrqÚpropertyrhÚsetterÚdeleterrrrˆrŠr”r•r–r™rržr›r r*r*r*r+rRŸsP
ö      "ÿü 
    rRc@sbeZdZUdZdZded<ded<ejddœd    d
„ƒZejd dœd d „ƒZ    dddddœdd„Z
dS)ÚManagesConnectiona3Common base for the two connection-management interfaces
    :class:`.PoolProxiedConnection` and :class:`.ConnectionPoolEntry`.
 
    These two objects are typically exposed in the public facing API
    via the connection pool event hooks, documented at :class:`.PoolEvents`.
 
    .. versionadded:: 2.0
 
    r*úOptional[DBAPIConnection]r6ú Optional[Any]Údriver_connectionrrJcCs
tƒ‚dS)a˜Info dictionary associated with the underlying DBAPI connection
        referred to by this :class:`.ManagesConnection` instance, allowing
        user-defined data to be associated with the connection.
 
        The data in this dictionary is persistent for the lifespan
        of the DBAPI connection itself, including across pool checkins
        and checkouts.  When the connection is invalidated
        and replaced with a new one, this dictionary is cleared.
 
        For a :class:`.PoolProxiedConnection` instance that's not associated
        with a :class:`.ConnectionPoolEntry`, such as if it were detached, the
        attribute returns a dictionary that is local to that
        :class:`.ConnectionPoolEntry`. Therefore the
        :attr:`.ManagesConnection.info` attribute will always provide a Python
        dictionary.
 
        .. seealso::
 
            :attr:`.ManagesConnection.record_info`
 
 
        NrArKr*r*r+ÚinfoszManagesConnection.infoúOptional[_InfoType]cCs
tƒ‚dS)a÷Persistent info dictionary associated with this
        :class:`.ManagesConnection`.
 
        Unlike the :attr:`.ManagesConnection.info` dictionary, the lifespan
        of this dictionary is that of the :class:`.ConnectionPoolEntry`
        which owns it; therefore this dictionary will persist across
        reconnects and connection invalidation for a particular entry
        in the connection pool.
 
        For a :class:`.PoolProxiedConnection` instance that's not associated
        with a :class:`.ConnectionPoolEntry`, such as if it were detached, the
        attribute returns None. Contrast to the :attr:`.ManagesConnection.info`
        dictionary which is never None.
 
 
        .. seealso::
 
            :attr:`.ManagesConnection.info`
 
        NrArKr*r*r+Ú record_info.szManagesConnection.record_infoNFr‹r#r5©r‡Úsoftr7cCs
tƒ‚dS)aOMark the managed connection as invalidated.
 
        :param e: an exception object indicating a reason for the invalidation.
 
        :param soft: if True, the connection isn't closed; instead, this
         connection will be recycled on next checkout.
 
        .. seealso::
 
            :ref:`pool_connection_invalidation`
 
 
        NrA©r:r‡r¬r*r*r+r“FszManagesConnection.invalidate)NF) r$r%r&r'r(r)rÚro_memoized_propertyr¨rªr“r*r*r*r+r¤Ýs
 
ÿr¤c@s4eZdZdZdZeddœdd„ƒZddœdd    „Zd
S) rOaInterface for the object that maintains an individual database
    connection on behalf of a :class:`_pool.Pool` instance.
 
    The :class:`.ConnectionPoolEntry` object represents the long term
    maintainance of a particular connection for a pool, including expiring or
    invalidating that connection to have it replaced with a new one, which will
    continue to be maintained by that same :class:`.ConnectionPoolEntry`
    instance. Compared to :class:`.PoolProxiedConnection`, which is the
    short-term, per-checkout connection manager, this object lasts for the
    lifespan of a particular "slot" within a connection pool.
 
    The :class:`.ConnectionPoolEntry` object is mostly visible to public-facing
    API code when it is delivered to connection pool event hooks, such as
    :meth:`_events.PoolEvents.connect` and :meth:`_events.PoolEvents.checkout`.
 
    .. versionadded:: 2.0  :class:`.ConnectionPoolEntry` provides the public
       facing interface for the :class:`._ConnectionRecord` internal class.
 
    r*r#rJcCs
tƒ‚dS)z3Return True the connection is currently checked outNrArKr*r*r+Úin_usepszConnectionPoolEntry.in_user5cCs
tƒ‚dS)zAClose the DBAPI connection managed by this connection pool entry.NrArKr*r*r+r>vszConnectionPoolEntry.closeN)r$r%r&r'r(r¡r¯r>r*r*r*r+rOYs
rOc@steZdZUdZdZded<ded<ded<d    ed
<dEd dd œdd„Zded<eddœdd„ƒZee     
dd¡ddœdd„ƒƒZ dZ d    ed<e    j ddœdd„ƒZe    j ddœd d!„ƒZed d"d#œd$d%„ƒZdFd&dd'd(œd)d*„ZdGdd'd+œd,d-„Zeddœd.d/„ƒZed    dœd0d1„ƒZd'dœd2d3„ZdHd6dd'd7œd8d9„Zd:dœd;d<„Zddœd=d>„Zd5d?œdd'd@œdAdB„Zd'dœdCdD„Zd4S)Ir‰aMaintains a position in a connection pool which references a pooled
    connection.
 
    This is an internal object used by the :class:`_pool.Pool` implementation
    to provide context management to a DBAPI connection maintained by
    that :class:`_pool.Pool`.   The public facing interface for this class
    is described by the :class:`.ConnectionPoolEntry` class.  See that
    class for public API details.
 
    .. seealso::
 
        :class:`.ConnectionPoolEntry`
 
        :class:`.PoolProxiedConnection`
 
    )Z__poolÚ    fairy_refÚfinalize_callbackÚfreshr‘r6Ú __weakref__Ú__dict__z(Deque[Callable[[DBAPIConnection], None]]r±r#r²ú'Optional[weakref.ref[_ConnectionFairy]]r°rZr‘TrR)Úpoolr™cCs6d|_d|_d|_d|_||_|r*| ¡tƒ|_dS)NFr)r²r°r‘r6Ú_ConnectionRecord__poolÚ_ConnectionRecord__connectrr±)r:r¶r™r*r*r+rpžsz_ConnectionRecord.__init__r¥r6r¦rJcCs"|jdkrdS|jj |j¡SdSr8)r6r·rWrErKr*r*r+r§«s
 
ÿz#_ConnectionRecord.driver_connectionú2.0zXThe _ConnectionRecord.connection attribute is deprecated; please use 'driver_connection'cCs|jSr8©r6rKr*r*r+rD´sz_ConnectionRecord.connectionrÚ_soft_invalidate_timercCsiSr8r*rKr*r*r+r¨¿sz_ConnectionRecord.infor©cCsiSr8r*rKr*r*r+rªÃsz_ConnectionRecord.record_infor—)r¶r7c sÂtrttˆ ¡ƒ‰nˆ ¡‰z ˆ ¡}WnFtk
rn}z(t ¡ˆj|ddW5QRX‚W5d}~XYnXˆ     ¡‰t
ˆ|ˆˆƒ}t   |‡‡‡fdd„¡ˆ_ }ˆt|<ˆr¾ˆj d|¡|S)NF©Ú_fairy_was_createdcs tdk    rtdˆˆ|ˆddSdS)NF©r )Ú_finalize_fairy)Úref©rUr¶rPr*r+ruÜsýÿz,_ConnectionRecord.checkout.<locals>.<lambda>z#Connection %r checked out from pool)r rr‰ržÚget_connectionrƒrÚ safe_reraiseÚ_checkin_failedZ_should_log_debugr—ÚweakrefrÀr°Ú_strong_ref_connection_recordsrr‚)Úclsr¶r6ÚerrÚfairyrÀr*rÁr+ÚcheckoutÇs, 
þ
ÿz_ConnectionRecord.checkoutrƒr5)rÈr½r7cCs|j|d|j|ddS)N©r‡r¼)r“Úcheckin)r:rÈr½r*r*r+rÄés ÿz!_ConnectionRecord._checkin_failed)r½r7cCsx|jdkr |r t d|¡dSd|_|j}|j}|jrT|j ¡}|dk    r2||ƒq2|jjrj|j ||¡|     |¡dS)NzDouble checkin attempted on %s)
r°rÚwarnr6r·r±ÚpoprSrÌr)r:r½rDr¶Ú    finalizerr*r*r+rÌñs
 
z_ConnectionRecord.checkincCs
|jdk    Sr8)r°rKr*r*r+r¯sz_ConnectionRecord.in_usecCs|jSr8)r‘rKr*r*r+Úlast_connect_time sz#_ConnectionRecord.last_connect_timecCs|jdk    r| ¡dSr8)r6Ú_ConnectionRecord__closerKr*r*r+r>s
z_ConnectionRecord.closeNFr‹r«cCs¬|jdkrdS|r(|jj |j||¡n|jj |j||¡|dk    rj|jj d|rVdnd|j|jj|¡n|jj d|r|dnd|j¡|r–t         ¡|_
n|j ddd|_dS)Nz*%sInvalidate connection %r (reason: %s:%s)zSoft Úz%sInvalidate connection %rTr|) r6r·rSZsoft_invalidater“rr¨Ú    __class__r$r’r»rÑr­r*r*r+r“s4
ÿ
û
ý  z_ConnectionRecord.invalidatercCsÚd}|jdkr"|j ¡| ¡n‚|jjdkr\t ¡|j|jjkr\|jj d|j¡d}nH|jj    |jkr‚|jj d|j¡d}n"|j
|jkr¤|jj d|j¡d}|rÆ|j dd|j ¡| ¡|jdk    sÔt ‚|jS)NFr\z)Connection %r exceeded timeout; recyclingTz=Connection %r invalidated due to pool invalidation; recyclingzCConnection %r invalidated due to local soft invalidation; recyclingr|) r6r¨Úclearr¸r·rir’r‘rr[r»rÑÚAssertionError)r:r`r*r*r+rÂ5s>
 
 
 
ÿþþý ý 
z _ConnectionRecord.get_connectioncCs$|jdkp"|jj|jkp"|j|jkSr8)r6r·r[r‘r»rKr*r*r+Ú_is_hard_or_soft_invalidatedis
 
 ÿ
ýz._ConnectionRecord._is_hard_or_soft_invalidatedr|)r}r7cCsP|j ¡|jjjr&|jj |j|¡|jdk    s4t‚|jj|j|dd|_dS)Nr|)r±rÔr·rSr>r6rÕrˆ)r:r}r*r*r+Ú__closeps
 
ÿz_ConnectionRecord.__closec CsÄ|j}d|_z2t ¡|_| |¡|_}|j d|¡d|_WnDtk
r‚}z&t     
¡|j d|¡W5QRXW5d}~XYn>X|j j r¦|j j   |j ¡ |j|¡|j j  |j ¡ |j|¡dS)NzCreated new connection %rTzError on connect(): %s)r·r6r’r‘rYrr‚r²rƒrrÃrSZ first_connectZ
for_modifyZexec_once_unless_exceptionr™Z_exec_w_sync_on_first_run)r:r¶rDr‡r*r*r+Z    __connectzs.
 
 
*ÿþÿþz_ConnectionRecord.__connect)T)T)T)NF)r$r%r&r'r(r)rpr¡r§rÚ
deprecatedrDr»r®r¨rªÚ classmethodrÊrÄrÌr¯rÐr>r“rÂrÖrÑr¸r*r*r*r+r‰{sL
  þ "ÿÿ!4
r‰Fr¥úOptional[_ConnectionRecord]rµzOptional[log._EchoFlagType]r#úOptional[_ConnectionFairy]r5)r6rxr¶rÀrUr rÉr7c Cs:|dk    }|rR|dk    st‚t |d¡|dk    s0t‚|j|k    r>dS|dksJt‚|j}n|rht t |¡d¡|jj}|rª|dkp~|}    | }
|jj p–|jj    } |jjo¦|jj    } n|dk}    d}
} d} |dk    r
|rÞ|rÞ|j
  d|¡zäzŠ|s|dk    sôt‚t||||ƒ}|j|kst‚|j|||    |
d
|    rh|r>||_| ¡| rh|jjrZ|j |¡|j|| d WnTtk
r¾}z4|j
j d dd |r |j|dt|tƒs®‚W5d}~XYnXW5|    r|r|rd|›d| sèdnd›d    } |j
  | ¡t  | ¡X|r$|jdk    r$| ¡d|_|_~~~dS)acCleanup for a :class:`._ConnectionFairy` whether or not it's already
    been garbage collected.
 
    When using an async dialect no IO can happen here (without using
    a dedicated thread), since this is called outside the greenlet
    context and with an already running loop. In this case function
    will only log a message and raise a warning.
    NTFz$Connection %r being returned to poolzFThe garbage collector is trying to clean up non-checked-in connection z, which will be z*dropped, as it cannot be safely terminatedZ
terminatedzº.  Please ensure that SQLAlchemy pooled connections are returned to the pool explicitly, either by calling ``close()`` or by using appropriate context managers to manage their lifecycle.rr|z!Exception during reset or similarrrË)rÕrÆrÎr°r6rÅrÀrWrFrGrr‚r„rrÍr—Ú_resetÚ_poolÚdetachrSZclose_detachedrˆrƒr“r…r†rÌrŽ)r6rxr¶rÀrUr rÉZ is_gc_cleanupZdont_restore_gcedrÞZcan_manipulate_connectionZ!can_close_or_terminate_connectionZrequires_terminate_for_closeÚmessager‡r*r*r+r¿—sž   
  ÿÿ
ÿ üü
 þ
ÿ  ÿýÿ   r¿z6Dict[weakref.ref[_ConnectionFairy], _ConnectionRecord]rÆc@s„eZdZdZdZejr@ddœdd„Zddœdd    „Zddœd
d „Z    e
d dœd d„ƒZ e
d dœdd„ƒZ ddœdd„Z ddœdd„ZdS)r4aA connection-like adapter for a :pep:`249` DBAPI connection, which
    includes additional methods specific to the :class:`.Pool` implementation.
 
    :class:`.PoolProxiedConnection` is the public-facing interface for the
    internal :class:`._ConnectionFairy` implementation object; users familiar
    with :class:`._ConnectionFairy` can consider this object to be equivalent.
 
    .. versionadded:: 2.0  :class:`.PoolProxiedConnection` provides the public-
       facing interface for the :class:`._ConnectionFairy` internal class.
 
    r*r5rJcCsdSr8r*rKr*r*r+r13szPoolProxiedConnection.commitrcCsdSr8r*rKr*r*r+Úcursor6szPoolProxiedConnection.cursorcCsdSr8r*rKr*r*r+r29szPoolProxiedConnection.rollbackr#cCs
tƒ‚dS)zgReturn True if this :class:`.PoolProxiedConnection` still refers
        to an active DBAPI connection.NrArKr*r*r+r<szPoolProxiedConnection.is_validcCs
tƒ‚dS)zVReturn True if this :class:`.PoolProxiedConnection` is detached
        from its pool.NrArKr*r*r+Ú is_detachedCsz!PoolProxiedConnection.is_detachedcCs
tƒ‚dS)aSeparate this connection from its Pool.
 
        This means that the connection will no longer be returned to the
        pool when closed, and will instead be literally closed.  The
        associated :class:`.ConnectionPoolEntry` is de-associated from this
        DBAPI connection.
 
        Note that any overall connection limiting constraints imposed by a
        Pool implementation may be violated after a detach, as the detached
        connection is removed from the pool's knowledge and control.
 
        NrArKr*r*r+rÞJszPoolProxiedConnection.detachcCs
tƒ‚dS)a$Release this connection back to the pool.
 
        The :meth:`.PoolProxiedConnection.close` method shadows the
        :pep:`249` ``.close()`` method, altering its behavior to instead
        :term:`release` the proxied connection back to the connection pool.
 
        Upon release to the pool, whether the connection stays "opened" and
        pooled in the Python process, versus actually closed out and removed
        from the Python process, is based on the pool implementation in use and
        its configuration and current state.
 
        NrArKr*r*r+r>Zs zPoolProxiedConnection.closeN)r$r%r&r'r(Útypingr r1ràr2r¡rrárÞr>r*r*r*r+r4"s r4c@s¶eZdZUdZdZded<ded<dddœdd    „Zed
d œd d „ƒZedd œdd„ƒZ    edd œdd„ƒZ
d$ddddœdd„Z e j dd œdd„ƒZd
d
ddœdd „Zd
d
d!œd"d#„ZdS)%Ú_AdhocProxiedConnectionadprovides the :class:`.PoolProxiedConnection` interface for cases where
    the DBAPI connection is not actually proxied.
 
    This is used by the engine internals to pass a consistent
    :class:`.PoolProxiedConnection` object to consuming dialects in response to
    pool events that may not always have the :class:`._ConnectionFairy`
    available.
 
    ©r6rŽÚ    _is_validrr6rOrŽ)r6rxcCs||_||_d|_dS)NTrä)r:r6rxr*r*r+rpzsz _AdhocProxiedConnection.__init__rrJcCs|jjSr8©rŽr§rKr*r*r+r§ƒsz)_AdhocProxiedConnection.driver_connectioncCs|jSr8rºrKr*r*r+rD‡sz"_AdhocProxiedConnection.connectionr#cCs|jS)z©Implement is_valid state attribute.
 
        for the adhoc proxied connection it's assumed the connection is valid
        as there is no "invalidate" routine.
 
        ©rårKr*r*r+r‹sz _AdhocProxiedConnection.is_validNFr‹r5r«cCs
d|_dS)NFrçr­r*r*r+r“•sz"_AdhocProxiedConnection.invalidater©cCs|jjSr8©rŽrªrKr*r*r+rªšsz#_AdhocProxiedConnection.record_infor©ÚargsÚkwargsr7cOs|jj||ŽSr8)r6rà©r:rêrër*r*r+ràžsz_AdhocProxiedConnection.cursor©Úkeyr7cCs t|j|ƒSr8©rr6©r:rîr*r*r+Ú __getattr__¡sz#_AdhocProxiedConnection.__getattr__)NF)r$r%r&r'r(r)rpr¡r§rDrr“rÚro_non_memoized_propertyrªràrñr*r*r*r+rãjs$
 
    
ÿrãc@sšeZdZUdZdZded<ded<ded<ddd    dd
œd d „Zd ed<eddœdd„ƒZee     
dd¡ddœdd„ƒƒZ e dKdddddœdd„ƒZ ddœdd„ZdLd d!d"œd#d$„Zd!dœd%d&„Zdd d d d!d'œd(d)„Zed*dœd+d,„ƒZed dœd-d.„ƒZed dœd/d0„ƒZe    jd1dœd2d3„ƒZe    jd4dœd5d6„ƒZdMd7d d!d8œd9d:„Zd;d;d<d=œd>d?„Zd@d;dAœdBdC„Zd!dœdDdE„Zd!dœdFdG„ZdNd d!dHœdIdJ„ZdS)Or—a&Proxies a DBAPI connection and provides return-on-dereference
    support.
 
    This is an internal object used by the :class:`_pool.Pool` implementation
    to provide context management to a DBAPI connection delivered by
    that :class:`_pool.Pool`.   The public facing interface for this class
    is described by the :class:`.PoolProxiedConnection` class.  See that
    class for public API details.
 
    The name "fairy" is inspired by the fact that the
    :class:`._ConnectionFairy` object's lifespan is transitory, as it lasts
    only for the length of a specific DBAPI connection being checked out from
    the pool, and additionally that as a transparent proxy, it is mostly
    invisible.
 
    .. seealso::
 
        :class:`.PoolProxiedConnection`
 
        :class:`.ConnectionPoolEntry`
 
 
    )r6rŽÚ_echorÝÚ_counterr³r´rRr¶rr6rTrór‰)r¶r6rxrUcCs"||_d|_||_||_||_dS)Nr)rÝrôr6rŽró)r:r¶r6rxrUr*r*r+rpÍs
z_ConnectionFairy.__init__rÚrŽr¦rJcCs|jdkrdS|jjSr8rærKr*r*r+r§Üs
z"_ConnectionFairy.driver_connectionr¹zWThe _ConnectionFairy.connection attribute is deprecated; please use 'driver_connection'cCs|jSr8rºrKr*r*r+rDâsz_ConnectionFairy.connectionNzOptional[threading.local]rÛ)r¶Ú threadconnsrÉr7c Csl|s"t |¡}|dk    r"t |¡|_|jdk    s4tdƒ‚|jdk    sFtdƒ‚|jd7_|j    jsb|j
rl|jdkrp|Sd}|dkrJ|jj }d|j_ z‚|j
rø|sâ|j r°|j  d|j¡|j |j¡}|sø|j rØ|j  d|j¡t ¡‚n|j rø|j  d    |j¡|j     |j|j|¡|WStjk
rî}z¼|jrZ|j  d
|¡|j |¡|j||dd n|j  d |j|¡|j |¡z|j ¡|_WnLtk
rÔ}z,t ¡|jj|d d~W5QRX‚W5d}~XYnX|d8}W5d}~XYqttk
rF}    z:t ¡&|j}
|
dk    r(|
j|    d d~W5QRX‚W5d}    ~    XYqtXqt|j  d¡| ¡t d¡‚dS)Nz,can't 'checkout' a detached connection fairyz0can't 'checkout' an invalidated connection fairyr-rrFzPool pre-ping on connection %sz;Pool pre-ping on connection %s failed, will invalidate poolz)Connection %s is fresh, skipping pre-pingzoDisconnection detected on checkout, invalidating all pooled connections prior to current timestamp (reason: %r)©rzVDisconnection detected on checkout, invalidating individual connection %s (reason: %r)Tr¼z+Reconnection attempts exhausted on checkoutzThis connection is closed)r‰rÊrÅrÀÚcurrentrŽrÕr6rôrSrjr²rórr‚rWrCrZInvalidatePoolErrorZDisconnectionErrorZinvalidate_poolr¨r“r”rÂrƒrrÃrÄZInvalidRequestError) rÇr¶rõrÉÚattemptsZconnection_is_freshÚresultr‡rÈZbe_outerrPr*r*r+r˜ës¸
 ÿþÿþÿÿþ
þÿý
þÿü ü ÿ
þ
 
 
þ  z_ConnectionFairy._checkoutcCstj|j|dS)N)rÉ)r—r˜rÝrKr*r*r+Ú_checkout_existingjsz#_ConnectionFairy._checkout_existingFr#r5)r r7c    Cs"t|j|j|jd|j||ddS)N)r rÉ)r¿r6rŽrÝró)r:r r*r*r+rmsùz_ConnectionFairy._checkincCs | ¡dSr8rörKr*r*r+Ú_closexsz_ConnectionFairy._close)r¶r r!r"r7c    Cs¨|jjr&|j |j|jt|||d¡|s.dS|jtkrx|rT|jrv|j     d|j¡q¤|jrj|j     d|j¡|j
  |¡n,|jt kr¤|jr˜|j     d|j¡|j
  |¡dS)Nrz.Connection %s reset, transaction already resetz Connection %s rollback-on-returnzConnection %s commit-on-return)rSÚresetr6rŽrrkr.rórr‚rWr;r/r<)r:r¶r r!r"r*r*r+rÜ{s@ýý
 
þþ
þz_ConnectionFairy._resetzlog._IdentifiedLoggerTypecCs|jjSr8)rÝrrKr*r*r+Ú_logger¦sz_ConnectionFairy._loggercCs
|jdk    Sr8rºrKr*r*r+rªsz_ConnectionFairy.is_validcCs
|jdkSr8)rŽrKr*r*r+rá®sz_ConnectionFairy.is_detachedrcCs|jdkriS|jjSdSr8)rŽr¨rKr*r*r+r¨²s
z_ConnectionFairy.infor©cCs|jdkrdS|jjSdSr8rèrKr*r*r+rª¹s
z_ConnectionFairy.record_infor‹r«cCsD|jdkrt d¡dS|jr.|jj||d|s@d|_| ¡dS)Nz.Can't invalidate an already-closed connection.)r‡r¬)r6rrÍrŽr“rr­r*r*r+r“Às
 
z_ConnectionFairy.invalidaterrrécOs|jdk    st‚|jj||ŽSr8)r6rÕràrìr*r*r+ràÑsz_ConnectionFairy.cursorrŸrícCs t|j|ƒSr8rïrðr*r*r+rñÕsz_ConnectionFairy.__getattr__cCs\|jdk    rX|j}d|_d|_|j |j¡|j ¡|_d|_|jjjrX|jj |j|¡dSr8)    rŽr°r6rÝr›r¨ÚcopyrSrÞrQr*r*r+rÞØs
 
z_ConnectionFairy.detachcCs$|jd8_|jdkr | ¡dS)Nr-r©rôrrKr*r*r+r>és
z_ConnectionFairy.close)Útransaction_resetr7cCs(|jd8_|jdkr$|j|ddS)Nr-rr¾rÿ)r:rr*r*r+Ú_close_specialîs
z_ConnectionFairy._close_special)NN)F)NF)F)r$r%r&r'r(r)rpr¡r§rrØrDrÙr˜rúrrûrÜrýrrár®r¨ròrªr“ràrñrÞr>rr*r*r*r+r—¥sR
 
 þü~ +ÿr—)FN)?r'Ú
__future__rÚ collectionsrZ dataclassesÚenumrÚ    threadingr’rârrrrr    r
r r r rrÅrÒrrrrZ util.typingrrZengine.interfacesrrrrrrZ sql._typingrZ    dataclassrr,r^Úlistr.r/r0r3rHrIrNZ
IdentifiedZ EventTargetrRr¤rOr‰r¿rÆr)r4rãr—r*r*r*r+Ú<module>    s|                          
,ÿÿ#@|"&÷    þ
H;