L i[=<dZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z ddlmZ dd lmZdd lmZdd lmZdd lmZddlmZddlmZdZ dZegZ GddeZexe _Zee _GddZGddeZdZdZdZy)aExtensible 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)InstrumentationFactory__sa_instrumentation_manager__c$t|tdS)z;Find user-specified instrumentation management for a class.N)getattrINSTRUMENTATION_MANAGERclss d/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sqlalchemy/ext/instrumentation.py%find_native_user_instrumentation_hookrEs 3/ 66ceZdZdZej Zej Zej ZdZ dZ dZ dZ dZ fdZdZd Zd Zd ZxZS) ExtendedInstrumentationRegistryzExtends :class:`.InstrumentationFactory` with additional bookkeeping, to accommodate multiple types of class managers. Fc^tD]$}||}||j||}||fcSy)N)NN)instrumentation_finders_extended_class_manager)selfclass_finderfactorymanagers r_locate_extended_factoryz8ExtendedInstrumentationRegistry._locate_extended_factorygsB- FVnG"66vwG''   rc|j|j|g}|r$td|jdt |y)Nz6multiple instrumentation implementations specified in z inheritance hierarchy: )!_collect_management_factories_for difference TypeError__name__list)rrr!existing_factoriess r_check_conflictsz0ExtendedInstrumentationRegistry._check_conflictspsQ!CC  *gY   ??D);$<>  rcH||}t|ts t||}|tk7r|jsd|_t |j |j |<|j|j|<|j|j|<|S)NT) isinstancer_ClassInstrumentationAdapter _extended_install_instrumented_lookupsmanager_getter_manager_finders state_getter_state_finders dict_getter _dict_finders)rrr!r"s rrz7ExtendedInstrumentationRegistry._extended_class_manager{s&/'<0267CG l "4>>"DN ) +(/(>(>(@f%&-&:&:&<F#%,%8%8%:6"rc&tj|}t}|D][}|j|}||j |j 2t D]}||}|nd}|j |]|jd|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)rclass_hierarchysetopt_manager_of_classaddr!rdiscard)rr hierarchy factoriesmemberr"r r!s rr%zAExtendedInstrumentationRegistry._collect_management_factories_fors((- E  'F//7G" goo.5#F$VnG*# #G g& ' $rct||||jvr(|j|=|j|=|j|=yyN)super unregisterr2r4r6)rr __class__s rrCz*ExtendedInstrumentationRegistry.unregistersM 6" T** *%%f-##F+""6* +rcr |jj|t}||S#t$rYywxYwrA)r2getr r')rrr s rr:z4ExtendedInstrumentationRegistry.opt_manager_of_classsC **..0F#;    s * 66c |jj|t}||}|tj|d||S#t $rtj|d|wxYw)Nz2Can't locate an instrumentation manager for class )r2rFr orm_excUnmappedClassErrorr')rrr r"s rmanager_of_classz0ExtendedInstrumentationRegistry.manager_of_classs **..s4KLFSkG00HNN ,,I#O  s A#A*c|| td|jj|jt|SNzNone has no persistent state.)AttributeErrorr4rFrDr rinstances rstate_ofz(ExtendedInstrumentationRegistry.state_ofsE   !@A A t""&&    5  rc|| td|jj|jt|SrL)rMr6rFrDr rNs rdict_ofz'ExtendedInstrumentationRegistry.dict_ofsE   !@A A t!!%%    4  r)r( __module__ __qualname____doc__weakrefWeakKeyDictionaryr2r4r6r/r#r+rr%rCr:rJrPrR __classcell__rDs@rrr[sm 1w002.W..0N-G--/MI "6+ "rrcveZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zd ZdZdZdZdZdZy)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. cyrArrs r__init__zInstrumentationManager.__init__ rct|d|yN_default_class_managersetattrrrr"s rmanagezInstrumentationManager.manages0':rct|dyrbdelattrrfs rrCz!InstrumentationManager.unregisters 01rc d}|S)Nc|jSrA)rcrs rrFz2InstrumentationManager.manager_getter..gets-- -rr])rrrFs rr1z%InstrumentationManager.manager_getters . rcyrAr]rrkeyinsts rinstrument_attributez+InstrumentationManager.instrument_attributer`rcyrAr]rns rpost_configure_attributez/InstrumentationManager.post_configure_attributer`rct|||yrArdrns rinstall_descriptorz)InstrumentationManager.install_descriptor sT"rct||yrArirrros runinstall_descriptorz+InstrumentationManager.uninstall_descriptor  rct|||yrArd)rrroimplementations rinstall_memberz%InstrumentationManager.install_members^,rct||yrArirws runinstall_memberz'InstrumentationManager.uninstall_memberryrc,tj|SrA)rprepare_instrumentation)rrrocollection_classs rinstrument_collection_classz2InstrumentationManager.instrument_collection_classs223CDDrc|jSrA)__dict__rrrOs rget_instance_dictz(InstrumentationManager.get_instance_dicts   rcyrAr]rs rinitialize_instance_dictz/InstrumentationManager.initialize_instance_dictr`rct|d|yN_default_staterd)rrrOstates r install_statez$InstrumentationManager.install_states*E2rct|dyrrirs r remove_statez#InstrumentationManager.remove_state!s *+rcdS)Nct|dSr)r)rOs rz5InstrumentationManager.state_getter..%s2B Crr]r^s rr3z#InstrumentationManager.state_getter$sCCrcfdS)Nc(j|SrA)r)rprrs rrz4InstrumentationManager.dict_getter..(sD2264@rr]r^s``rr5z"InstrumentationManager.dict_getter's @@rN)r(rSrTrUr_rgrCr1rqrsrurxr|r~rrrrrr3r5r]rrr[r[s_( ;2   #-E! 3,DArr[ceZdZdZdZdZdZdZddZfdZ dZ d Z d Z d Z d Zd ZddZdZddZdZdZdZdZxZS)r.z?Adapts a user-defined InstrumentationManager to a ClassManager.c||_|jj||_|jj||_t j ||yrA)_adaptedr3 _get_stater5 _get_dictrr_)rroverrides rr_z%_ClassInstrumentationAdapter.__init__.sE  --44V<226:dF+rcP|jj|j|yrA)rrgrrs rrgz#_ClassInstrumentationAdapter.manage5s T[[$/rcP|jj|j|yrA)rrCrrs rrCz'_ClassInstrumentationAdapter.unregister8s   d3rcL|jj|jSrA)rr1rrs rr1z+_ClassInstrumentationAdapter.manager_getter;s}}++DKK88rctj|||||s(|jj|j||yyrA)rrqrr)rrorp propagateds rrqz1_ClassInstrumentationAdapter.instrument_attribute>s8))$T:F MM . .t{{C Frcxt|||jj|j|||yrA)rBrsrr)rrorDs rrsz5_ClassInstrumentationAdapter.post_configure_attributeCs. (- ..t{{CcKrcR|jj|j||yrA)rrur)rrorps rruz/_ClassInstrumentationAdapter.install_descriptorGs ((c4@rcP|jj|j|yrA)rrxrrros rrxz1_ClassInstrumentationAdapter.uninstall_descriptorJs **4;;>( #&&x0 0rc|jj|j|||j||}|jj |j|||SrA)rrr_state_constructorr)rrOrs rrz+_ClassInstrumentationAdapter.setup_instancepsR ..t{{HE =++Hd;E ##DKK5A rcP|jj|j|yrA)rrrrNs rteardown_instancez._ClassInstrumentationAdapter.teardown_instancezs ""4;;9rcZ |j|y#tj$rYywxYw)NTF)rrHNO_STATErNs rrz&_ClassInstrumentationAdapter.has_state}s2  OOH %  s **c|jSrA)rrs rr3z)_ClassInstrumentationAdapter.state_getters rc|jSrA)rrs rr5z(_ClassInstrumentationAdapter.dict_getters ~~r)FrA)r(rSrTrUr_rgrCr1rqrsrurxr|r~rrrrrrrr3r5rXrYs@rr.r.+siI,049G LA=G9  1:rr.ctttjtjtj tj y)aReplace 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_dictrJr:N)_install_lookupsdict_instrumentation_factoryrPrRrJr:r]rrr0r0s8 3<<2::5FF!9!N!N  rcjtttttt dt _y)zRestore simplified lookups.rFN)rrr r r r rr/r]rr_reinstall_default_lookupsrs) 0.4!<  */&rcj|da|da|da|datxt_xt _t _txt_xt _t _txt_xt _t _txt_xt_xt _t _y)NrrrJr:)rrrJr:orm_baserorm_instrumentationorm_util)lookupss rrrs-.NO,M12"#9: Hj7* HZ5) H ;,4HHH!HH$AH'0r)rUrVrormrrrrrrHr rrorm.instrumentationr r r r rrrrrrrr[r.r0rrr]rrrs"" 8"69=7.8;27 AA  {&<{~$%,/G/F+IAIAX^<^B. /Hr