U a9@sdZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd l mZdd l mZdd l mZdd l mZddl mZdZddZegZGdddeZee _Zee _GdddeZGdddeZddZddZddZdS)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_state_getter) ClassManager)InstrumentationFactoryZ__sa_instrumentation_manager__cCs t|tdS)z;Find user-specified instrumentation management for a class.N)getattrINSTRUMENTATION_MANAGERclsr_C:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-nyjtotrf\sqlalchemy\ext\instrumentation.py%find_native_user_instrumentation_hook;srcsteZdZdZeZeZeZdZ ddZ ddZ ddZ d d Z fd d Zd dZddZddZZS)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_factory]s  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_conflictsfs 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)rrrrrrrrqs  z7ExtendedInstrumentationRegistry._extended_class_managercCstt|}t}|D]P}||}|dk r8||jqtD]}||}|dk r<qZqr? __classcell__rrr7rrQs    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. cCsdSr3rr6rrr__init__szInstrumentationManager.__init__cCst|d|dSN_default_class_managersetattrrrrrrrmanageszInstrumentationManager.managecCst|ddSrHdelattrrLrrrr5sz!InstrumentationManager.unregistercCs dd}|S)NcSs|jSr3)rIrrrrr9sz2InstrumentationManager.manager_getter..getr)rrr9rrrr(sz%InstrumentationManager.manager_gettercCsdSr3rrrkeyinstrrrinstrument_attributesz+InstrumentationManager.instrument_attributecCsdSr3rrPrrrpost_configure_attributesz/InstrumentationManager.post_configure_attributecCst|||dSr3rJrPrrrinstall_descriptorsz)InstrumentationManager.install_descriptorcCst||dSr3rNrrrQrrruninstall_descriptorsz+InstrumentationManager.uninstall_descriptorcCst|||dSr3rJ)rrrQimplementationrrrinstall_membersz%InstrumentationManager.install_membercCst||dSr3rNrVrrruninstall_membersz'InstrumentationManager.uninstall_membercCs t|Sr3)rZprepare_instrumentation)rrrQcollection_classrrrinstrument_collection_classsz2InstrumentationManager.instrument_collection_classcCs|jSr3)__dict__rrr=rrrget_instance_dictsz(InstrumentationManager.get_instance_dictcCsdSr3rr^rrrinitialize_instance_dictsz/InstrumentationManager.initialize_instance_dictcCst|d|dSNZ_default_staterJ)rrr=staterrr install_statesz$InstrumentationManager.install_statecCst|ddSrarNr^rrr remove_statesz#InstrumentationManager.remove_statecCsddS)NcSs t|dSra)r)r=rrr z5InstrumentationManager.state_getter..rr6rrrr* sz#InstrumentationManager.state_gettercsfddS)Ncs |Sr3)r_)rRrrrrre rfz4InstrumentationManager.dict_getter..rr6rrgrr, sz"InstrumentationManager.dict_getterN)r!r@rArBrGrMr5r(rSrTrUrWrYrZr\r_r`rcrdr*r,rrrrrFs$rFcseZdZdZddZddZddZdd 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||dSr3)_adaptedr* _get_stater, _get_dictr rG)rroverriderrrrGsz%_ClassInstrumentationAdapter.__init__cCs|j|j|dSr3)rhrMrrrrrrMsz#_ClassInstrumentationAdapter.managecCs|j|j|dSr3)rhr5rrlrrrr5sz'_ClassInstrumentationAdapter.unregistercCs|j|jSr3)rhr(rrlrrrr( sz+_ClassInstrumentationAdapter.manager_getterFcCs*t|||||s&|j|j||dSr3)r rSrhr)rrQrRZ propagatedrrrrS#sz1_ClassInstrumentationAdapter.instrument_attributecs*tt|||j|j|||dSr3)r4r%rTrhrrrQr7rrrT(sz5_ClassInstrumentationAdapter.post_configure_attributecCs|j|j||dSr3)rhrUr)rrQrRrrrrU,sz/_ClassInstrumentationAdapter.install_descriptorcCs|j|j|dSr3)rhrWrrmrrrrW/sz1_ClassInstrumentationAdapter.uninstall_descriptorcCs|j|j||dSr3)rhrYr)rrQrXrrrrY2sz+_ClassInstrumentationAdapter.install_membercCs|j|j|dSr3)rhrZrrmrrrrZ5sz-_ClassInstrumentationAdapter.uninstall_membercCs|j|j||Sr3)rhr\r)rrQr[rrrr\8s z8_ClassInstrumentationAdapter.instrument_collection_classcCs2t|jdd}|r||||St||||SdS)Ninitialize_collection)rrhr rn)rrQrbrZdelegaterrrrn=s z2_ClassInstrumentationAdapter.initialize_collectionNcCs|j|j}||||Sr3)r__new__setup_instance)rrbr=rrr new_instanceFs 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_staterpr<rrr_new_state_if_noneKs z/_ClassInstrumentationAdapter._new_state_if_nonecCs:|j|j||dkr$|||}|j|j|||Sr3)rhr`rZ_state_constructorrc)rr=rbrrrrpUs  z+_ClassInstrumentationAdapter.setup_instancecCs|j|j|dSr3)rhrdrr<rrrteardown_instance_sz._ClassInstrumentationAdapter.teardown_instancecCs0z||Wntjk r&YdSXdSdS)NFT)riorm_excZNO_STATEr<rrrrrbs z&_ClassInstrumentationAdapter.has_statecCs|jSr3)rirlrrrr*jsz)_ClassInstrumentationAdapter.state_gettercCs|jSr3)rjrlrrrr,msz(_ClassInstrumentationAdapter.dict_getter)F)N)N)r!r@rArBrGrMr5r(rSrTrUrWrYrZr\rnrqrsrprtrrr*r,rErrr7rr%s(    r%cCstttjtjtjddS)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/N)_install_lookupsdict_instrumentation_factoryr>r?r/rrrrr'qs r'cCstttttddt_dS)zRestore simplified lookups.rvFN)ryrzr r r r{r&rrrr_reinstall_default_lookupssr|cCsR|da|da|datt_t_t_tt_t_t_tt_t_t_dS)Nrwrxr/)rwrxr/orm_baserorm_instrumentation)Zlookupsrrrrys ry)rBrCrZormrrr}rrrurr~Zorm.instrumentationr r r r r rrrrr{objectrFr%r'r|ryrrrrs2           oLa