zmc
2023-08-08 e792e9a60d958b93aef96050644f369feb25d61b
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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
U
¸ý°dgqã@sŽdZddlmZddlZddlZddlmZddlmZddlmZddlm    Z    ddlm
Z
dd    lm Z dd
lm Z dd lm Z dd lmZdd lmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlm Z ddlm!Z!ddlm"Z"ddlm#Z#ddlm$Z$dd lm%Z%dd!lm&Z&dd"lm'Z'dd#lm(Z(dd$lm)Z)dd%lm*Z*dd&lm+Z+dd'lm,Z,dd(lm-Z-dd)lm.Z.dd*lm/Z/dd+lm0Z0dd,lm1Z1dd-lm2Z2dd.lm3Z3dd/lm4Z4dd0lm5Z5dd1lm6Z6dd2lm7Z7dd3lm8Z8dd4lm9Z9dd5lm:Z:dd6lm;Z;dd7lm<Z<dd8lm=Z=dd9lm>Z>d:d;lm?Z?d:dlmZd:d<lm@Z@d:d=lmAZAd:d>l?mBZBd:d?l?mCZCd:d@lDmZEd:dAlDmFZFd:dBlDmGZGd:dClDmHZHd:dDlDmIZId:dElJmKZKd:dFlLmMZMd:dGlLmNZNd:dHlOmPZPd:dIlOmQZQd:dJlOmRZRer‚ddKlmSZSddLlmTZTddMlmUZUddNlmVZVddOlmWZWddPlmXZXddQlmYZYddRlmZZZddSlm[Z[ddTl\m]Z]ddUl^m_Z_ddVlAm`Z`ddWlambZbd:dXlcmdZdd:dYlemfZfd:dZlemgZgd:d[lemhZhd:d\lemiZid:d]ljmkZkd:d^llmmZmd:d_llmnZnd:d`lompZpd:dalqmrZredbƒZseee dce etfZuetƒZve@jwGddde„deeese=esejxejyeseHjzeHj{eEj|eFj}eAj~eCƒ ƒZdfdgdhdidjdkœdldm„Z€Gdndo„doeesƒZej‚dpdqGdrds„dseKƒƒZƒdjdtduœdvdw„Z„eA …dx¡Z†eA …dy¡Z‡eA …dz¡ZˆeA …d{¡Z‰eA …d|¡ZŠGd}d~„d~ƒZ‹e‹ZŒe‹ZGdd€„d€ƒZŽGdd‚„d‚eŽƒZGdƒd„„d„eƒZGd…d†„d†ƒZ‘erÜd€d‡dˆœd‰dŠ„Z’n
e “d‹¡Z’GdŒd„de‘eŽƒZ”dŽdfddd‘œd’d“„Z•eA …d”¡Z–e—e˜e6ƒe˜e/ƒgƒZ™Gd•d–„d–e ƒZšešd—d—d—ƒZ›e7fd˜dfd™d–dšœd›dœ„Zœe7fdcdfd™d–dœdždŸ„ZdÑdgd¡dfddd¢œd£d¤„Zždd¥œdgdfd¦dhd§djd¨d©œdªd«„ZŸdÒdgdfdd¬dd­d§djdŽd®œ    d¯d°„Z dd¥œd±dfd¦d²d§d¨d³œd´dµ„Z¡d±dfdd¶œd·d¸„Z¢d˜dfd¹dºœd»d¼„Z£dcd½dfd¹d¾œd¿dÀ„Z¤dÁd„Z¥dÓd˜dfdjdÃddĜdÅdƄZ¦d˜dfdjdǜdÈdɄZ§d˜dfddǜdÊd˄Z¨d˜dfddǜdÌd̈́Z©d˜ddΜdÏdЄZªdS)ÔzÍDefines instrumentation for class attributes and their interaction
with instances.
 
This module is usually not directly visible to user applications, but
defines a large part of the ORM's interactivity.
 
 
é)Ú annotationsN)ÚAny)ÚCallable)Úcast)ÚClassVar)ÚDict)ÚList)Ú
NamedTuple)ÚOptional)Úoverload)ÚSequence)ÚTuple)ÚType)Ú TYPE_CHECKING)ÚTypeVar)ÚUnioné)Ú collections)Úexc)Ú
interfaces)Úinsp_is_aliased_class)Ú_DeclarativeMapped)Ú
ATTR_EMPTY)Ú ATTR_WAS_SET)Ú CALLABLES_OK)ÚDEFERRED_HISTORY_LOAD)ÚINIT_OK)Ú instance_dict©Úinstance_state)Ú instance_str)ÚLOAD_AGAINST_COMMITTED)ÚLoaderCallableStatus)Úmanager_of_class)ÚMapped)Ú    NEVER_SET)Ú NO_AUTOFLUSH)Ú    NO_CHANGE)ÚNO_KEY)ÚNO_RAISE)ÚNO_VALUE)ÚNON_PERSISTENT_OK)Úopt_manager_of_class)ÚPASSIVE_CLASS_MISMATCH)ÚPASSIVE_NO_FETCH)ÚPASSIVE_NO_FETCH_RELATED)ÚPASSIVE_NO_INITIALIZE)ÚPASSIVE_NO_RESULT)Ú PASSIVE_OFF)ÚPASSIVE_ONLY_PERSISTENT)ÚPASSIVE_RETURN_NO_VALUE)Ú PassiveFlag)ÚRELATED_OBJECT_OK)ÚSQL_OK)ÚSQLORMExpression)Ú    state_stré)Úevent)Ú
inspection)Úutil)Ú
dispatcher)Ú EventTarget)Úbase)Ú    cache_key)Ú    coercions)Úroles)Úvisitors)Ú HasCacheKey)Ú_TraverseInternalsType)ÚInternalTraversal)ÚLiteral)ÚSelf)Ú    TypeGuard)Ú _EntityType)Ú_ExternalEntityType)Ú _InstanceDict)Ú_InternalEntityType)Ú_LoaderCallable)Ú_O)Ú_AdaptedCollectionProtocol)ÚCollectionAdapter)ÚMapperProperty)ÚRelationshipProperty)Ú InstanceState)Ú AliasedInsp)ÚWriteOnlyAttributeImpl)Ú    _Dispatch)Ú_ColumnExpressionArgument)Ú_DMLColumnArgument)Ú    _InfoType)Ú_PropagateAttrsType)Ú_AnnotationDict)Ú ColumnElement)ÚLabel)Ú OperatorType)Ú
FromClauseÚ_TúInstanceState[Any]c    @s.eZdZUdZdZdZded<ded<ded    <d
ed <d ed <ded<ded<ded<ded<dZdoddddddddœdd„Zd    e    j
j fde    j
j fde    j
j fde    j jfgZd d!œd"d#„Zed$d!œd%d&„ƒZefd d'd(d)œd*d+„Zed,d!œd-d.„ƒZd
ed/<d0ed1<d0d!œd2d3„Zd4d!œd5d6„Zed
d!œd7d8„ƒZed9d!œd:d;„ƒZd0d!œd<d=„Zed>d!œd?d@„ƒZd dAdBœdCdD„ZdEdFdGœdHdI„ZdJdKdLœdMdN„ZdOdPdQœdRdS„Zd dKdTœdUdV„Z ddWdXœdYdZ„Z!d[d d d\d]œd^d_„Z"d[d d d\d]œd`da„Z#dpdcd$d$ddœdedf„Z$dd dgœdhdi„Z%dd!œdjdk„Z&dld!œdmdn„Z'dS)qÚQueryableAttributea«Base class for :term:`descriptor` objects that intercept
    attribute events on behalf of a :class:`.MapperProperty`
    object.  The actual :class:`.MapperProperty` is accessible
    via the :attr:`.QueryableAttribute.property`
    attribute.
 
 
    .. seealso::
 
        :class:`.InstrumentedAttribute`
 
        :class:`.MapperProperty`
 
        :attr:`_orm.Mapper.all_orm_descriptors`
 
        :attr:`_orm.Mapper.attrs`
    ) Úclass_ÚkeyÚimplÚ
comparatorÚpropertyÚparentÚ
expressionÚ_of_typeÚ_extra_criteriaZ_slots_dispatchZ_propagate_attrsÚ_docTz"dispatcher[QueryableAttribute[_T]]Údispatchú_ExternalEntityType[Any]reÚstrrfú_InternalEntityType[Any]Ú parententityÚ AttributeImplrgúinterfaces.PropComparator[_T]rhz"Optional[_InternalEntityType[Any]]rlzTuple[ColumnElement[bool], ...]rmú Optional[str]rnZorm_instrumented_attributeN©ú_ExternalEntityType[_O]ú_InternalEntityType[_O]zOptional[AttributeImpl])rerfrsrhrgÚof_typeÚextra_criteriac
CsŒ||_||_||_|_||_|dk    s*t‚||_||_||_d|_    t
|ƒ}|rˆ|j D]2}    ||    krT|j   |    |j ¡|    |j jrTd|j _qTdS©NT)rerfÚ _parententityrjrgÚAssertionErrorrhrlrmrnr,Z_basesroÚ_updateÚ_active_history)
Úselfrerfrsrhrgrzr{Úmanagerr@rwrwúPd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/orm/attributes.pyÚ__init__Âs 
 
 zQueryableAttribute.__init__r}r©ÚreturncCst|j|jjj|j|jjffS©N)Ú_queryable_attribute_unreducerfr}ZmapperreÚentity©rrwrwrƒÚ
