Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Dieter Maurer wrote: The "str" example shows also that it is not sensible that the adapter registry framework gives the adapter (factory) a way to determine its name ("str" has nothing where the "name" could be sticked in). True enough, I guess I'll just have to stick with my hack or Tres' currying suggestion... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Chris Withers wrote at 2006-11-28 18:09 +: >Benji York wrote: >> Chris Withers wrote: >>> I don't think it'll be a common pattern, but it doesn't feel right to >>> me that a named adapter (ie: one registered with a specific name) has >>> no way of finding out what name it has been registered with... >> >> Because the same adapter can be registered more than once, it would >> actually need to find out all the names with which it was registered. > >Really? Now this is a use case I hadn't thought of.. can you give me >some examples of where you've run into this? An example where an adapter *can* be registered several times was presented by yourself :-) The "str" adapter (factory) can be used to adapt anything to a string. You may register it several times because you may not want to adapt all interfaces with it but only those derived of several base interfaces. You may or may not use different names as you might have different types of string adaptation (e.g. different types of string presentations). The "str" example shows also that it is not sensible that the adapter registry framework gives the adapter (factory) a way to determine its name ("str" has nothing where the "name" could be sticked in). -- Dieter ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Previously Stephan Richter wrote: > On Wednesday 29 November 2006 03:37, Wichert Akkerman wrote: > > The fact that something is true in Zope 3 does not necessarily make it a > > good idea. > > But the chances are pretty high! ;-) Of course I meant to say 'Zope 2' there, which does reduce the chances. Wichert. -- Wichert Akkerman <[EMAIL PROTECTED]>It is simple to make things. http://www.wiggy.net/ It is hard to make things simple. ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
On Wednesday 29 November 2006 03:37, Wichert Akkerman wrote: > The fact that something is true in Zope 3 does not necessarily make it a > good idea. But the chances are pretty high! ;-) Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Previously Chris Withers wrote: > Really? Certainly in Zope 2, prettymuch every persistent objects needs > to be getId()'able... The fact that something is true in Zope 3 does not necessarily make it a good idea. Wichert. -- Wichert Akkerman <[EMAIL PROTECTED]>It is simple to make things. http://www.wiggy.net/ It is hard to make things simple. ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Benji York wrote: Really? Now this is a use case I hadn't thought of.. can you give me some examples of where you've run into this? I don't know that I have, but the component system doesn't preclude it so anything we come up with will have to take it into effect. I'll whisper yagni at this point in the same way someone no doubt did when deciding if named adapters should be able to discover the name they're registered with ;-) Sure, where "everything" is defined as content space objects, other objects more rarely. Really? Certainly in Zope 2, prettymuch every persistent objects needs to be getId()'able... Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
[Zope3-dev] Re: Can an adapter find out what name it was registered for?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Benji York wrote: > Chris Withers wrote: >> Benji York wrote: >>> Chris Withers wrote: I don't think it'll be a common pattern, but it doesn't feel right to me that a named adapter (ie: one registered with a specific name) has no way of finding out what name it has been registered with... >>> Because the same adapter can be registered more than once, it would >>> actually need to find out all the names with which it was registered. >> Really? Now this is a use case I hadn't thought of.. can you give me >> some examples of where you've run into this? > > I don't know that I have, but the component system doesn't preclude it > so anything we come up with will have to take it into effect. I have already used the same adapters registered under different names (including the default "empty string" name). The CA is about allowing component configuration to express policy, which sometimes means that reusing an adapter makes sense (e.g., one might override the 'bar' named adapter for a particular object, while leaving the 'foo' adapter alone; the fact that the "default" registration uses the same factory for 'foo' and 'bar' Just Works now). I would argue that having adapters which need to know their name is *very* unusual, in fact. >>> This seems somewhat analogous to a Python object being given multiple >>> names. In that case too, there is no way for the object to know what >>> it's names are. >> Hmmm, okay, but I'd counter with both Zope 2 and Zope 3 having the >> notion of an object knowing its own name. Certainly in Zope 2, >> everything has an id or .getId(). That pattern evolved for a reason ;-) > > Sure, where "everything" is defined as content space objects, other > objects more rarely. That "pattern" has actually been the source of a lot of lost hair in the past -- content itmes know their IDs, which means that renaming them involves modifying *both* the container *and* the item. There was a fishbowl proposal for Zope2 to move the ID into the acquisition wrapper, which would have removed the need for content items to know them. Tres. - -- === Tres Seaver +1 202-558-7113 [EMAIL PROTECTED] Palladion Software "Excellence by Design"http://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFbNMH+gerLs4ltQ4RAheTAJ4rQee1njxmI0t4BrNkn8ikLzNThwCfWp/b EHnI2flrrxL0d33v9oLudcg= =hm22 -END PGP SIGNATURE- ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
On Tue, Nov 28, 2006 at 06:12:19PM +, Chris Withers wrote: > Is there a python-only way to register adapters instead of in ZCML and, > if it exists, is it safe to use in conjunction with the normal zcml dances? There's always a way :) You could just do what the directive does - call the adapter() function which used to be in zope.app.component.metaconfigure but now lives in zope.component.zcml. I haven't done it but AFAICT it should work safely. It's sometimes instructive to look at how directives are implemented. Find the meta.zcml file that declares the directive, and that'll tell you what module contains the schema and handler for that directive. The handler does the work. -- Paul Winkler http://www.slinkp.com ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Chris Withers wrote: Benji York wrote: Chris Withers wrote: I don't think it'll be a common pattern, but it doesn't feel right to me that a named adapter (ie: one registered with a specific name) has no way of finding out what name it has been registered with... Because the same adapter can be registered more than once, it would actually need to find out all the names with which it was registered. Really? Now this is a use case I hadn't thought of.. can you give me some examples of where you've run into this? I don't know that I have, but the component system doesn't preclude it so anything we come up with will have to take it into effect. This seems somewhat analogous to a Python object being given multiple names. In that case too, there is no way for the object to know what it's names are. Hmmm, okay, but I'd counter with both Zope 2 and Zope 3 having the notion of an object knowing its own name. Certainly in Zope 2, everything has an id or .getId(). That pattern evolved for a reason ;-) Sure, where "everything" is defined as content space objects, other objects more rarely. -- Benji York Senior Software Engineer Zope Corporation ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
[Zope3-dev] Re: Can an adapter find out what name it was registered for?
Tres Seaver wrote: for name in ('vindaloo', 'madras', 'tiki_masala'): globals()[name] = MNA_factory_maker(name) and then in ZCML: ...but here you have to specify the same info twice and hence duplicate info and get it identical in two places, which feels icky to me. Is there a python-only way to register adapters instead of in ZCML and, if it exists, is it safe to use in conjunction with the normal zcml dances? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Benji York wrote: Chris Withers wrote: I don't think it'll be a common pattern, but it doesn't feel right to me that a named adapter (ie: one registered with a specific name) has no way of finding out what name it has been registered with... Because the same adapter can be registered more than once, it would actually need to find out all the names with which it was registered. Really? Now this is a use case I hadn't thought of.. can you give me some examples of where you've run into this? This seems somewhat analogous to a Python object being given multiple names. In that case too, there is no way for the object to know what it's names are. Hmmm, okay, but I'd counter with both Zope 2 and Zope 3 having the notion of an object knowing its own name. Certainly in Zope 2, everything has an id or .getId(). That pattern evolved for a reason ;-) cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
[Zope3-dev] Re: Can an adapter find out what name it was registered for?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Chris Withers wrote: > Stephan Richter wrote: >> On Friday 17 November 2006 03:43, Chris Withers wrote: >>> What do you suggest I do when the adapter needs to know the name it was >>> registered for? >> You can make the name part of the adapter API. > > Not sure what you mean by this? > >> However, I would suggest revising the design; I have never come across a >> scenario where I wanted the name of the adapter be known within the adapter. >> This seems to be a recipe for trouble. > > I don't think it'll be a common pattern, but it doesn't feel right to me > that a named adapter (ie: one registered with a specific name) has no > way of finding out what name it has been registered with... The classic pattern here would be to create the "guts" of your adapter as a class, and then curry the "factory" part which governs instantiation of the class. You could double-curry the factory, as well, if you wanted to avoid the class. E.g.: class MyNamedAdapter(object): def __init__(self, context, name): self.context = context self.name = name def causeBrowToSweat(self): return 'Sweating: %s' % self.name def MNA_factory_maker(name): def _curried(context, name=name): return MyNamedAdapter(context, name) return _curried for name in ('vindaloo', 'madras', 'tiki_masala'): globals()[name] = MNA_factory_maker(name) and then in ZCML: Tres. - -- === Tres Seaver +1 202-558-7113 [EMAIL PROTECTED] Palladion Software "Excellence by Design"http://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFa6jg+gerLs4ltQ4RAoSlAJwJvyp3gWfI72Pt+t2wiE5ozPFQxQCfWxwU yVagPjfHMhjbK7wfeDghjI8= =7BoL -END PGP SIGNATURE- ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
On Monday 27 November 2006 11:17, Benji York wrote: > This seems somewhat analogous to a Python object being given multiple > names. In that case too, there is no way for the object to know what > it's names are. Great analogy. I used that one before too, but did not think of it this time. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Chris Withers wrote: I don't think it'll be a common pattern, but it doesn't feel right to me that a named adapter (ie: one registered with a specific name) has no way of finding out what name it has been registered with... Because the same adapter can be registered more than once, it would actually need to find out all the names with which it was registered. This seems somewhat analogous to a Python object being given multiple names. In that case too, there is no way for the object to know what it's names are. -- Benji York Senior Software Engineer Zope Corporation ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
Stephan Richter wrote: On Friday 17 November 2006 03:43, Chris Withers wrote: What do you suggest I do when the adapter needs to know the name it was registered for? You can make the name part of the adapter API. Not sure what you mean by this? However, I would suggest revising the design; I have never come across a scenario where I wanted the name of the adapter be known within the adapter. This seems to be a recipe for trouble. I don't think it'll be a common pattern, but it doesn't feel right to me that a named adapter (ie: one registered with a specific name) has no way of finding out what name it has been registered with... cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
On Friday 17 November 2006 03:43, Chris Withers wrote: > What do you suggest I do when the adapter needs to know the name it was > registered for? You can make the name part of the adapter API. However, I would suggest revising the design; I have never come across a scenario where I wanted the name of the adapter be known within the adapter. This seems to be a recipe for trouble. Regards, Stephan -- Stephan Richter CBU Physics & Chemistry (B.S.) / Tufts Physics (Ph.D. student) Web2k - Web Software Design, Development and Training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
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 ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?
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? cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
[Zope3-dev] Re: Can an adapter find out what name it was registered for?
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Philipp von Weitershausen wrote: > Chris Withers wrote: >> Can a named adapter find out the name it was registered with during the >> adaptation process? > > Nope. But you can create the adapter factories in such a way that they know that name, via a little "curry powder": >>> map = {} >>> for name in 'foo', 'bar', 'baz': ... def whoami(name=name): ... return name ... map[name] = whoami ... >>> map['foo']() 'foo' >>> map['bar']() 'bar' Tres. - -- === Tres Seaver +1 202-558-7113 [EMAIL PROTECTED] Palladion Software "Excellence by Design"http://palladion.com -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.2.2 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFFXRsj+gerLs4ltQ4RAtHSAKC85EasxcDQpCTDaY7AGT2lHpP7egCeJ12k qaUxJBox8tQ1Pz5LWw99IHk= =zgNn -END PGP SIGNATURE- ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com
[Zope3-dev] Re: Can an adapter find out what name it was registered for?
Chris Withers wrote: Can a named adapter find out the name it was registered with during the adaptation process? Nope. -- http://worldcookery.com -- Professional Zope documentation and training ___ Zope3-dev mailing list Zope3-dev@zope.org Unsub: http://mail.zope.org/mailman/options/zope3-dev/archive%40mail-archive.com