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
U
¸ý°d/?ã@sdZddlZddlmZddlmZddlmZddlmZddlm    Z
dd    lm Z ddlmZ dd
lmZdd lmZdd lmZdd lmZddlmZddlmZdZdd„ZegZGdd„deƒZeƒe _Zee _Gdd„dƒZGdd„deƒZdd„Zdd„Zdd„ZdS)aExtensible class instrumentation.
 
The :mod:`sqlalchemy.ext.instrumentation` package provides for alternate
systems of class instrumentation within the ORM.  Class instrumentation
refers to how the ORM places attributes on the class which maintain
data and track changes to that data, as well as event hooks installed
on the class.
 
.. note::
    The extension package is provided for the benefit of integration
    with other object management packages, which already perform
    their own instrumentation.  It is not intended for general use.
 
For examples of how the instrumentation extension is used,
see the example :ref:`examples_instrumentation`.
 
éNé)Úutil)Ú
attributes)Úbase)Ú collections)Úexc)Úinstrumentation)Ú_default_dict_getter)Ú_default_manager_getter)Ú_default_opt_manager_getter)Ú_default_state_getter)Ú ClassManager)ÚInstrumentationFactoryZ__sa_instrumentation_manager__cCs t|tdƒS)z;Find user-specified instrumentation management for a class.N)ÚgetattrÚINSTRUMENTATION_MANAGER©Úcls©rúUd:\z\workplace\vscode\pyvenv\venv\Lib\site-packages\sqlalchemy/ext/instrumentation.pyÚ%find_native_user_instrumentation_hookEsrcs|eZdZdZe ¡Ze ¡Ze ¡ZdZ    dd„Z
dd„Z dd„Z d    d
„Z ‡fd d „Zd d„Zdd„Zdd„Zdd„Z‡ZS)ÚExtendedInstrumentationRegistryz„Extends :class:`.InstrumentationFactory` with additional
    bookkeeping, to accommodate multiple types of
    class managers.
 
    FcCs6tD],}||ƒ}|dk    r| ||¡}||fSqdS)N)NN)Úinstrumentation_findersÚ_extended_class_manager)ÚselfÚclass_ÚfinderÚfactoryÚmanagerrrrÚ_locate_extended_factorygs  z8ExtendedInstrumentationRegistry._locate_extended_factorycCs0| |¡ |g¡}|r,td|jt|ƒfƒ‚dS)NzRmultiple instrumentation implementations specified in %s inheritance hierarchy: %r)Ú!_collect_management_factories_forÚ
differenceÚ    TypeErrorÚ__name__Úlist)rrrZexisting_factoriesrrrÚ_check_conflictspsÿþ þÿz0ExtendedInstrumentationRegistry._check_conflictscCsd||ƒ}t|tƒst||ƒ}|tkr6|js6d|_tƒ| ¡|j|<| ¡|j|<|     ¡|j
|<|S)NT) Ú
isinstancer Ú_ClassInstrumentationAdapterÚ    _extendedÚ_install_instrumented_lookupsÚmanager_getterÚ_manager_findersÚ state_getterÚ_state_findersÚ dict_getterÚ _dict_finders)rrrrrrrr{s
 
z7ExtendedInstrumentationRegistry._extended_class_managercCstt |¡}tƒ}|D]P}| |¡}|dk    r8| |j¡qtD]}||ƒ}|dk    r<qZq<d}| |¡q| d¡|S)acReturn a collection of factories in play or specified for a
        hierarchy.
 
        Traverses the entire inheritance graph of a cls and returns a
        collection of instrumentation factories for those classes. Factories
        are extracted from active ClassManagers, if available, otherwise
        instrumentation_finders is consulted.
 
        N)rZclass_hierarchyÚsetÚopt_manager_of_classÚaddrrÚdiscard)rrZ    hierarchyZ    factoriesÚmemberrrrrrrrŒs
 
 
 
zAExtendedInstrumentationRegistry._collect_management_factories_forcs2tƒ |¡||jkr.|j|=|j|=|j|=dS©N)ÚsuperÚ
unregisterr*r,r.©rr©Ú    __class__rrr6§s
 