__reduce__ïsüþzQueryableAttribute.__reduce__ÚboolcCs|jjSr‡)rgÚ uses_objectsrŠrwrwrƒÚ_impl_uses_objectsüsz%QueryableAttribute._impl_uses_objectsr5ÚHistory)ÚinstanceÚpassiver†cCs|j t|ƒt|ƒ|¡Sr‡)rgÚ get_historyrr)rrr‘rwrwrƒr’s
ÿzQueryableAttribute.get_historyr[cCs|jjS)a¬Return the 'info' dictionary for the underlying SQL element.
 
        The behavior here is as follows:
 
        * If the attribute is a column-mapped property, i.e.
          :class:`.ColumnProperty`, which is mapped directly
          to a schema-level :class:`_schema.Column` object, this attribute
          will return the :attr:`.SchemaItem.info` dictionary associated
          with the core-level :class:`_schema.Column` object.
 
        * If the attribute is a :class:`.ColumnProperty` but is mapped to
          any other kind of SQL expression other than a
          :class:`_schema.Column`,
          the attribute will refer to the :attr:`.MapperProperty.info`
          dictionary associated directly with the :class:`.ColumnProperty`,
          assuming the SQL expression itself does not have its own ``.info``
          attribute (which should be the case, unless a user-defined SQL
          construct has defined one).
 
        * If the attribute refers to any other kind of
          :class:`.MapperProperty`, including :class:`.Relationship`,
          the attribute will refer to the :attr:`.MapperProperty.info`
          dictionary associated with that :class:`.MapperProperty`.
 
        * To access the :attr:`.MapperProperty.info` dictionary of the
          :class:`.MapperProperty` unconditionally, including for a
          :class:`.ColumnProperty` that's associated directly with a
          :class:`_schema.Column`, the attribute can be referred to using
          :attr:`.QueryableAttribute.property` attribute, as
          ``MyClass.someattribute.property.info``.
 
        .. seealso::
 
            :attr:`.SchemaItem.info`
 
            :attr:`.MapperProperty.info`
 
        )rhÚinforŠrwrwrƒr“s(zQueryableAttribute.inforjzColumnElement[_T]rkc
Cs¢|j}t|tƒst‚|jtkr(d|i}n|j|j|dœ}|j ¡}zt    rVt|t
ƒsVt‚|j }Wn6t k
r”}zt  d||f¡|‚W5d}~XYn
X||ƒSdS)NÚentity_namespace)Ú    proxy_keyZ proxy_ownerr”z}When interpreting attribute "%s" as a SQL expression, expected __clause_element__() to return a ClauseElement object, got: %r)Ú_entity_namespaceÚ
isinstancerEr~rfÚ_UNKNOWN_ATTR_KEYr}rhÚ__clause_element__rr^Z    _annotateÚAttributeErrorrZInvalidRequestError)rr”rZceÚannoZaerwrwrƒÚ_memoized_attr_expressionDs,
 
ý
 
þÿüz,QueryableAttribute._memoized_attr_expressionr\cCst d|jdœ¡S)NZorm)Zcompile_state_pluginZplugin_subject)r=Z immutabledictZ _parentmapperrŠrwrwrƒÚ_memoized_attr__propagate_attrsfs
þÿz2QueryableAttribute._memoized_attr__propagate_attrscCs|jSr‡)r}rŠrwrwrƒr–qsz$QueryableAttribute._entity_namespacer]cCs
| ¡jSr‡)r™Ú _annotationsrŠrwrwrƒržuszQueryableAttribute._annotationscCs|jSr‡)rkrŠrwrwrƒr™ysz%QueryableAttribute.__clause_element__zList[FromClause]cCs|jjSr‡)rkÚ _from_objectsrŠrwrwrƒrŸ|sz QueryableAttribute._from_objectsz(Sequence[Tuple[_DMLColumnArgument, Any]]©Úvaluer†cCs |j |¡S)z'Return setter tuples for a bulk UPDATE.)rhÚ_bulk_update_tuples©rr¡rwrwrƒr¢€sz&QueryableAttribute._bulk_update_tupleszAliasedInsp[Any]rI)Úadapt_to_entityr†cCs,|jr
t‚|j|j|j|j|j |¡|dS)N)rgrhrs)rlr~Ú    __class__r‰rfrgrhr¤©rr¤rwrwrƒr¤‡s
 
ûz"QueryableAttribute.adapt_to_entityz_EntityType[Any]zQueryableAttribute[_T])r‰r†c    Cs.t|j|j|j|j|j |¡t |¡|j    dS©N©rgrhrzr{)
rdrerfr}rgrhrzr<Úinspectrm)rr‰rwrwrƒrz‘s
ùzQueryableAttribute.of_typez_ColumnExpressionArgument[bool]zQueryableAttribute[bool])Úclausesr†c    Gs\trt|jtjƒst‚tdd„t |¡Dƒƒ}t    |j
|j |j |j |jj|Ž|j|j|dS)Ncss|]}t tj|¡VqdSr‡)rBÚexpectrCZWhereHavingRole)Ú.0ZclauserwrwrƒÚ    <genexpr>¢sÿz*QueryableAttribute.and_.<locals>.<genexpr>r¨)rr—rhrTZ
Comparatorr~Útupler=Zcoerce_generator_argrdrerfr}rgÚand_rlrm)rrªÚexprsrwrwrƒr¯œsþ
ùzQueryableAttribute.and_)Úkwr†c    Ks$t|j|j|j|j|j|j|jdSr§)rdrerfr}rgrhrlrm©rr±rwrwrƒÚ_clone±sùzQueryableAttribute._clonez    Label[_T])Únamer†cCs| ¡ |¡Sr‡)r™Úlabel)rr´rwrwrƒrµ¼szQueryableAttribute.labelr`zColumnElement[Any])ÚopÚotherÚkwargsr†cOs||jf|ž|ŽSr‡©rh©rr¶r·r¸rwrwrƒÚoperate¿szQueryableAttribute.operatecKs|||jf|ŽSr‡r¹rºrwrwrƒÚreverse_operateÄsz"QueryableAttribute.reverse_operateFrc©ÚstateÚ
optimisticr†cCs|jj||ddk    S)N)r¿F©rgÚ    hasparent)rr¾r¿rwrwrƒrÁÉszQueryableAttribute.hasparent)rfr†c
Cs€ztj ||¡WStk
r$YnXzt|j|ƒWStk
rz}z(tdt|ƒjt|jƒj||fƒ|‚W5d}~XYnXdS)NúFNeither %r object nor %r object associated with %s has an attribute %r©r=Ú MemoizedSlotsÚ __getattr__ršÚgetattrrhÚtypeÚ__name__)rrfÚerrrwrwrƒrÅÎs$
üþÿ    ÷zQueryableAttribute.__getattr__cCs|jj›d|j›S©NÚ.©rerÈrfrŠrwrwrƒÚ__str__âszQueryableAttribute.__str__zOptional[MapperProperty[Any]]cCs|jjSr‡©rhrirŠrwrwrƒÚ_memoized_attr_propertyåsz*QueryableAttribute._memoized_attr_property)NNrw)F)(rÈÚ
__module__Ú __qualname__Ú__doc__Ú    __slots__Z is_attributeÚ__annotations__Z__visit_name__r„rDÚExtendedInternalTraversalÚ    dp_stringÚdp_multirGZdp_clauseelement_listÚ_cache_key_traversalr‹rirŽr2r’r“rœrr–ržr™rŸr¢r¤rzr¯r³rµr»r¼rÁrÅrÍrÏrwrwrwrƒrdƒsj
ø'
 
 
 
ü ÿ)
    " 
  ÿrdrqzType[_O]ryrpr)rfÚ mapped_classrsr‰r†cCs$t|ƒr| |||¡St||ƒSdSr‡)rZ_get_from_serializedrÆ)rfrÙrsr‰rwrwrƒrˆésrˆcs¾eZdZdZdZdZejddœdd„ƒZejddd    œd
d„ƒZej    ddœ‡fd d„ ƒZd d ddœdd„Z
d ddœdd„Z e dd ddœdd„ƒZ e d d ddœdd„ƒZ dd ddœdd„Z ‡ZS)ÚInstrumentedAttributez¤Class bound instrumented attribute which adds basic
    :term:`descriptor` methods.
 
    See :class:`.QueryableAttribute` for a description of most features.
 
 
    rwTrvr…cCs|jSr‡©rnrŠrwrwrƒrÒ    szInstrumentedAttribute.__doc__ÚNoner cCs
||_dSr‡rÛr£rwrwrƒrÒ scstƒjSr‡)ÚsuperrÒ)Úcls©r¥rwrƒrÒsÚobjectr)rr¡r†cCs|j t|ƒt|ƒ|d¡dSr‡)rgÚsetrr)rrr¡rwrwrƒÚ__set__s ÿzInstrumentedAttribute.__set__©rr†cCs|j t|ƒt|ƒ¡dSr‡)rgÚdeleterr)rrrwrwrƒÚ
__delete__sz InstrumentedAttribute.__delete__úInstrumentedAttribute[_T])rÚownerr†cCsdSr‡rw©rrrçrwrwrƒÚ__get__szInstrumentedAttribute.__get__rbcCsdSr‡rwrèrwrwrƒré!súOptional[object]z$Union[InstrumentedAttribute[_T], _T]c
Cs~|dkr |St|ƒ}|jjr0|j|kr0||jSz t|ƒ}Wn.tk
rj}zt |¡|‚W5d}~XYnX|j ||¡SdSr‡)    rrgÚsupports_populationrfrršÚorm_excZUnmappedInstanceErrorÚget)rrrçÚdict_r¾rÉrwrwrƒré%s
 )rÈrÐrÑrÒrÓZ inherit_cacher=Zrw_hybridpropertyÚsetterZ
classlevelrârår réÚ __classcell__rwrwrßrƒrÚ÷s rÚT)Úfrozenc@sReZdZUdejfgZded<dZded<dZded<dZ    ded    <e
d
d „ƒZ d S) ÚAdHocHasEntityNamespacer–z ClassVar[_TraverseInternalsType]Ú_traverse_internals)r–rrFzClassVar[bool]Ú    is_mapperÚis_aliased_classcCs|jjSr‡)r–r”rŠrwrwrƒr”Bsz(AdHocHasEntityNamespace.entity_namespaceN) rÈrÐrÑrGZdp_has_cache_keyrórÔrÓrôrõrir”rwrwrwrƒrò6s
ÿ   ròz&Callable[..., QueryableAttribute[Any]])Ú
descriptorr†csBG‡fdd„dttƒ}tˆƒjd|_tj|tˆƒdˆd|S)z´Create an QueryableAttribute / user descriptor hybrid.
 
    Returns a new QueryableAttribute type that delegates descriptor
    behavior and getattr() to the given descriptor.
    cs¶eZdZdZdZd!dd„Zedd„ƒZedd    „ƒZd
Z    d e
j j fd e
j j fgZed d„ƒZedd„ƒZedd„ƒZejdd„ƒZdd„Zdd„Zdd„Zddœdd„Z‡fdd „ZdS)"z'create_proxied_attribute.<locals>.ProxyzžPresents the :class:`.QueryableAttribute` interface as a
        proxy on top of a Python descriptor / :class:`.PropComparator`
        combination.
 
        rwNcSs4||_||_||_||_||_||_||_|_dSr‡)rerfröÚoriginal_propertyÚ _comparatorÚ_adapt_to_entityrnrÒ)rrerfrörhr¤Údocr÷rwrwrƒr„`s
