divmod-users team mailing list archive
-
divmod-users team
-
Mailing list archive
-
Message #00019
Re: [Axiom] Why does Empowered.__conform__ need a store?
Right, I knew powerupsFor with that interface didn't make sense, but forgot
about __conform__ being called on the pup. Thanks!
On Feb 14, 2013 2:05 AM, "Tristan Seligmann" <mithrandi@xxxxxxxxxxxxx>
wrote:
> On Sat, Feb 9, 2013 at 1:24 PM, Laurens Van Houtven <_@xxxxxx> wrote:
> >
> > Why does powerupsFor not have a special case for IPowerupIndirector? is
> > empowered.powerupsFor(IPowerupIndirector) a valid thing to do? What does
> > that *mean*?
>
> powerupsFor(IPowerupIndirector) is a senseless thing to do, since you
> cannot install a powerup for IPowerupIndirector (powerUp explicitly
> disallows this since it won't do anything sensible).
>
> When you install a powerup (call it pup) on someItem for
> ISomeInterface, normally when you retrieve powerups (and the base
> operation for doing so is powerupsFor) for ISomeInterface, the object
> pup will be returned as one of the powerups. However, if pup can be
> adapted to IPowerupIndirector, then the return value of
> IPowerupIndirector(pup).indirect(ISomeInterface) is returned instead
> of pup. This is why __conform__ has the special-case it does; if pup
> is just a regular powerup, pup.__conform__ will be called when Axiom
> invokes IPowerupIndirector(pup), so we need to avoid trying to do a
> powerup query for IPowerupIndirector.
>
> The only implementation of IPowerupIndirector in Axiom itself is
> axiom.substore.SubStore; the implementation looks like this:
>
> def indirect(self, interface):
> """
> Like __conform__, I adapt my store to whatever interface I am
> asked to
> produce a powerup for. This allows for app stores to be installed
> as
> powerups for their site stores directly, rather than having an
> additional item type for each interface that we might wish to
> adapt to.
> """
> return interface(self)
>
> Hopefully the docstring makes it clear how this is supposed to be used.
>
> > I'm considering replacing the implementation of __conform__ with:
> >
> > try:
> > return self.powerupsFor(interface).next()
> > except AttributeError: # self.store == None, self.store.query ->
> > AttributeError
> > return None
> >
> > ... modulo the IPowerupIndirector thing, which may have to move to
> > powerupsFor or may have to be included in that definition.
>
> This code seems almost the same as the existing code, except you've
> removed the special cases for IPowerupIndirector and
> aggregateInterfaces, and no longer handle the case where there are no
> powerups for the given interface, so I'm not quite sure what you're
> trying to accomplish with it.
> --
> mithrandi, i Ainil en-Balandor, a faer Ambar
>
Follow ups
References