[Zope3-dev] Re: Can an adapter find out what name it was
registered for?
Philipp von Weitershausen
philipp at weitershausen.de
Fri Nov 17 07:58:59 EST 2006
Chris Withers wrote:
> Philipp von Weitershausen wrote:
>> Chris Withers wrote:
>>> Can a named adapter find out the name it was registered with during
>>> the adaptation process?
>>
>> Nope.
>
> I can see why it's that way, but it seems a shame and maybe even an
> oversight :-/
>
> What do you suggest I do when the adapter needs to know the name it was
> registered for?
If you really really want the adapter to be aware of its name, you could
walk thru the adapter registrations of the component registry until you
find one that refers to the adapter, e.g. (pseudoish code):
registry = zope.component.getSiteManager()
for registration in registry.registeredAdapters():
if registration.factory is YourAdapterClass:
return registration.name
HTH
--
http://worldcookery.com -- Professional Zope documentation and training
More information about the Zope3-dev
mailing list