z0create_proxied_attribute.<locals>.Proxy.__init__cSstj|jddS©NF)Zraiseerr©r<r©rerŠrwrwrƒr}rsz5create_proxied_attribute.<locals>.Proxy._parententitycSstj|jddSrûrürŠrwrwrƒrjvsz.create_proxied_attribute.<locals>.Proxy.parentTrfr}cSs|jdk    ot|j|jƒjjSr‡)r÷rÆrerfrgrrŠrwrwrƒrށs
þz:create_proxied_attribute.<locals>.Proxy._impl_uses_objectscSs"t|jdƒr|jjSt|jƒSdS)Nr})Úhasattrrør}ròrŠrwrwrƒr–ˆs z9create_proxied_attribute.<locals>.Proxy._entity_namespacecSs|jjSr‡rÎrŠrwrwrƒri‘sz0create_proxied_attribute.<locals>.Proxy.propertycSs0t|jƒr| ¡|_|jr*|j |j¡|_|jSr‡)Úcallablerørùr¤rŠrwrwrƒrh•s
 
ÿz2create_proxied_attribute.<locals>.Proxy.comparatorcSs| |j|j|j|j|¡Sr‡)r¥r‰rfrörør¦rwrwrƒr¤Ÿsûz7create_proxied_attribute.<locals>.Proxy.adapt_to_entityc[s"|j|j|j|j|j|j|jdS)N)r¤r÷)r¥rerfrörørùr÷r²rwrwrƒr³¨súz.create_proxied_attribute.<locals>.Proxy._clonecSs,|j ||¡}||jkr$|dkr$|S|SdSr‡)röré)rrrçÚretvalrwrwrƒré²sz/create_proxied_attribute.<locals>.Proxy.__get__rqr…cSs|jj›d|j›SrÊrÌrŠrwrwrƒrͼsz/create_proxied_attribute.<locals>.Proxy.__str__c sztj ||¡WStk
r$YnXz tˆ|ƒWStk
r }zº|dkrXtdƒ|‚z
|j}Wn<tk
rž}ztdtˆƒj||fƒ|‚W5d}~XYn^Xzt||ƒWWY¢LStk
rú}z&tdtˆƒjt|ƒj||fƒ|‚W5d}~XYnXW5d}~XYnXdS)zNDelegate __getattr__ to the original descriptor and/or
            comparator.rhz[Neither %r object nor unconfigured comparator object associated with %s has an attribute %rNrÂrÃ)rÚ    attributerÉrhZerr2Zerr3©rörwrƒrÅ¿sB 
 
þÿüüþÿ    ÷z3create_proxied_attribute.<locals>.Proxy.__getattr__)NNN)rÈrÐrÑrÒrmr„rir}rjZ_is_internal_proxyrDrÕrÖr×rØrŽr–r=Zmemoized_propertyrhr¤r³rérÍrÅrwrrwrƒÚProxySs6 ø
 
 
 
 
þ
 
 
 
        
 
rrö)r´Z from_instance)rdrrÇrÈr=Zmonkeypatch_proxied_specials)rörrwrrƒÚcreate_proxied_attributeGs ÿrZREMOVEÚAPPENDZREPLACEZ BULK_REPLACEZMODIFIEDc@s8eZdZdZdZdd„Zdd„Zedd„ƒZd    d
„Z    d S) ÚAttributeEventTokenaïA token propagated throughout the course of a chain of attribute
    events.
 
    Serves as an indicator of the source of the event and also provides
    a means of controlling propagation across a chain of attribute
    operations.
 
    The :class:`.Event` object is sent as the ``initiator`` argument
    when dealing with events such as :meth:`.AttributeEvents.append`,
    :meth:`.AttributeEvents.set`,
    and :meth:`.AttributeEvents.remove`.
 
    The :class:`.Event` object is currently interpreted by the backref
    event handlers, and is used to control the propagation of operations
    across two mutually-dependent attributes.
 
    .. versionchanged:: 2.0  Changed the name from ``AttributeEvent``
       to ``AttributeEventToken``.
 
    :attribute impl: The :class:`.AttributeImpl` which is the current event
     initiator.
 
    :attribute op: The symbol :attr:`.OP_APPEND`, :attr:`.OP_REMOVE`,
     :attr:`.OP_REPLACE`, or :attr:`.OP_BULK_REPLACE`, indicating the
     source operation.
 
    ©rgr¶Ú parent_tokencCs||_||_|jj|_dSr‡r)rZattribute_implr¶rwrwrƒr„szAttributeEventToken.__init__cCs"t|tƒo |j|jko |j|jkSr‡)r—rrgr¶)rr·rwrwrƒÚ__eq__s
 
 
