[Zope-dev] ZPatterns bug: Link to parent providers - includes patch

Steve Alexander steve@cat-box.net
Sun, 17 Sep 2000 18:54:23 +0100


This is a multi-part message in MIME format.
--------------B91DCCFEBE4E48892C030815
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

ZPatterns 0-4-2a2

The attribute excludePIs of LinkToParentProviders can be one of three
types:

It starts off as an empty tuple. When you choose to exclude one or more
providers from the parent, it becomes a list. If you choose to exclude
no providers from the parent, it becomes a string.

When it is a string, the because it has been changed from the default
state, but there are no exclusions, the second line of the method
_getProviders fails, as it is trying to evaluate string in string.
(Providers.py, line 299.)

An easy solution is to change the line from this:

  return filter(lambda x,exclude=self.excludePIs: x.id not in exclude,
r)

to this:

  return filter(lambda x,exclude=list(self.excludePIs):
                x.id not in exclude, r)


For a negligible bit of extra efficiency in the case where the link to
parent providers' properties haven't been altered, change line 295, from
this:

    excludePIs=()

to this:

    excludePIs=[]


This seems like more of a Zope implementation fault: surely a multiple
selection property should always be set to a list, even when empty?

Patch attached.

--
Steve Alexander
Software Engineer
Cat-Box limited
http://www.cat-box.net
--------------B91DCCFEBE4E48892C030815
Content-Type: text/plain; charset=us-ascii;
 name="patch.txt"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="patch.txt"

*** Providers.py.orig
--- Providers.py
***************
*** 292,302 ****
      meta_type='Link to parent Data Plug-ins'
      __plugin_kind__ = 'Data Plug-in'
  
!     excludePIs=()
      
      def _getProviders(self):
          r=getattr(self.aq_inner.aq_parent.aq_parent,'__allProviders__',())
!         return filter(lambda x,exclude=self.excludePIs: x.id not in exclude, r)
  
      def parentPIids(self):
          r=getattr(self.aq_inner.aq_parent.aq_parent,'__allProviders__',())
--- 292,303 ----
      meta_type='Link to parent Data Plug-ins'
      __plugin_kind__ = 'Data Plug-in'
  
!     excludePIs=[]
      
      def _getProviders(self):
          r=getattr(self.aq_inner.aq_parent.aq_parent,'__allProviders__',())
!         return filter(lambda x,exclude=list(self.excludePIs):
!                       x.id not in exclude, r)
  
      def parentPIids(self):
          r=getattr(self.aq_inner.aq_parent.aq_parent,'__allProviders__',())

--------------B91DCCFEBE4E48892C030815--