Re: [Zope3-dev] Re: Can an adapter find out what name it was registered for?

2006-11-27 Thread Chris Withers

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?

2006-11-27 Thread Benji York

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?

2006-11-27 Thread Stephan Richter
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



[Zope3-dev] Re: Can an adapter find out what name it was registered for?

2006-11-27 Thread Tres Seaver
-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:

   adapter for=.interfaces.IChicken
provides=.interfaces.ICurry
name=vindaloo
factory=.adapters.vindaloo /


Tres.
- --
===
Tres Seaver  +1 202-558-7113  [EMAIL PROTECTED]
Palladion Software   Excellence by Designhttp://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