ÿ
ýzAttributeEventToken.__eq__cCs|jjSr‡)rgrfrŠrwrwrƒrf#szAttributeEventToken.keycCs |j |¡Sr‡rÀ)rr¾rwrwrƒrÁ'szAttributeEventToken.hasparentN)
rÈrÐrÑrÒrÓr„rrirfrÁrwrwrwrƒrøs
rc@sêeZdZUdZded<ded<ded<ded<ded<dZd    ed
<d    ed <d    ed <dKdddddddddddddœ dd„ZdZddœdd„Zdd„Z    d d!„Z
e e    e
ƒZ dLd"ddd#œd$d%„Z d"d"dd&d'œd(d)„Zefd"d*d+d,d-œd.d/„Zefd"d*d+d0d-œd1d2„Zd"d*dd3œd4d5„Zefd"d*d+dd-œd6d7„Zd"dd+dd8œd9d:„Zefd"d*ddd+d&d;œd<d=„Zefd"d*ddd+d&d;œd>d?„Zefd"d*ddd+d&d;œd@dA„Zd ed dfd"d*ddd+ddd&dBœdCdD„Zd"d*d&d3œdEdF„Zefd"d*d+dd-œdGdH„ZdIdJ„Zd S)Mrtz4internal implementation for instrumented attributes.rŒÚ
collectionÚdefault_accepts_scalar_loaderrrëÚdynamicFrÚ_replace_tokenÚ _remove_tokenÚ _append_tokenNTrxrqrOú"_Dispatch[QueryableAttribute[Any]]zOptional[Callable[..., bool]]úOptional[AttributeEventToken]zOptional[bool]r) rerfÚ    callable_roÚ trackparentÚcompare_functionÚactive_historyrÚload_on_unexpireÚsend_modified_eventsÚaccepts_scalar_loaderr¸c Ks’||_||_||_||_||_|p$||_|
|_|dkr@tj|_    n||_    | dk    rV| |_
n|j |_
|   dd¡} | |_ |r|d|j_|    |_t|tƒ|_dS)aºConstruct an AttributeImpl.
 
        :param \class_: associated class
 
        :param key: string name of the attribute
 
        :param \callable_:
          optional function which generates a callable based on a parent
          instance, which produces the "default" values for a scalar or
          collection attribute when it's first accessed, if not present
          already.
 
        :param trackparent:
          if True, attempt to track if an instance has a parent attached
          to it via this attribute.
 
        :param compare_function:
          a function that compares two values which are normally
          assignable to this attribute.
 
        :param active_history:
          indicates that get_history() should always return the "old" value,
          even if it means executing a lazy callable upon attribute change.
 
        :param parent_token:
          Usually references the MapperProperty, used as a key for
          the hasparent() function to identify an "owning" attribute.
          Allows multiple AttributeImpls to all match a single
          owner attribute.
 
        :param load_on_unexpire:
          if False, don't include this attribute in a load-on-expired
          operation, i.e. the "expired_attribute_loader" process.
          The attribute can still be in the "expired" list and be
          considered to be "expired".   Previously, this flag was called
          "expire_missing" and is only used by a deferred column
          attribute.
 
        :param send_modified_events:
          if False, the InstanceState._modified_event method will have no
          effect; this means the attribute will never show up as changed in a
          history entry.
 
        NÚ_deferred_historyFT)rerfrrorrrÚoperatorÚeqÚis_equalrr
Úpoprr€rrÚ OP_MODIFIEDÚ_modified_token)rrerfrrorrrrrrrr¸rrwrwrƒr„>s&;
 
 zAttributeImpl.__init__) rerfrrorrrrrrrrr…cCs|jj›d|j›SrÊrÌrŠrwrwrƒrÍ¢szAttributeImpl.__str__cCs|jjS)z(Backwards compat for impl.active_history©ror€rŠrwrwrƒÚ_get_active_history¥sz!AttributeImpl._get_active_historycCs ||j_dSr‡rr£rwrwrƒÚ_set_active_historyªsz!AttributeImpl._set_active_historyrcr½cCs*d}|jst|ƒ‚|j t|jƒ|¡dk    S)a4Return the boolean value of a `hasparent` flag attached to
        the given state.
 
        The `optimistic` flag determines what the default return value
        should be if no `hasparent` flag can be located.
 
        As this function is used to determine if an instance is an
        *orphan*, instances that were loaded from storage should be
        assumed to not be orphans, until a True/False value for this
        flag is set.
 
        An instance attribute that is loaded by a callable function
        will also not have a `hasparent` flag.
 
        ú6This AttributeImpl is not configured to track parents.F)rr~ÚparentsríÚidr)rr¾r¿ÚmsgrwrwrƒrÁ¯sÿzAttributeImpl.hasparentrÜ)r¾Ú parent_stater¡r†cCsd}|jst|ƒ‚t|jƒ}|r,||j|<n`||jkr‚|j|}|dk    r‚|j|jkr‚| ¡dkr~t dt    |ƒt    |ƒ|jf¡‚dSd|j|<dS)zÁSet a boolean flag on the given item corresponding to
        whether or not it is attached to a parent object via the
        attribute represented by this ``InstrumentedAttribute``.
 
        r"FNzRemoving state %s from parent state %s along attribute '%s', but the parent record has gone stale, can't be sure this is the most recent parent.)
rr~r$rr#rfÚobjrìZStaleDataErrorr9)rr¾r&r¡r%Zid_Z last_parentrwrwrƒÚ sethasparentÈs, 
 
 
ÿ
þ ýûÿ zAttributeImpl.sethasparentrMr5r©r¾rîr‘r†cCs
tƒ‚dSr‡©ÚNotImplementedError©rr¾rîr‘rwrwrƒr’ôszAttributeImpl.get_historyÚ_AllPendingTypecCs
tƒ‚dS)a¦Return a list of tuples of (state, obj)
        for all objects in this attribute's current state
        + history.
 
        Only applies to object-based attributes.
 
        This is an inlining of existing functionality
        which roughly corresponds to:
 
            get_state_history(
                        state,
                        key,
                        passive=PASSIVE_NO_INITIALIZE).sum()
 
        Nr*r,rwrwrƒÚget_all_pendingüszAttributeImpl.get_all_pending©r¾rîr†cCs@|j|kstdƒ‚d}|jjD]}||||ƒ}|tk    r|}q|S)z=Produce an empty value for an uninitialized scalar attribute.úO_default_value should only be invoked for an uninitialized or expired attributeN)rfr~roZ init_scalarr)rr¾rîr¡ÚfnÚretrwrwrƒÚ_default_values ÿ  zAttributeImpl._default_valuec
CsØ|j|kr||jS|j}||jks2|j|tkr¼|t@s>tS| |||¡}|tks\|tkr`|S|tkr¦z
||WStk
r¢}ztd|ƒ|‚W5d}~XYq¼Xn|tk    r¼|     |||¡S|t
@sÈtS|  ||¡SdS)züRetrieve a value from the given object.
        If a callable is assembled on this object's attribute, and
        passive is False, the callable will be executed and the
        resulting value will be set as the new value for this attribute.
        z=Deferred loader for attribute %r failed to populate correctlyN) rfÚcommitted_stater*rr1Ú_fire_loader_callablesrÚKeyErrorrÚset_committed_valuerr3)rr¾rîr‘rfr¡rÉrwrwrƒrí%s8
 
ÿ þ
þÿüzAttributeImpl.get©r¾rfr‘r†cCsZ|jr"|jr"||jkr"| ||¡S||jkr@|j|}|||ƒS|jrR| ||¡StSdSr‡)rrÚexpired_attributesZ _load_expiredZ    callablesrr)rr¾rfr‘rrwrwrƒr5Rsÿþý 
 
 
 z$AttributeImpl._fire_loader_callables©r¾rîr¡Ú    initiatorr‘r†cCs|j|||||ddS©N©r‘©rá©rr¾rîr¡r;r‘rwrwrƒÚappendcszAttributeImpl.appendcCs|j||d|||ddS)N)r‘Ú    check_oldr>r?rwrwrƒÚremovemsÿzAttributeImpl.removec    Cs|j||d|||dddS)NT)r‘rArr>r?rwrwrƒrysùzAttributeImpl.pop©r¾rîr¡r;r‘rArr†cCs