z*ExtendedInstrumentationRegistry.unregistercCs6z|j |t¡}Wntk
r(YdSX||ƒSdSr4)r*Úgetr r!)rrrrrrr0®sÿz4ExtendedInstrumentationRegistry.opt_manager_of_classcCsdz|j |t¡}Wn&tk
r8t |d|›¡‚Yn(X||ƒ}|dkr\t |d|›¡‚|SdS)Nz2Can't locate an instrumentation manager for class )r*r:r
r!Úorm_excZUnmappedClassError)rrrrrrrÚmanager_of_class¹sÿ
þz0ExtendedInstrumentationRegistry.manager_of_classcCs$|dkrtdƒ‚|j |jt¡|ƒS©NzNone has no persistent state.)ÚAttributeErrorr,r:r9r ©rÚinstancerrrÚstate_ofÊsÿþz(ExtendedInstrumentationRegistry.state_ofcCs$|dkrtdƒ‚|j |jt¡|ƒSr=)r>r.r:r9r    r?rrrÚdict_ofÑsÿþz'ExtendedInstrumentationRegistry.dict_of)r"Ú
__module__Ú __qualname__Ú__doc__ÚweakrefÚWeakKeyDictionaryr*r,r.r'rr$rrr6r0r<rArBÚ __classcell__rrr8rr[s       rc@s˜eZdZdZdd„Zdd„Zdd„Zdd    „Zd
d „Zd d „Z    dd„Z
dd„Z dd„Z dd„Z dd„Zdd„Zdd„Zdd„Zdd„Zd d!„Zd"d#„Zd$S)%ÚInstrumentationManageraWUser-defined class instrumentation extension.
 
    :class:`.InstrumentationManager` can be subclassed in order
    to change
    how class instrumentation proceeds. This class exists for
    the purposes of integration with other object management
    frameworks which would like to entirely modify the
    instrumentation methodology of the ORM, and is not intended
    for regular usage.  For interception of class instrumentation
    events, see :class:`.InstrumentationEvents`.
 
    The API for this class should be considered as semi-stable,
    and may change slightly with new releases.
 
    cCsdSr4rr7rrrÚ__init__ôszInstrumentationManager.__init__cCst|d|ƒdS©NÚ_default_class_manager©Úsetattr©rrrrrrÚmanage÷szInstrumentationManager.managecCst|dƒdSrK©ÚdelattrrOrrrr6úsz!InstrumentationManager.unregistercCs dd„}|S)NcSs|jSr4)rLrrrrr:þsz2InstrumentationManager.manager_getter.<locals>.getr)rrr:rrrr)ýsz%InstrumentationManager.manager_gettercCsdSr4r©rrÚkeyÚinstrrrÚinstrument_attributesz+InstrumentationManager.instrument_attributecCsdSr4rrSrrrÚpost_configure_attributesz/InstrumentationManager.post_configure_attributecCst|||ƒdSr4rMrSrrrÚinstall_descriptor    sz)InstrumentationManager.install_descriptorcCst||ƒdSr4rQ©rrrTrrrÚuninstall_descriptor sz+InstrumentationManager.uninstall_descriptorcCst|||ƒdSr4rM)rrrTÚimplementationrrrÚinstall_membersz%InstrumentationManager.install_membercCst||ƒdSr4rQrYrrrÚuninstall_membersz'InstrumentationManager.uninstall_membercCs
