[Zope-CMF] addActionProvider
Tres Seaver
tseaver@zope.com
27 Aug 2002 10:17:00 -0400
On Tue, 2002-08-27 at 04:51, Thomas Olsen wrote:
> On Tuesday August 27 2002 10:24, Thomas Olsen wrote:
> > def addActionProvider( self, provider_name ):
> > """ add the name of a new action provider """
> > if hasattr( self, provider_name ) \
> > and not provider_name in self.action_providers:
> > p_old = self.action_providers
> > p_new = p_old.append(provider_name)
> > self.action_providers = p_new
>
> Oops - this made me loose all my action providers.
> This seems to work a bit better:
>
> def addActionProvider( self, provider_name ):
> """ add the name of a new action provider """
> ap = self.action_providers
> if type(ap) is not type([]) and type(ap) is not type(()):
> ap = []
> if hasattr( self, provider_name ) \
> and not provider_name in ap:
> ap.append(provider_name)
> self.action_providers = ap
We *really* want self.action_proviers to be a tuple, not a list, to
avoid issues with mutable attributes shared between the class and the
instance. Some tools created before 1.3 did have lists; here is how I
would accomodate these tools:
def addActionProvider( self, provider_name ):
""" add the name of a new action provider """
ap = self.action_providers
if type(ap) is not type([]) and type(ap) is not type(()):
ap = []
ap = list(ap)[:] # Get a totally fresh copy
if hasattr( self, provider_name ) \
and not provider_name in ap:
ap.append(provider_name)
self.action_providers = tuple(ap)
BTW, I think Gitte Wang reported the same problem to the collector:
http://collector.zope.org/CMF/42
Tres.
--
===============================================================
Tres Seaver tseaver@zope.com
Zope Corporation "Zope Dealers" http://www.zope.com