tƒ‚dSr‡r*)rr¾rîr¡r;r‘rArrwrwrƒrá‹s
zAttributeImpl.setcCs
tƒ‚dSr‡r*)rr¾rîrwrwrƒrä—szAttributeImpl.deletecCs>|j|jkr*|j|j}|tkr$dS|Sn|j|||dSdS)z,return the unchanged value of this attributeNr=)rfr4r*rí)rr¾rîr‘r¡rwrwrƒÚget_committed_valuešs   z!AttributeImpl.get_committed_valuecCs|||j<| ||jg¡|S)z=set an attribute value on the given instance and 'commit' it.)rfÚ_commit)rr¾rîr¡rwrwrƒr7«s
z!AttributeImpl.set_committed_value)FNFNTTN)F)rÈrÐrÑrÒrÔÚ_is_has_collection_adapterr„rÓrÍr r!rirrÁr(r2r’r0r.r3rír5r@rBrrárärDr7rwrwrwrƒrt/sb
ô&U
ÿ0ü üü-úúúø ürtc
s¶eZdZdZdZdZdZdZdZdZ    ‡fdd„Z
ddd    d
œd d „Z e fdd dddœdd„Z de ddfdd dddddd    dœdd„Zdddddddœdd„Zddddd    dœd d!„Z‡ZS)"ÚScalarAttributeImplz8represents a scalar value-holding InstrumentedAttribute.TF)r rr cs0tƒj||Žt|tƒ|_|_t|tƒ|_dSr‡)rÝr„rÚ
OP_REPLACEr rÚ    OP_REMOVEr )rÚargr±rßrwrƒr„¾s ÿ zScalarAttributeImpl.__init__rcrMrÜr/cCsŽ|jjr| ||t¡}n| |jt¡}|jjr@| ||||j¡|     |||¡| 
|jt¡}|tkrŠ|tkrŠ|j sŠ|j|j krŠt d|ƒ‚dS)Nú%s object does not have a value)ror€rír4rfr*rBÚfire_remove_eventr Ú_modified_eventrZexpiredr9rš©rr¾rîÚoldÚexistingrwrwrƒräÅs ÿþý
üzScalarAttributeImpl.deletezDict[str, Any]r5rr)cCsv|j|krt ||||j¡S|j|jkr8t ||t¡S|t@rH|tN}|j|||d}|tkrdtSt |||¡SdSr<)    rfrÚfrom_scalar_attributer4r*rrír1Ú HISTORY_BLANK©rr¾rîr‘Úcurrentrwrwrƒr’Øs
 zScalarAttributeImpl.get_historyNrrrêrŒrCc    Cs\|jjr| ||t¡}n| |jt¡}|jjr@| |||||¡}| |||¡|||j<dSr‡)    ror€rír4rfr*ráÚfire_replace_eventrM©    rr¾rîr¡r;r‘rArrOrwrwrƒráës
ÿzScalarAttributeImpl.setrb©r¾rîr¡Úpreviousr;r†cCs&|jjD]}|||||p|jƒ}q|Sr‡)rorár ©rr¾rîr¡rXr;r1rwrwrƒrUs ÿz&ScalarAttributeImpl.fire_replace_event©r¾rîr¡r;r†cCs$|jjD]}||||p|jƒqdSr‡)rorBr ©rr¾rîr¡r;r1rwrwrƒrLs z%ScalarAttributeImpl.fire_remove_event)rÈrÐrÑrÒr
rrër    r rÓr„rär2r’rárUrLrðrwrwrßrƒrG³s$ üørGc
@sºeZdZdZdZdZdZdZdZddddœd    d
„Z    e
fddd d d œdd„Z e fddd dd œdd„Z de
ddfddddd ddddœdd„Zddddddœdd„Zdddddddœdd „ZdS)!ÚScalarObjectAttributeImplz•represents a scalar-holding InstrumentedAttribute,
    where the target object is also instrumented.
 
    Adds events to delete/set operations.
 
    FTrwrcrMrÜr/cCsˆ|jjr"|j||ttBtBd}n|j||ttAtBtBd}|     ||||j
¡|  |j t ¡}|t kr„|tk    r„|j dkr„td|ƒ‚dS)Nr=rK)ror€rír3r&r!r.rr)rLr rrfr*r1ršrNrwrwrƒrä)s8ÿþýÿþýÿþýz ScalarObjectAttributeImpl.deleter5rr)cCs¬|j|kr||j}n,|t@r&|tN}|j|||d}|tkrBtS|jsVt |||¡S|j |jt    ¡}|tkr–|t
t Bt Bt BtBB}| ||j|¡}tj||||dSdS)Nr=)Úoriginal)rfrrír1rRrrÚfrom_object_attributer4Ú _NO_HISTORYr3r&r!r)rr5)rr¾rîr‘rTr]Zloader_passiverwrwrƒr’IsB
 ÿþýüÿÿÿz%ScalarObjectAttributeImpl.get_historyr-cCs°|j|kr||j}n|t@r0|j|||d}ngS|dk    r\|tk    r\|tk    r\t|ƒ|fg}ndg}|j|jkr¬|j|j}|dk    r¬|tk    r¬|tk    r¬||k    r¬| t|ƒ|f¡|S)Nr=)NN)rfrrír1r*rr4r@)rr¾rîr‘rTr2r]rwrwrƒr.ls2
 ÿþý  ÿþýüz)ScalarObjectAttributeImpl.get_all_pendingNrrrŒrCc    Csš|jjr"|j||ttBtBd}n|j||ttAtBtBd}|dk    rz|t    k    rz||k    rz|r^dSt
dt |ƒt |ƒ|j fƒ‚| |||||¡}|||j <dS)z'Set a value on the given InstanceState.r=Nz2Object %s not associated with %s on attribute '%s')ror€rír3r&r!r.rr)r1Ú
ValueErrorr r9rfrUrVrwrwrƒrá‘sD ÿþýÿþý    ÿþýÿÿzScalarObjectAttributeImpl.setrZcCsX|jr&|dttfkr&| t|ƒ|d¡|jjD]}||||p@|jƒq.| |||¡dS)NF)    rr1r*r(rrorBr rMr[rwrwrƒrL¾sý z+ScalarObjectAttributeImpl.fire_remove_eventrbrWcCs‚|jr.||k    r.|dttfkr.| t|ƒ|d¡|jjD]}|||||pJ|jƒ}q6| |||¡|jr~|dk    r~| t|ƒ|d¡|S)NFT)    rr1r*r(rrorár rMrYrwrwrƒrUÑs&
ý ÿz,ScalarObjectAttributeImpl.fire_replace_event)rÈrÐrÑrÒr
rrër    rÓrär2r’r0r.rárLrUrwrwrwrƒr\s$$ü'ü*ø-r\c @sÒeZdZUdZded<dZdddddd    œd
d „Zed dd ddddœdd„ƒZed!dd ddddœdd„ƒZed"dd ddddœdd„ƒZde    j
fdd ddddœdd„Zde    j
dddfdd ddddddddœ    dd„Z dS)#ÚHasCollectionAdapterrwrŒr    TrcrQrRrÜ©r¾r    ÚadapterÚ
fire_eventr†cCs
tƒ‚dSr‡r*©rr¾r    rcrdrwrwrƒÚ_dispose_previous_collectionõsz1HasCollectionAdapter._dispose_previous_collection.rMú Literal[None]ú Literal[PassiveFlag.PASSIVE_OFF]©r¾rîÚ    user_datar‘r†cCsdSr‡rw©rr¾rîrjr‘rwrwrƒÚget_collectionþsz#HasCollectionAdapter.get_collectionr5cCsdSr‡rwrkrwrwrƒrlsú$Optional[_AdaptedCollectionProtocol]úIUnion[Literal[LoaderCallableStatus.PASSIVE_NO_RESULT], CollectionAdapter]cCsdSr‡rwrkrwrwrƒrls
NcCs
tƒ‚dSr‡r*rkrwrwrƒrls    Frr©    r¾rîr¡r;r‘rArÚ_adaptr†c        Cs
tƒ‚dSr‡r*)    rr¾rîr¡r;r‘rArrprwrwrƒrá)s zHasCollectionAdapter.set)..)..)..) rÈrÐrÑrÓrÔrFrfr rlr5r2rárwrwrwrƒraïs2
    û    û    ûû÷raz"TypeGuard[CollectionAttributeImpl])rgr†cCsdSr‡rw)rgrwrwrƒÚ_is_collection_attribute_impl9srqr    c s<eZdZUdZdZdZdZdZdZde    d<dZ
dO‡fdd    „    Z d
d „Z e fd d dddœdd„Zefd d dddœdd„Zd d dddddœdd„Zd d dddddœdd„Zd d ddddœd d!„Zd d d"ddddœd#d$„Zd d dd%œd&d'„Zd d d(d%œd)d*„Zd d+d,œd-d.„Ze fd d d"dddd/œd0d1„Ze fd d d"dddd/œd2d3„Ze fd d d"dddd/œd4d5„Zdej dddfd d d"ddd"d6d6dd7œ    d8d9„Zd d(d:d6dd;œd<d=„Zd(dd>œd?d@„Zd d d"d(dAœdBdC„Ze dPd d dEdFd:dGœdHdI„ƒZ!e dQd d d(dd:dGœdJdI„ƒZ!e dDe fd d dKddLdGœdMdI„ƒZ!de fd d dKddLdGœdNdI„Z!‡Z"S)RÚCollectionAttributeImpla«A collection-holding attribute that instruments changes in membership.
 
    Only handles collections of instrumented objects.
 
    InstrumentedCollectionAttribute holds an arbitrary, user-specified
    container object (defaulting to a list) and brokers access to the
    CollectionAdapter, a "view" onto that object that presents consistent bag
    semantics to the orm layer independent of the user data implementation.
 
    TFrÚ_bulk_replace_token)ÚcopyÚcollection_factoryrr rsÚ_duck_typed_asNc      s¨tƒj||||f||dœ|    —Ž|dkr.|j}||_||_t|tƒ|_t|tƒ|_    t|t
