o ]Lb.[@sdZddlmZddlZddlmZddlmZddlmZddlmZdd l m Z dd l m Z dd l m Z d ZGd ddeZeZGdddeZeZzddlmZWn ey`eZYnwGdddeZeZzddlmZWn ey~eZYnwGdddeZGdddeeZee GdddeZGdddeeZee GdddeZdd Zd!d"Z d#d$Z!d%d&Z"dS)'zAdapter management )absolute_importN) implementer) providedBy Interface)ro)IAdapterRegistry)_normalize_name) STRING_TYPESc@seZdZdZdZdddZddZedd d d Zd d Z d dZ ddZ e fddZ dddZddZdddZddZdS)BaseAdapterRegistry) lookupqueryMultiAdapterlookup1 queryAdapter adapter_hook lookupAllnames subscriptions subscribersrcCs$g|_g|_i|_|||_dSN) _adapters _subscribers _provided _createLookup __bases__selfbasesrrM/usr/lib/python3/dist-packages/mercurial/thirdparty/zope/interface/adapter.py__init__*s  zBaseAdapterRegistry.__init__cCs$||jd<t||_||dSNr)__dict__rchangedrrrr! _setBasesYs  zBaseAdapterRegistry._setBasescCs |jdSr#)r$rrrr!^ zBaseAdapterRegistry.cCs ||Sr)r&rrrr!r(_r)cCs.|||_|jD] }t|j||j|<q dSr) LookupClass _v_lookup _delegatedgetattrr$)rnamerrr!rbs  z!BaseAdapterRegistry._createLookupcCs|jd7_|j|dSNr) _generationr+r%roriginally_changedrrr!r%gszBaseAdapterRegistry.changedc Cs t|ts td|dur|||||dSttt|}t|}t|}|j }t||kr:| it||ks/||}||f}|D]} | | } | durVi} | || <| }qE| ||urbdS|||<|j |dd} | |j |<| dkr~|j |||dS)Nname is not a stringrr) isinstancer ValueError unregistertuplemap_convert_None_to_Interfacer lenrappendgetrr+ add_extendorr%) rrequiredprovidedr.valueorderbyorder componentskeykdnrrr!registerks8        zBaseAdapterRegistry.registerc Csvttt|}t|}t|}|j}t||krdS||}||f}|D]}||} | dur3dS| }q%||Sr)r7r8r9r r:rr<) rr>r?r.rArBrCrDrErFrrr! registereds    zBaseAdapterRegistry.registeredNcCs4ttt|}t|}|j}|t|krdS||}||f}g} |D]} || } | dur1dS| || f| }q#||} | durFdS|durP| |urPdS||=|sxt| D]\} } | | } | ren| | =qY|rx|dsx|d=|rx|dro|j|d}|dkr|j|=|j |n||j|<| |dS)NFrr) r7r8r9r:rr<r;reversedrr+remove_extendorr%)rr>r?r.r@rArBrCrDlookupsrErFoldcomprGrrr!r6sF       zBaseAdapterRegistry.unregisterc Csttt|}t}t|}|j}t||kr!|it||ks||}||f}|D]} || } | dur=i} | || <| }q,||d|f||<|durg|j|dd} | |j|<| dkrg|j || |dS)Nrrr) r7r8r9_BLANKr:rr;r<rr+r=r%) rr>r?r@r.rArBrCrDrErFrGrrr! subscribes,       zBaseAdapterRegistry.subscribecs^ttt|}t|}|j}|t|krdS||}||f}g}|D]} || } | dur1dS||| f| }q#|t} | sDdSdurKd} n tfdd| D} | | kr\dS| rc| |t<n&|t=t|D]\} } | | } | rvn| | =qj|r|ds|d=|r|dr|dur|j |t| t| }|dkr|j |=|j || |dS)Nrcsg|]}|ur|qSrr).0vr@rr! sz3BaseAdapterRegistry.unsubscribe..rJr) r7r8r9r:rr<r;rPrKrr+rLr%)rr>r?r@rArBrCrDrMrErFrNnewrOrGrrTr! unsubscribesN        zBaseAdapterRegistry.unsubscribecCsGddd}|S)Nc@seZdZiZdS)z2BaseAdapterRegistry.get..XXXTwistedFakeOutN)__name__ __module__ __qualname__ selfImpliedrrrr!XXXTwistedFakeOut)sr\r)r_r\rrr!r<(szBaseAdapterRegistry.getrr)rXrYrZr,r0r"r&propertyrrr%rHrPrIr6rQrWr<rrrr!r s  / # 0  r?r.defaultrfresultrrr!rHs     zLookupBaseFallback.lookupcCsTt|ts td|||}||t}|tur"||f|||S|dur(|S|SNr3)r4r r5rhr<rirrkrrr!r^s   zLookupBaseFallback.lookup1cCs|||||Sr)r)robjectr?r.rlrrr!rkszLookupBaseFallback.queryAdapterc Csjt|ts tdt|}|||}||t}|tur%||f||}|dur3||}|dur3|S|Srn)r4r r5rrhr<rir) rr?ror.rlr>rffactoryrmrrr!rns   zLookupBaseFallback.adapter_hookcCV|j|}|duri}||j|<t|}||t}|tur)|||}|||<|Sr)rbr<r7ri_uncached_lookupAllrr>r?rfrmrrr!r~    zLookupBaseFallback.lookupAllcCrqr)rcr<r7ri_uncached_subscriptionsrsrrr!rrtz LookupBaseFallback.subscriptionsr) rXrYrZr"r%rhrPrrrrrrrrrr!r`/s    r`) LookupBasec@s4eZdZddZddZddZddZd d Zd S) VerifyingBaseFallbackcCs4t|||jjdd|_dd|jD|_dS)NrcSg|]}|jqSrr0rRrrrr!rUz1VerifyingBaseFallback.changed..)r`r% _registryr _verify_ro_verify_generationsr1rrr!r%s zVerifyingBaseFallback.changedcCs(dd|jD|jkr|ddSdS)NcSrxrryrzrrr!rUr|z1VerifyingBaseFallback._verify..)r~rr%r'rrr!_verifys zVerifyingBaseFallback._verifycC|t|||Sr)rr`rh)rr?r.rrr!rhzVerifyingBaseFallback._getcachecCrr)rr`rrr>r?rrr!rrzVerifyingBaseFallback.lookupAllcCrr)rr`rrrrr!rrz#VerifyingBaseFallback.subscriptionsN)rXrYrZr%rrhrrrrrr!rws  rw) VerifyingBasecseZdZfddZdfdd ZddZdd Zd d Zd d Ze fddZ e dfddZ ddZ ddZ ddZddZZS)AdapterLookupBasecs&||_i|_|tt|dSr)r} _requiredinit_extendorssuperrr")rregistry __class__rr!r"szAdapterLookupBase.__init__NcsFtt|d|jD]}|}|dur||q |jdSr)rrr%rkeysrWrd)rrer{rrr!r%s zAdapterLookupBase.changedcCs"i|_|jjD]}||qdSr) _extendorsr}rr=)rprrr!rs  z AdapterLookupBase.init_extendorscsP|j}jD]}||d}fdd|Dgfdd|D||<qdS)Nrcsg|] }|r|qSr isOrExtendsrRer?rr!rUz2AdapterLookupBase.add_extendor..csg|] }|s|qSrrrrrr!rUrr__iro__r<)rr?ri extendorsrrr!r=s  zAdapterLookupBase.add_extendorcs4|j}jD]}fdd||dD||<qdS)Ncsg|]}|kr|qSrrrrrr!rUsz5AdapterLookupBase.remove_extendor..rr)rr?rrrrr!rLs  z!AdapterLookupBase.remove_extendorcGs6|j}|D]}|}||vr||d||<qdSr/)rweakrefrQ)rr>_refsr{refrrr! _subscribes zAdapterLookupBase._subscribec Cs~t|}d}t|}|jjD])}|j}|t|krq|jj|}|s$q||} t| |||d|}|dur7nq|j ||SNr) r7r:r}rrr+rr<_lookupr) rr>r?r.rmrArrBrrCrrr!rjs&    z"AdapterLookupBase._uncached_lookupcCs8|tt|||}|dur|S||}|dur|S|Sr)rr8r)robjectsr?r.rlrprmrrr!r%sz#AdapterLookupBase.queryMultiAdapterc Cs~t|}t|}i}t|jjD]#}|j}|t|krq|jj|}|s&q||}t ||||d|q|j |t| Sr) r7r:rKr}rrr+rr< _lookupAllritems) rr>r?rArmrrBrrCrrr!rr0s   z%AdapterLookupBase._uncached_lookupAllcCsdd|||DS)NcSsg|]}|dqS)rr)rRrgrrr!rUCsz+AdapterLookupBase.names..)rrrrr!rBszAdapterLookupBase.namesc Cst|}t|}g}t|jjD],}|j}|t|krq|dur$|f}n |jj|}|dur0qt ||||t |d|q|j ||Sr) r7r:rKr}rrr+rr<_subscriptionsrPr)rr>r?rArmrrBrrrr!ruEs"  z)AdapterLookupBase._uncached_subscriptionscCs`|tt||}|durd}|D]}||q|Sg}|D]}||}|dur-||q|S)Nr)rr8rr;)rrr?rrm subscription subscriberrrr!r\s  zAdapterLookupBase.subscribersr)rXrYrZr"r%rr=rLrrPrjrrrrrur __classcell__rrrr!rs    rc@ eZdZdS) AdapterLookupNrXrYrZrrrr!rjrcsJeZdZeZd fdd ZddZddZfdd Zfd d Z Z S) AdapterRegistryrcst|_tt||dSr)rWeakKeyDictionary_v_subregistriesrrr"rrrr!r"rs zAdapterRegistry.__init__cCsd|j|<dSr/rrr{rrr!_addSubregistryyszAdapterRegistry._addSubregistrycCs||jvr |j|=dSdSrrrrrr!_removeSubregistry|s  z"AdapterRegistry._removeSubregistrycsZ|jdd}|D] }||vr||q |D] }||vr"||qtt||dS)Nrr)r$r<rrrrr&)rr rNr{rrr!r&s  zAdapterRegistry._setBasescs.tt|||jD]}||q dSr)rrr%rr)rr2subrrr!r%s zAdapterRegistry.changedr^) rXrYrZrr*r"rrr&r%rrrrr!rms  rc@r)VerifyingAdapterLookupNrrrrr!rrrc@seZdZeZdS)VerifyingAdapterRegistryN)rXrYrZrr*rrrr!rsrcCs|durtS|Srr)xrrr!r9sr9c Cs||kr(||jD]}||}|r%t|||||d|}|dur%|Sq dS|D]} || }|r@||}|dur@|Sq*dSr/)__sro__r<r) rCspecsr?r.rlspeccompsr{ifacerrr!rs"    rc Csn||kr"t||jD]}||}|rt|||||d|q dSt|D]}||}|r4||q&dSr/)rKrr<rupdate) rCrr?rmrrrrrrrr!rs    rc Cs~||kr#t||jD]}||}|r t||||||d|q dSt|D]} || }|r<||}|r<||q'dSr/)rKrr<rextend) rCrr?r.rmrrrrrrrr!rs     r)#__doc__ __future__rrr rrrr interfacesr _compatr r rPror rir` LookupBasePy_zope_interface_coptimizationsrv ImportErrorrwVerifyingBasePyrrrrrrr9rrrrrrr!sR        l  $$