U kf[=@sdZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z ddlmZ dd lmZdd lmZdd lmZdd lmZddlmZddlmZdZddZegZGdddeZee _Zee _GdddZGdddeZddZddZddZdS)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)InstrumentationFactoryZ__sa_instrumentation_manager__cCs t|tdS)z;Find user-specified instrumentation management for a class.N)getattrINSTRUMENTATION_MANAGERclsrN/opt/hc_python/lib64/python3.8/site-packages/sqlalchemy/ext/instrumentation.py%find_native_user_instrumentation_hookEsrcs|eZdZdZeZeZeZdZ ddZ ddZ ddZ d d Z fd d Zd dZddZddZddZZS)ExtendedInstrumentationRegistryzExtends :class:`.InstrumentationFactory` with additional bookkeeping, to accommodate multiple types of class managers. FcCs6tD],}||}|dk r|||}||fSqdS)N)NN)instrumentation_finders_extended_class_manager)selfclass_finderfactorymanagerrrr_locate_extended_factorygs  z8ExtendedInstrumentationRegistry._locate_extended_factorycCs0|||g}|r,td|jt|fdS)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|tst||}|tkr6|js6d|_t||j|<||j|<| |j |<|S)NT) isinstancer _ClassInstrumentationAdapter _extended_install_instrumented_lookupsmanager_getter_manager_finders state_getter_state_finders dict_getter _dict_finders)rrrrrrrr{s  z7ExtendedInstrumentationRegistry._extended_class_managercCstt|}t}|D]P}||}|dk r8||jqtD]}||}|dk r<qZqr.r:r9r r?rrrdict_ofsz'ExtendedInstrumentationRegistry.dict_of)r" __module__ __qualname____doc__weakrefWeakKeyDictionaryr*r,r.r'rr$rrr6r0r<rArB __classcell__rrr8rr[s    rc@seZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZddZddZddZd 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|dSN_default_class_managersetattrrrrrrrmanageszInstrumentationManager.managecCst|ddSrKdelattrrOrrrr6sz!InstrumentationManager.unregistercCs dd}|S)NcSs|jSr4)rLrrrrr:sz2InstrumentationManager.manager_getter..getr)rrr:rrrr)sz%InstrumentationManager.manager_gettercCsdSr4rrrkeyinstrrrinstrument_attributesz+InstrumentationManager.instrument_attributecCsdSr4rrSrrrpost_configure_attributesz/InstrumentationManager.post_configure_attributecCst|||dSr4rMrSrrrinstall_descriptor sz)InstrumentationManager.install_descriptorcCst||dSr4rQrrrTrrruninstall_descriptor sz+InstrumentationManager.uninstall_descriptorcCst|||dSr4rM)rrrTimplementationrrrinstall_membersz%InstrumentationManager.install_membercCst||dSr4rQrYrrruninstall_membersz'InstrumentationManager.uninstall_membercCs t|Sr4)rZprepare_instrumentation)rrrTcollection_classrrrinstrument_collection_classsz2InstrumentationManager.instrument_collection_classcCs|jSr4)__dict__rrr@rrrget_instance_dictsz(InstrumentationManager.get_instance_dictcCsdSr4rrarrrinitialize_instance_dictsz/InstrumentationManager.initialize_instance_dictcCst|d|dSNZ_default_staterM)rrr@staterrr install_statesz$InstrumentationManager.install_statecCst|ddSrdrQrarrr remove_state!sz#InstrumentationManager.remove_statecCsddS)NcSs t|dSrd)r)r@rrr%z5InstrumentationManager.state_getter..rr7rrrr+$sz#InstrumentationManager.state_gettercsfddS)Ncs |Sr4)rb)rUrrrrrh(riz4InstrumentationManager.dict_getter..rr7rrjrr-'sz"InstrumentationManager.dict_getterN)r"rCrDrErJrPr6r)rVrWrXrZr\r]r_rbrcrfrgr+r-rrrrrIs$rIcseZdZdZddZddZddZdd Zd*d d Zfd dZ ddZ ddZ ddZ ddZ ddZddZd+ddZddZd,d d!Zd"d#Zd$d%Zd&d'Zd(d)ZZS)-r&z?Adapts a user-defined InstrumentationManager to a ClassManager.cCs2||_|j||_|j||_t||dSr4)_adaptedr+ _get_stater- _get_dictr rJ)rroverriderrrrJ.sz%_ClassInstrumentationAdapter.__init__cCs|j|j|dSr4)rkrPrrrrrrP5sz#_ClassInstrumentationAdapter.managecCs|j|j|dSr4)rkr6rrorrrr68sz'_ClassInstrumentationAdapter.unregistercCs|j|jSr4)rkr)rrorrrr);sz+_ClassInstrumentationAdapter.manager_getterFcCs*t|||||s&|j|j||dSr4)r rVrkr)rrTrUZ propagatedrrrrV>sz1_ClassInstrumentationAdapter.instrument_attributecs&t||j|j|||dSr4)r5rWrkrrrTr8rrrWCs 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)Ninitialize_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)zInstall 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?rrrteardown_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 tttjtjtjtjddS)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_dictr<r0N)_install_lookupsdict_instrumentation_factoryrArBr<r0rrrrr(s r(cCsttttttddt_dS)zRestore simplified lookups.rxFN)r{r|r r r r r}r'rrrr_reinstall_default_lookupssr~cCsr|da|da|da|datt_t_t_tt_t_t_tt_t_t_tt_t_t_t_dS)Nryrzr<r0)ryrzr<r0orm_baserorm_instrumentationorm_util)lookupsrrrr{s$   r{)rErFrZormrrrrrr;rrrZorm.instrumentationr r r r r rrrrrr}rIr&r(r~r{rrrr s4             La