ƒ|_ t   | ¡¡|_t|jddƒr¤t |d¡dd„ƒ}
t |d¡dd„ƒ} dS)    N)rrÚ
_sa_linkerÚinit_collectioncSs| |¡dSr‡©rw©Útargetr    Úcollection_adapterrwrwrƒÚlink‚sz.CollectionAttributeImpl.__init__.<locals>.linkÚdispose_collectioncSs| d¡dSr‡ryrzrwrwrƒÚunlink†sz0CollectionAttributeImpl.__init__.<locals>.unlink)rÝr„Ú_CollectionAttributeImpl__copyrtrurÚ    OP_APPENDrrIr ÚOP_BULK_REPLACErsr=Úduck_type_collectionrvrÆr;Z listens_for) rrerfrroÚ typecallablerÚ copy_functionrr¸r}rrßrwrƒr„_s4 üúù
   ÿ
 
 
z CollectionAttributeImpl.__init__cCsdd„t |¡DƒS)NcSsg|]}|‘qSrwrw)r¬ÚyrwrwrƒÚ
<listcomp>‹sz2CollectionAttributeImpl.__copy.<locals>.<listcomp>)rr|)rÚitemrwrwrƒZ__copyŠszCollectionAttributeImpl.__copyrcrMr5rr)cCs.|j|||d}|tkrtSt |||¡SdSr<)rír1rRrÚfrom_collectionrSrwrwrƒr’sz#CollectionAttributeImpl.get_historyr-cs²|j|krgS||j}t|dƒ}|j|jkr¤|j|j}|tk    r¤dd„|Dƒ}dd„|Dƒ}t|ƒ‰t|ƒ‰‡fdd„|Dƒ‡fdd„|Dƒ‡fdd„|DƒSdd„|DƒS)    NÚ _sa_adaptercSs$g|]}|dk    rt|ƒpd|f‘qSr‡r©r¬Úcrwrwrƒr‡ªsÿz;CollectionAttributeImpl.get_all_pending.<locals>.<listcomp>cSs$g|]}|dk    rt|ƒpd|f‘qSr‡rr‹rwrwrƒr‡®sÿcs g|]\}}|ˆkr||f‘qSrwrw©r¬ÚsÚo©Ú original_setrwrƒr‡·sþcs g|]\}}|ˆkr||f‘qSrwrwrrrwrƒr‡¼scs g|]\}}|ˆkr||f‘qSrwrwr©Ú current_setrwrƒr‡½sþcSsg|]}t|ƒ|f‘qSrwr)r¬rrwrwrƒr‡Äs)rfrÆr4r*Údict)rr¾rîr‘rTr]Úcurrent_statesÚoriginal_statesrw©r“r‘rƒr.™s4
 
 
  þþ
þû
þúÿz'CollectionAttributeImpl.get_all_pendingrbrz Optional[Any])r¾rîr¡r;rfr†cCsX|jjD]}||||p|j|d}q| ||td¡|jrT|dk    rT| t|ƒ|d¡|S)N©rfT)ror@rrMr*rr(r©rr¾rîr¡r;rfr1rwrwrƒÚfire_append_eventÆs  z)CollectionAttributeImpl.fire_append_eventcCs(|jjD]}||||p|j|d}q|S)Nr˜)roZappend_wo_mutationrr™rwrwrƒÚfire_append_wo_mutation_eventØs z5CollectionAttributeImpl.fire_append_wo_mutation_eventrÜ)r¾rîr;rfr†cCs| ||td¡dS)afA special event used for pop() operations.
 
        The "remove" event needs to have the item to be removed passed to
        it, which in the case of pop from a set, we don't have a way to access
        the item before the operation.   the event is used for all pop()
        operations (even though set.pop is the one where it is really needed).
 
        TN)rMr*)rr¾rîr;rfrwrwrƒÚfire_pre_remove_eventåsz-CollectionAttributeImpl.fire_pre_remove_eventrcCsX|jr |dk    r | t|ƒ|d¡|jjD]}||||p:|j|dq(| ||td¡dS)NFr˜T)rr(rrorBr rMr*r™rwrwrƒrLös
 z)CollectionAttributeImpl.fire_remove_eventr/cCs@|j|krdS| ||td¡| ||j¡}| ¡||j=dSr|)rfrMr*rlr”Zclear_with_event)rr¾rîr    rwrwrƒräs 
zCollectionAttributeImpl.deleterQcCsF|j|kstdƒ‚|j|jkr*|j|jS| |¡\}}| |¡|S)z;Produce an empty collection for an un-initialized attributer0)rfr~Ú_empty_collectionsÚ_initialize_collectionZ
_set_empty)rr¾rîrcrjrwrwrƒr3s ÿ  
z&CollectionAttributeImpl._default_valuez4Tuple[CollectionAdapter, _AdaptedCollectionProtocol])r¾r†cCs0|j |j||j¡\}}|j |||¡||fSr‡)r‚Zinitialize_collectionrfrurorx)rr¾rcr    rwrwrƒrž$sÿz.CollectionAttributeImpl._initialize_collectionr:cCsv|j||d|d}|tkrT|j||||td}|j|ks@tdƒ‚| |j¡ |¡ntrft    |t
ƒsft‚|  ||¡dS©N)rjr‘r˜z,Collection was loaded during event handling.) rlr1ršr(rfr~Ú_get_pending_mutationr@rr—rRZappend_with_event©rr¾rîr¡r;r‘r    rwrwrƒr@0s,ÿÿÿþzCollectionAttributeImpl.appendcCsx|j||jd|d}|tkrV|j||||td|j|ksBtdƒ‚| |j¡ |¡nt    rht
|t ƒsht‚|  ||¡dSrŸ) rlr”r1rLr(rfr~r rBrr—rRZremove_with_eventr¡rwrwrƒrBHs ÿÿþzCollectionAttributeImpl.removec
Cs8z|j|||||dWntttfk
r2YnXdSr<)rBr`r6Ú
IndexErrorr?rwrwrƒr^szCollectionAttributeImpl.poprŒroc    Csn|}    }
d} | |¡\} } |r°| jdk    r4|  |    ¡}    qÆt |    ¡}|j}||k    rx|    dkrXdp^|    jj}|jj}td||fƒ‚t|    dƒrŒ|         ¡}    qÆ|t
kr¦t |    ƒ} |      ¡}    qÆt |    ƒ}    nt |    ¡t
krÆt |ƒ} t |    ƒ}|j}|jj|||| d|j||t|tj@Ad}|tkr| ||¡}n||
kr(dS| |||d¡|j}| ||j<tj||| |d| |||d¡dS)NrÜz/Incompatible collection type: %s is not %s-likeÚ _sa_iterator)Úkeysr=T)r;)ržZ
_converterr=rƒrvr¥rÈÚ    TypeErrorrýr£r”ÚlistÚvaluesÚiterrsroZ bulk_replacerír3r5r)r1r3rMrŠrfrrf)rr¾rîr¡r;r‘rArrpÚiterableZ orig_iterableZnew_keysZnew_collectionrjZ setting_typeZreceiving_typeÚgivenÚwantedZ
new_valuesZevtrOÚold_collectionrwrwrƒránsd 
 
ÿýÿÿ
 
 
 
 ý
 
 
ÿzCollectionAttributeImpl.setrRrbcCs,|`|j |jd¡|r(|j |||¡dSr‡)rŠrrrfror~rerwrwrƒrf¿sz4CollectionAttributeImpl._dispose_previous_collection)r    r†cCst|dƒ}d|_dS)NrŠT)rÆZ invalidated)rr    rcrwrwrƒÚ_invalidate_collectionÎs
z.CollectionAttributeImpl._invalidate_collection)r¾rîr¡r†c
Csš| |¡\}}|r| |¡||j|j<| ||jg¡|j|jkr–| |||d¡|j |j¡}|j}|j    }|D]}    | 
|    ¡qr|D]}    |  |    ¡q†|S)z=Set an attribute value on the given instance and 'commit' it.T) ržZappend_multiple_without_eventr”rfrEZ_pending_mutationsrMrZ added_itemsZ deleted_itemsZappend_without_eventZremove_without_event)
rr¾rîr¡r    rjÚpendingÚaddedÚremovedrˆrwrwrƒr7Ôs
    z+CollectionAttributeImpl.set_committed_value.rgrhricCsdSr‡rwrkrwrwrƒrlñsz&CollectionAttributeImpl.get_collectioncCsdSr‡rwrkrwrwrƒrlûsrmrncCsdSr‡rwrkrwrwrƒrls
