o ]Lb,Z@sdZddlmZddlmZzddlmZWn ey#ddZYnwdd lm Z dd lm Z dd lm Z dd lm Z dd lm Z ddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZGdddeZddZ GdddeZ!ee Gd d!d!eZ"d"d#Z#d$d%Z$d&d'Z%d(d)Z&eeGd*d+d+eZ'ee Gd,d-d-eZ(eeGd.d/d/e(Z)ee Gd0d1d1e(Z*d2S)3zBasic components support )absolute_import) defaultdict)notifycOsdSN)argkwrrN/usr/lib/python3/dist-packages/mercurial/thirdparty/zope/interface/registry.pyrsr)ISpecification)ComponentLookupError)IAdapterRegistration) IComponents)IHandlerRegistration) ISubscriptionAdapterRegistration)IUtilityRegistration) Registered) Unregistered) Interface) implementedBy) implementer)implementer_only) providedBy)AdapterRegistry) CLASS_TYPES) STRING_TYPESc@s,eZdZddZddZddZddZd S) _UnhashableComponentCountercCsdd|D|_dS)NcSsg|]}|qSrr).0itemrrr 3sz8_UnhashableComponentCounter.__init__..)items_data)self otherdictrrr __init__1sz$_UnhashableComponentCounter.__init__cCs$|jD] \}}||kr|SqdSNr)r")r#key componentcountrrr __getitem__5s z'_UnhashableComponentCounter.__getitem__cCsHt|jD]\}}|d|kr||f|j|<dSq|j||fdSr&) enumerater"append)r#r(r)idatarrr __setitem__;s  z'_UnhashableComponentCounter.__setitem__cCs6t|jD]\}}|d|kr|j|=dSqt|r&)r+r"KeyError)r#r(r-r.rrr __delitem__Bs  z'_UnhashableComponentCounter.__delitem__N)__name__ __module__ __qualname__r%r*r/r1rrrr r.s  rcCsttSr)rintrrrr _defaultdict_intIr6c@sDeZdZddZddZddZddZd d Zd d Zd dZ dS)_UtilityRegistrationscCs"tt|_||_||_|dSr)rr6_cache _utilities_utility_registrations%_UtilityRegistrations__populate_cache)r# utilitiesutility_registrationsrrr r%Ns  z_UtilityRegistrations.__init__cCs4t|jD]\\}}}|d}|||qdSr&)iterr;r!$_UtilityRegistrations__cache_utility)r#p_r.r(rrr __populate_cacheVsz&_UtilityRegistrations.__populate_cachecCsZz|j||d7<WdSty,t|j|}|j|<||d7<YdSw)Nr )r9 TypeErrorr)r#providedr(provrrr __cache_utility[s  z%_UtilityRegistrations.__cache_utilitycCs@|j|}||}|d8}|dkr||=|dkS|||<|dkS)Nr r)r9)r#rEr(r)rrr __uncache_utilityds z'_UtilityRegistrations.__uncache_utilitycCs*z |j||dkWStyYdSw)NrF)r9rD)r#rEr(rrr _is_utility_subscribedss  z,_UtilityRegistrations._is_utility_subscribedcCsV|||}|||f|j||f<|jd||||s#|jd|||||dSNr)rIr;r:register subscriber@)r#rEnamer(infofactory subscribedrrr registerUtilityzs z%_UtilityRegistrations.registerUtilitycCsD|j||f=|jd|||||}|s |jd||dSdSrJ)r;r: unregister&_UtilityRegistrations__uncache_utility unsubscribe)r#rErMr(rPrrr unregisterUtilitys  z'_UtilityRegistrations.unregisterUtilityN) r2r3r4r%r<r@rSrIrQrUrrrr r8Ls  r8csheZdZdZdFddZddZfdd Zd d Zd d Ze ddZ ddZ ddZ e ddddZ  dGddZ  dHddZddZdIddZdJd d!Zd"d#Zd$d%Z  dKd&d'Z  dLd(d)Zd*d+ZdId,d-ZdJd.d/Z  dId0d1ZdJd2d3Zd4d5Z   dKd6d7Zd8d9Z  dLd:d;Zdd?Z!d@dAZ"dNdBdCZ#dDdEZ$Z%S)O ComponentsNrcCs8t|tsJ||_||t||_d|_dSr) isinstancerr2_init_registries_init_registrationstuple __bases___v_utility_registrations_cache)r#rMbasesrrr r%s   zComponents.__init__cCsd|jj|jfS)Nz<%s %s>) __class__r2r#rrr __repr__zComponents.__repr__cs<tt|}dd|dD}t|}||d<t|S)NcSs i|] \}}|ds||qS)_v_) startswith)rkvrrr s  z)Components.__reduce__..r)superrV __reduce__r!listr[)r# reductionfiltered_stater_rr ris zComponents.__reduce__cCst|_t|_dSr)radaptersr=r`rrr rYs zComponents._init_registriescCsi|_i|_g|_g|_dSr)r;_adapter_registrations_subscription_registrations_handler_registrationsr`rrr rZs zComponents._init_registrationscCs>|j}|dus|j|jus|j|jurt|j|j}|_|Sr)r]r:r=r;r8)r#cacherrr _utility_registrations_caches   z'Components._utility_registrations_cachecCs|jddS)Nr\r)__dict__getr`rrr _getBasesszComponents._getBasescCs>tdd|D|j_tdd|D|j_t||jd<dS)NcSg|]}|jqSr)rnrbaserrr r z(Components._setBases..cSrwr)r=rxrrr r rzr\)r[rnr\r=rtr#r^rrr _setBasess  zComponents._setBasescCs|Sr)rvr`rrr szComponents.cCs ||Sr)r|r{rrr r}s Tc Cs|r |rtd|}|durt|}|dkrt|}|j||f}|dur<|dd||fkr3dS||d|||j||||||rWtt t ||||||dSdS)N$Can't specify factory and component.rWrr) rD_getUtilityProvided_getNamer;rurUrsrQrrUtilityRegistration)r#r(rErMrNeventrOregrrr rQs.   zComponents.registerUtilitycCs|r |rtd|}|dur|durtdt|}|j||f}|dus1|dur3||dkr3dS|dur;|d}|j|||ttt||||g|ddRdS)Nr~z3Must specify one of component, factory and providedrFr T) rDrr;rursrUrrr)r#r(rErMrOoldrrr rUs* zComponents.unregisterUtilityccs8t|jD]\\}}}t|||g|RVqdSr)r?r;r!r)r#rErMr.rrr registeredUtilitiess  zComponents.registeredUtilitiescCs|jd|||SrJ)r=lookup)r#rErMdefaultrrr queryUtilityrbzComponents.queryUtilitycCs&|jd||}|durt|||SrJ)r=rr )r#rErMutilityrrr getUtilitys zComponents.getUtilityccs(|jd|D] \}}||fVqdSrJ)r= lookupAll)r# interfacerMrrrr getUtilitiesFor$s zComponents.getUtilitiesForcCs|jd|SrJ)r= subscriptions)r#rrrr getAllUtilitiesRegisteredFor(z'Components.getAllUtilitiesRegisteredForc Csv|durt|}t||}|dkrt|}||f|j|||f<|j|||||r9ttt||||||dSdSNrW) _getAdapterProvided_getAdapterRequiredrrornrKrrAdapterRegistrationr#rOrequiredrErMrNrrrr registerAdapter+s   zComponents.registerAdaptercCs|dur|dur tdt|}|dur|durtdt||}|j|||f}|dus8|dur:||dkr:dS|j|||f=|j|||ttt ||||g|RdS)N(Must specify one of factory and provided(Must specify one of factory and requiredrFT) rDrrrorurnrRrrr)r#rOrrErMrrrr unregisterAdapter=s&   zComponents.unregisterAdapterccs<t|jD]\\}}}\}}t||||||VqdSr)r?ror!r)r#rrErMr(rNrrr registeredAdaptersXs  zComponents.registeredAdapterscC|j||||Sr)rn queryAdapter)r#objectrrMrrrr r^rbzComponents.queryAdaptercC(|j|||}|durt||||Sr)rnrr )r#rrrMadapterrrr getAdaptera zComponents.getAdaptercCrr)rnqueryMultiAdapter)r#objectsrrMrrrr rgszComponents.queryMultiAdaptercCrr)rnrr )r#rrrMrrrr getMultiAdapterlrzComponents.getMultiAdapterccsB|jttt||D]\}}||}|dur||fVq dSr)rnrrjmapr)r#rrErMrOrrrr getAdaptersrs   zComponents.getAdaptersc Csr|rtd|durt|}t||}|j|||||f|j||||r7ttt ||||||dSdS)N'Named subscribers are not yet supported) rDrrrpr,rnrLrrSubscriptionRegistrationrrrr registerSubscriptionAdapterzs     z&Components.registerSubscriptionAdaptercc$|jD] }t|g|RVqdSr)rprr#r.rrr registeredSubscriptionAdapters z)Components.registeredSubscriptionAdaptersc s|rtddurdurtdtdur"dur"tdtdur7fdd|jD}n fdd|jD}t|t|jkrNdS||jdd<|jttt ||dd S) Nrrrcs4g|]\}}}}}|kr|ks|||||fqSrrrrrAnfr-)rErrr r s   z.cs<g|]\}}}}}|kr|kr|ks|||||fqSrrrrOrErrr r s   FrWT) rDrrrplenrnrTrrr)r#rOrrErMnewrrr unregisterSubscriptionAdapters4   z(Components.unregisterSubscriptionAdaptercCs|j||Srrn subscribers)r#rrErrr rrzComponents.subscriberscCs^|rtdt||}|j||||f|j|d||r-ttt|||||dSdS)Nz$Named handlers are not yet supported) rDrrqr,rnrLrrHandlerRegistration)r#rOrrMrNrrrr registerHandlers   zComponents.registerHandlerccrr)rqrrrrr registeredHandlersrzComponents.registeredHandlerscs|rtddurdurtdtdur&fdd|jD}n fdd|jD}t|t|jkr.cs0g|]\}}}}|kr|ks||||fqSrrrrOrrr r s   FrWT) rDrrqrrnrTrrr)r#rOrrMrrrr unregisterHandlers(   zComponents.unregisterHandlercGs|j|ddSrr)r#rrrr handlerbzComponents.handle)rWr)NNrWrWTN)NNrWN)rWN)rW)NNrWrWT)NNNrW)NrWrWT)NNrW)&r2r3r4r]r%rarirYrZpropertyrsrvr|r\rQrUrrrrrrrrrrrrrrrrrrrrr __classcell__rrrmr rVsp                *  "rVcCsz|jWStyYdSwr)__component_name__AttributeError)r(rrr rs  rcC(tt|}t|dkr|dStd)Nr rzWThe utility doesn't provide a single interface and no provided interface was specified.)rjrrrD)r(rErrr r  rcCr)Nr rzaThe adapter factory doesn't implement a single interface and no provided interface was specified.)rjrrrD)rOrErrr rrrcCs|durz|j}Wntytdwt|rtdg}|D]!}|dur+t}nt|s>t|tr:t|}ntd| |q"t |S)NzoThe adapter factory doesn't have a __component_adapts__ attribute and no required specifications were specifiedzLthe required argument should be a list of interfaces, not a single interfacez8Required specification must be a specification or class.) __component_adapts__rrDr rrrXrrr,r[)rOrresultrrrr rs(       rc@sVeZdZdddZddZddZdd Zd d Zd d ZddZ ddZ ddZ dS)rNcC,||||||f\|_|_|_|_|_|_dSr)registryrErMr(rNrO)r#rrErMr(docrOrrr r%/szUtilityRegistration.__init__c Cs<d|jj|jt|jdd|jt|jdt|j|j|j fS)Nz%s(%r, %s, %r, %s, %r, %r)r2) r_r2rgetattrrErMr(reprrOrNr`rrr ra4szUtilityRegistration.__repr__cCt|Sridr`rrr __hash__=r7zUtilityRegistration.__hash__cCt|t|kSrrr#otherrrr __eq__@zUtilityRegistration.__eq__cCt|t|kSrrrrrr __ne__CrzUtilityRegistration.__ne__cCt|t|kSrrrrrr __lt__FrzUtilityRegistration.__lt__cCt|t|kSrrrrrr __le__IrzUtilityRegistration.__le__cCt|t|kSrrrrrr __gt__LrzUtilityRegistration.__gt__cCt|t|kSrrrrrr __ge__OrzUtilityRegistration.__ge__r r2r3r4r%rarrrrrrrrrrr r,s   rc@sTeZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ dS)rcCrr)rrrErMrOrN)r#rrrErMr(rrrr r%Us zAdapterRegistration.__init__c CsTd|jj|jdddd|jDdt|jdd|jt|jdt |j|j fS)Nz%s(%r, %s, %s, %r, %s, %r)[, cSrwrr2rrrrr r ^z0AdapterRegistration.__repr__..]r2) r_r2rjoinrrrErMrOrrNr`rrr raZszAdapterRegistration.__repr__cCrrrr`rrr rcr7zAdapterRegistration.__hash__cCrrrrrrr rfrzAdapterRegistration.__eq__cCrrrrrrr rirzAdapterRegistration.__ne__cCrrrrrrr rlrzAdapterRegistration.__lt__cCrrrrrrr rorzAdapterRegistration.__le__cCrrrrrrr rrrzAdapterRegistration.__gt__cCrrrrrrr rurzAdapterRegistration.__ge__Nrrrrr rRs  rc@s eZdZdS)rN)r2r3r4rrrr rxsrc@s,eZdZddZeddZdZddZdS)rcCs&|||||f\|_|_|_|_|_dSr)rrrMhandlerrN)r#rrrMrrrrr r%s zHandlerRegistration.__init__cCs|jSr)rr`rrr rOszHandlerRegistration.factoryNc CsHd|jj|jdddd|jDd|jt|jdt|j|j fS)Nz%s(%r, %s, %r, %s, %r)rrcSrwrrrrrr r rz0HandlerRegistration.__repr__..rr2) r_r2rrrrMrrOrrNr`rrr raszHandlerRegistration.__repr__)r2r3r4r%rrOrErarrrr r}s   rN)+__doc__ __future__r collectionsrrr ImportError interfacesr r rrrrrrrrr declarationsrrrrrr_compatrrrrr6r8rVrrrrrrrrrrrr sX                     Cl%%