t |¡Sr4)rZprepare_instrumentation)rrrTÚcollection_classrrrÚinstrument_collection_classsz2InstrumentationManager.instrument_collection_classcCs|jSr4)Ú__dict__©rrr@rrrÚget_instance_dictsz(InstrumentationManager.get_instance_dictcCsdSr4rrarrrÚinitialize_instance_dictsz/InstrumentationManager.initialize_instance_dictcCst|d|ƒdS©NZ_default_staterM)rrr@ÚstaterrrÚ install_statesz$InstrumentationManager.install_statecCst|dƒdSrdrQrarrrÚ remove_state!sz#InstrumentationManager.remove_statecCsdd„S)NcSs
t|dƒSrd)r)r@rrrÚ<lambda>%óz5InstrumentationManager.state_getter.<locals>.<lambda>rr7rrrr+$sz#InstrumentationManager.state_gettercs‡‡fdd„S)Ncs ˆ ˆ|¡Sr4)rb)rU©rrrrrh(riz4InstrumentationManager.dict_getter.<locals>.<lambda>rr7rrjrr-'sz"InstrumentationManager.dict_getterN)r"rCrDrErJrPr6r)rVrWrXrZr\r]r_rbrcrfrgr+r-rrrrrIßs$rIcs¶eZdZdZdd„Zdd„Zdd„Zdd    „Zd*d d „Z‡fd d„Z    dd„Z
dd„Z dd„Z dd„Z dd„Zdd„Zd+dd„Zdd„Zd,d d!„Zd"d#„Zd$d%„Zd&d'„Zd(d)„Z‡ZS)-r&z?Adapts a user-defined InstrumentationManager to a ClassManager.cCs2||_|j |¡|_|j |¡|_t ||¡dSr4)Ú_adaptedr+Ú
_get_stater-Ú    _get_dictr rJ)rrÚoverriderrrrJ.sz%_ClassInstrumentationAdapter.__init__cCs|j |j|¡dSr4)rkrPr©rrrrrP5sz#_ClassInstrumentationAdapter.managecCs|j |j|¡dSr4)rkr6rrorrrr68sz'_ClassInstrumentationAdapter.unregistercCs|j |j¡Sr4)rkr)rrorrrr);sz+_ClassInstrumentationAdapter.manager_getterFcCs*t ||||¡|s&|j |j||¡dSr4)r rVrkr)rrTrUZ
propagatedrrrrV>sz1_ClassInstrumentationAdapter.instrument_attributecs&tƒ |¡|j |j|||¡dSr4)r5rWrkr©rrTr8rrrWCs z5_ClassInstrumentationAdapter.post_configure_attributecCs|j |j||¡dSr4)rkrXr)rrTrUrrrrXGsz/_ClassInstrumentationAdapter.install_descriptorcCs|j |j|¡dSr4)rkrZrrprrrrZJsz1_ClassInstrumentationAdapter.uninstall_descriptorcCs|j |j||¡dSr4)rkr\r)rrTr[rrrr\Msz+_ClassInstrumentationAdapter.install_membercCs|j |j|¡dSr4)rkr]rrprrrr]Psz-_ClassInstrumentationAdapter.uninstall_membercCs|j |j||¡Sr4)rkr_r)rrTr^rrrr_Ss
ÿz8_ClassInstrumentationAdapter.instrument_collection_classcCs2t|jddƒ}|r||||ƒSt ||||¡SdS)NÚinitialize_collection)rrkr rq)rrTrerZdelegaterrrrqXs ÿz2_ClassInstrumentationAdapter.initialize_collectionNcCs|j |j¡}| ||¡|Sr4)rÚ__new__Úsetup_instance)rrer@rrrÚ new_instanceas z)_ClassInstrumentationAdapter.new_instancecCs| |¡rdS| |¡SdS)z‚Install a default InstanceState if none is present.
 
        A private convenience method used by the __init__ decorator.
        FN)Ú    has_statersr?rrrÚ_new_state_if_nonefs
z/_ClassInstrumentationAdapter._new_state_if_nonecCs:|j |j|¡|dkr$| ||¡}|j |j||¡|Sr4)rkrcrZ_state_constructorrf)rr@rerrrrsps
 z+_ClassInstrumentationAdapter.setup_instancecCs|j |j|¡dSr4)rkrgrr?rrrÚteardown_instancezsz._ClassInstrumentationAdapter.teardown_instancecCs0z| |¡Wntjk
r&YdSXdSdS)NFT)rlr;ZNO_STATEr?rrrru}s
z&_ClassInstrumentationAdapter.has_statecCs|jSr4)rlrorrrr+…sz)_ClassInstrumentationAdapter.state_gettercCs|jSr4)rmrorrrr-ˆsz(_ClassInstrumentationAdapter.dict_getter)F)N)N)r"rCrDrErJrPr6r)rVrWrXrZr\r]r_rqrtrvrsrwrur+r-rHrrr8rr&+s(
     
 
 
 
r&cCs tttjtjtjtjdƒdS)aºReplace global class/object management functions
    with ExtendedInstrumentationRegistry implementations, which
    allow multiple types of class managers to be present,
    at the cost of performance.
 
    This function is called only by ExtendedInstrumentationRegistry
    and unit tests specific to this behavior.
 
    The _reinstall_default_lookups() function can be called
    after this one to re-establish the default functions.
 
    ©Úinstance_stateÚ instance_dictr<r0N)Ú_install_lookupsÚdictÚ_instrumentation_factoryrArBr<r0rrrrr(Œs üÿr(cCsttttttdƒdt_dS)zRestore simplified lookups.rxFN)r{r|r r    r
r r}r'rrrrÚ_reinstall_default_lookups£süÿr~cCsr|da|da|da|datt_t_t_tt_t_t_tt_t_t_tt_t_t_t_dS)Nryrzr<r0)ryrzr<r0Úorm_baserÚorm_instrumentationÚorm_util)Zlookupsrrrr{°s.þþþüÿür{)rErFÚrZormrrrrrr;rr€rZorm.instrumentationr    r
r r r rrrrrr}rIr&r(r~r{rrrrÚ<module>    s8             þLa