cCs6|dkr0|j|||d}|tjkr&|Std|ƒ}|jS)z÷Retrieve the CollectionAdapter associated with the given state.
 
        if user_data is None, retrieves it from the state using normal
        "get()" rules, which will fire lazy callables or return the "empty"
        collection value.
 
        Nr=rQ)rír"r1rrŠ)rr¾rîrjr‘Zfetch_user_datarwrwrƒrls 
 
)NFNN)..)..)#rÈrÐrÑrÒrr    r
rër rÔrÓr„r€r2r’r0r.ršr›rœrLrär3ržr@rBrr5rárfr­r7r rlrðrwrwrßrƒrrBsn
 ÷+üü-  úúú÷ Qû    û    ûûrrzQueryableAttribute[Any]rŒrÜ)rrfÚuselistr†cs˜ˆjj‰ˆj‰‡fdd„‰‡‡‡‡fdd„}‡‡‡fdd„}‡‡‡fdd„}ˆrhtjˆd    |d
d
d
d ntjˆd |d
d
d
d tjˆd |d
d
d
d dS)z6Apply listeners to synchronize a two-way relationship.cs$tdt|ƒ|j|jˆjjfƒ‚dS)NzŽBidirectional attribute conflict detected: Passing object %s to attribute "%s" triggers a modify event on attribute "%s" via the backref "%s".)r`r9rrg)Ú child_stater;Ú
child_impl)rrwrƒÚ_acceptable_key_err;süüÿz.backref_listeners.<locals>._acceptable_key_errcs||kr |S|dk    r~|tk    r~|tk    r~t|ƒt|ƒ}}|jˆj}|jsV|jsV|j}n|j    }||k    r~|j
|||  ¡ˆj t d|dk    r t|ƒt|ƒ}    }
|    jˆj} |jˆk    rÈ|j| jk    rȈ||| ƒ| j } t| ƒrÜ| jnd} || k    r || k    r | j|    |
|  ¡|t d|Sr<)r1r*rrr‚rgr    r r r rr'rr.rrqrsr@)r¾ÚchildZoldchildr;r±Ú    old_stateZold_dictrgZcheck_recursive_tokenr²Ú
child_dictr³Úcheck_append_tokenÚcheck_bulk_replace_token)r´rfÚ parent_implrrwrƒÚ"emit_backref_from_scalar_set_eventIsdÿþýþ  û
þ ÿ
þ ÿýÿþûz=backref_listeners.<locals>.emit_backref_from_scalar_set_eventc    s|dkr dSt|ƒt|ƒ}}|jˆj}|jˆk    rL|j|jk    rLˆ|||ƒ|j}t|ƒr`|jnd}||k    rŒ||k    rŒ|j|||     ¡|t
d|Sr<) rrr‚rgrrrqrsr@r'r.)    r¾rµr;r±r²r·r³r¸r¹)r´rfrrwrƒÚ)emit_backref_from_collection_append_eventŒs4 ÿ
þ ÿýÿþûzDbackref_listeners.<locals>.emit_backref_from_collection_append_eventc
s¼|dk    r¸|tk    r¸|tk    r¸t|ƒt|ƒ}}|jˆj}|js\|js\|j}|j    }ˆoXˆj }    n|j}t
|ƒrp|j nd}d}    ||k    r¸||k    r¸|    r t   |jˆj|¡s¸|j||| ¡|tddS)NFr=)r1r*rrr‚rgr    r r r rqrsr=Z    has_dupesr”rfrr'r.)
r¾rµr;r±r²r·r³Zcheck_remove_tokenZcheck_replace_tokenZcheck_for_dupes_on_remove)rfrºr±rwrƒÚ)emit_backref_from_collection_remove_event°sFÿþýþ  ÿýÿþ
üûzDbackref_listeners.<locals>.emit_backref_from_collection_remove_eventr@T)rÿÚrawZ include_keyrárBN)rgrr;Úlisten)rrfr±r»r¼r½rw)r´rrfrºrr±rƒÚbackref_listeners+s>  C$1ú    ú    úrÀZ
NO_HISTORYc@sÚeZdZUdZded<ded<ded<ddœdd    „Zddœd
d „Zd dœd d„Zd dœdd„Zd dœdd„Z    ddœdd„Z
ddœdd„Z e dddddœdd„ƒZ e efddddddœdd „ƒZe d!ddddœd"d#„ƒZd$S)%raA 3-tuple of added, unchanged and deleted values,
    representing the changes which have occurred on an instrumented
    attribute.
 
    The easiest way to get a :class:`.History` object for a particular
    attribute on an object is to use the :func:`_sa.inspect` function::
 
        from sqlalchemy import inspect
 
        hist = inspect(myobject).attrs.myattribute.history
 
    Each tuple member is an iterable sequence:
 
    * ``added`` - the collection of items added to the attribute (the first
      tuple element).
 
    * ``unchanged`` - the collection of items that have not changed on the
      attribute (the second tuple element).
 
    * ``deleted`` - the collection of items that have been removed from the
      attribute (the third tuple element).
 
    zUnion[Tuple[()], List[Any]]r¯Ú    unchangedÚdeletedrŒr…cCs|tkSr‡)rRrŠrwrwrƒÚ__bool__    szHistory.__bool__cCst|jp|jp|jƒ S)zhReturn True if this :class:`.History` has no changes
        and no existing, unchanged state.
 
        )rŒr¯rÂrÁrŠrwrwrƒÚempty"    sz History.emptyz Sequence[Any]cCs|jpg|jpg|jpgS)z3Return a collection of added + unchanged + deleted.)r¯rÁrÂrŠrwrwrƒÚsum*    sÿz History.sumcCs|jpg|jpgS)z)Return a collection of added + unchanged.)r¯rÁrŠrwrwrƒÚ non_deleted1    szHistory.non_deletedcCs|jpg|jpgS)z+Return a collection of unchanged + deleted.)rÁrÂrŠrwrwrƒÚ    non_added6    szHistory.non_addedcCst|jp |jƒS)z2Return True if this :class:`.History` has changes.)rŒr¯rÂrŠrwrwrƒÚ has_changes;    szHistory.has_changescCs0tdd„|jDƒdd„|jDƒdd„|jDƒƒS)NcSs g|]}|dk    rt|ƒpd‘qSr‡rr‹rwrwrƒr‡B    sÿz$History.as_state.<locals>.<listcomp>cSs g|]}|dk    rt|ƒpd‘qSr‡rr‹rwrwrƒr‡F    sÿcSs g|]}|dk    rt|ƒpd‘qSr‡rr‹rwrwrƒr‡J    sÿ)rr¯rÁrÂrŠrwrwrƒÚas_state@    sþþþ÷zHistory.as_staterGrcr)rr¾rTr†cCs°|j |jt¡}|tkr<|tkr,|dddƒS|d|gdƒSnp|tk    rb| ||¡dkrb|d|gdƒSt|ƒtkr„d}t|ƒtkrŠd}n|g}|tkrž|dd|ƒS||gd|ƒSdS)NrwT)r4rírfr_r*rr$Ú_NO_STATE_SYMBOLS©rÞrr¾rTr]rÂrwrwrƒrQP    s$ ÿþ   zHistory.from_scalar_attributer\)rr¾rTr]r†cCs¸|tkr|j |jt¡}|tkrD|tkr4|dddƒS|d|gdƒSnp||krb|tk    rb|d|gdƒSt|ƒtksv|dkrŒd}t|ƒtkr’d}n|g}|tkr¦|dd|ƒS||gd|ƒSdS)Nrw)r_r4rírfr*r$rÊrËrwrwrƒr^y    s 
   zHistory.from_object_attributerrcsÄ|j |jt¡}|tkr$|dddƒSt|dƒ}|tkrF|t|ƒddƒS|tkr^|dt|ƒdƒSdd„|Dƒ}dd„|Dƒ}t|ƒ‰t|ƒ‰|‡fdd„|Dƒ‡fdd„|Dƒ‡fdd„|DƒƒSdS)    NrwrŠcSs$g|]}|dk    rt|ƒpd|f‘qSr‡rr‹rwrwrƒr‡²    sÿz+History.from_collection.<locals>.<listcomp>cSs$g|]}|dk    rt|ƒpd|f‘qSr‡rr‹rwrwrƒr‡¶    sÿcsg|]\}}|ˆkr|‘qSrwrwrrrwrƒr‡¿    scsg|]\}}|ˆkr|‘qSrwrwrrrwrƒr‡À    scsg|]\}}|ˆkr|‘qSrwrwrr’rwrƒr‡Á    s)r4rírfr_r*rÆr¦r”)rÞrr¾rTr]r•r–rwr—rƒr‰     s* 
þþýzHistory.from_collectionN)rÈrÐrÑrÒrÔrÃrÄrÅrÆrÇrÈrÉÚ classmethodrQr_r^r‰rwrwrwrƒr    s$
(û&rrwràr5)r'rfr‘r†cCstt|ƒ||ƒS)a
Return a :class:`.History` record for the given object
    and attribute key.
 
    This is the **pre-flush** history for a given attribute, which is
    reset each time the :class:`.Session` flushes changes to the
    current database transaction.
 
    .. note::
 
        Prefer to use the :attr:`.AttributeState.history` and
        :meth:`.AttributeState.load_history` accessors to retrieve the
        :class:`.History` for instance attributes.
 
 
    :param obj: an object whose class is instrumented by the
      attributes package.
 
    :param key: string attribute name.
 
    :param passive: indicates loading behavior for the attribute
       if the value is not already present.   This is a
       bitflag attribute, which defaults to the symbol
       :attr:`.PASSIVE_OFF` indicating all necessary SQL
       should be emitted.
 
    .. seealso::
 
        :attr:`.AttributeState.history`
 
        :meth:`.AttributeState.load_history` - retrieve history
        using loader callables if the value is not locally present.
 
    )Úget_state_historyr)r'rfr‘rwrwrƒr’È    s%r’r8cCs | ||¡Sr‡)r’)r¾rfr‘rwrwrƒrÍð    srÍFrP)rÞr'rfr¿r†cCst|ƒ}t|ƒ}| |||¡S)ZTODO)r#rÚ
has_parent)rÞr'rfr¿r‚r¾rwrwrƒrÎö    srÎ)rúrurvræ)rerfrhrsrúr±r†cKs$t|||||d}t||f|Ž|S)N)rhrsrú)Úregister_descriptorÚregister_attribute_impl)rerfrhrsrúr±ÚdescrwrwrƒÚregister_attributeÿ    s    ÿrÒzOptional[_LoaderCallable]zOptional[Type[AttributeImpl]])    rerfr±rÚ    useobjectÚ
impl_classÚbackrefr±r†c KsÞt|ƒ}|r*| dd¡}    | ||    p$t¡}
n | dd¡}
td||jƒ} |rdtd|ƒ|||
| f|Ž} nJ|r„t|||| fd|
i|—Ž} n*|rœt|||| f|Ž} nt|||| f|Ž} | ||_    |rÌt
||||ƒ|  |¡||S)Nr„rzType[WriteOnlyAttributeImpl]) r#rZinstrument_collection_classr¦rrorrr\rGrgrÀZpost_configure_attribute) rerfr±rrÓrÔrÕr±r‚Úfactoryr„rorgrwrwrƒrÐ
s^  ÿ ÿÿÿÿÿÿÿÿ
 
rÐz    Type[Any]rr)rerfrhrsrúr†cCs.t|ƒ}t||||d}||_| ||¡|S)N)rhrs)r#rÚrÒZinstrument_attribute)rerfrhrsrúr‚rörwrwrƒrÏC
sÿ rÏ)rerfr†cCst|ƒ |¡dSr‡)r#Zuninstrument_attribute)rerfrwrwrƒÚunregister_attributeW
sr×rR)r'rfr†cCst|ƒ}|j}t|||ƒS)a4Initialize a collection attribute and return the collection adapter.
 
    This function is used to provide direct access to collection internals
    for a previously unloaded attribute.  e.g.::
 
        collection_adapter = init_collection(someobject, 'elements')
        for elem in values:
            collection_adapter.append_without_event(elem)
 
    For an easier way to do the above, see
    :func:`~sqlalchemy.orm.attributes.set_committed_value`.
 
    :param obj: a mapped object
 
    :param key: string attribute name where the collection is located.
 
    )rr”Úinit_state_collection)r'rfr¾rîrwrwrƒrx[
srxrM)r¾rîrfr†cCst|j|j}trt|tƒst‚| |d¡}|dk    rH|j}| |||d¡|     ||¡}|j
|||t j d}|  ¡|S)z„Initialize a collection attribute and return the collection adapter.
 
    Discards any existing collection which may be there.
 
    NFr=)r‚rgrr—rar~rrŠrfr3rlr5r.Z _reset_empty)r¾rîrfÚattrrOr¬rjrcrwrwrƒrØr
s    ÿrØcCs,t|ƒt|ƒ}}|j|j |||¡dS)a[Set the value of an attribute with no history events.
 
    Cancels any previous history present.  The value should be
    a scalar value for scalar-holding attributes, or
    an iterable for any collection-holding attribute.
 
    This is the same underlying method used when a lazy loader
    fires off and loads additional data from the database.
    In particular, this method can be used by application code
    which has loaded additional attributes or collections through
    separate queries, which can then be attached to an instance
    as though it were part of its original loaded state.
 
    N)rrr‚rgr7)rrfr¡r¾rîrwrwrƒr7
sr7r)rrfr¡r;r†cCs.t|ƒt|ƒ}}|j|j ||||¡dS)asSet the value of an attribute, firing history events.
 
    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.
    Custom attribute management schemes will need to make usage
    of this method to establish attribute state as understood
    by SQLAlchemy.
 
    :param instance: the object that will be modified
 
    :param key: string name of the attribute
 
    :param value: value to assign
 
    :param initiator: an instance of :class:`.Event` that would have
     been propagated from a previous event listener.  This argument
     is used when the :func:`.set_attribute` function is being used within
     an existing event listening function where an :class:`.Event` object
     is being supplied; the object may be used to track the origin of the
     chain of events.
 
     .. versionadded:: 1.2.3
 
    N)rrr‚rgrá)rrfr¡r;r¾rîrwrwrƒÚ set_attribute 
srÚ)rrfr†cCs&t|ƒt|ƒ}}|j|j ||¡S)aZGet the value of an attribute, firing any callables required.
 
    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.
    Custom attribute management schemes will need to make usage
    of this method to make usage of attribute state as understood
    by SQLAlchemy.
 
    )rrr‚rgrí©rrfr¾rîrwrwrƒÚ get_attributeÂ
s
rÜcCs*t|ƒt|ƒ}}|j|j ||¡dS)aQDelete the value of an attribute, firing history events.
 
    This function may be used regardless of instrumentation
    applied directly to the class, i.e. no descriptors are required.
    Custom attribute management schemes will need to make usage
    of this method to establish attribute state as understood
    by SQLAlchemy.
 
    N)rrr‚rgrärÛrwrwrƒÚ del_attributeÐ
s
rÝcCsDt|ƒt|ƒ}}|j|j}|j ||j¡|j||tdddS)aøMark an attribute on an instance as 'modified'.
 
    This sets the 'modified' flag on the instance and
    establishes an unconditional change event for the given attribute.
    The attribute must have a value present, else an
    :class:`.InvalidRequestError` is raised.
 
    To mark an object "dirty" without referring to any specific attribute
    so that it is considered within a flush, use the
    :func:`.attributes.flag_dirty` call.
 
    .. seealso::
 
        :func:`.attributes.flag_dirty`
 
    T©Z is_userlandN)    rrr‚rgroÚmodifiedrrMr*)rrfr¾rîrgrwrwrƒÚ flag_modifiedÞ
s ràrãcCs(t|ƒt|ƒ}}|j|dtdddS)a¹Mark an instance as 'dirty' without any specific attribute mentioned.
 
    This is a special operation that will allow the object to travel through
    the flush process for interception by events such as
    :meth:`.SessionEvents.before_flush`.   Note that no SQL will be emitted in
    the flush process for an object that has no changes, even if marked dirty
    via this method.  However, a :meth:`.SessionEvents.before_flush` handler
    will be able to see the object in the :attr:`.Session.dirty` collection and
    may establish changes on it, which will then be included in the SQL
    emitted.
 
    .. versionadded:: 1.2
 
    .. seealso::
 
        :func:`.attributes.flag_modified`
 
    NTrÞ)rrrMr*)rr¾rîrwrwrƒÚ
flag_dirtyõ
srá)F)FNFNN)N)«rÒÚ
__future__rZ dataclassesrÚtypingrrrrrrr    r
r r r rrrrÚrrrìrÚ_typingrr@rrrrrrrrr r!r"r#r$r%r&r'r(r)r*r+r,r-r.r/r0r1r2r3r4r5r6r7r8r9r;r<r=r>r?ZsqlZsql_baserArBrCrDZ sql.cache_keyrEZ sql.visitorsrFrGZ util.typingrHrIrJrKrLrMrNrOrPrQrRrSZ relationshipsrTr¾rUrVZ    writeonlyrWZ
event.baserXZ sql._typingrYrZr[r\Zsql.annotationr]Z sql.elementsr^r_Z sql.operatorsr`Zsql.selectablerarbràr-r˜Z_self_inspectsZInspectionAttrZPropComparatorZJoinTargetRoleZ OnClauseRoleZ    ImmutableZSlotsMemoizedHasCacheKeyrÄrdrˆrÚZ    dataclassròrÚsymbolrIrrHr‚rrZAttributeEventÚEventrtrGr\rarqÚ
attrgetterrrrÀr_Ú    frozensetr$rÊrrRr’rÍrÎrÒrÐrÏr×rxrØr7rÚrÜrÝràrárwrwrwrƒÚ<module>    sf                                                                                                  ÿ
ög?
+
 
 
 
 
3gVH
lT
D ÿ)ÿÿúù :úü"