Ignore:
Timestamp:
Nov 11, 2010 10:29:06 AM (13 years ago)
Author:
mylan
Message:

#228: remake filters to generators

File:
1 edited

Legend:

Unmodified
Added
Removed
  • quintagroup.plonegooglesitemaps/branches/blacklist/quintagroup/plonegooglesitemaps/filters.py

    r2979 r2996  
     1from itertools import ifilter 
    12from zope.interface import implements 
    23from zope.component import queryMultiAdapter 
    34from quintagroup.plonegooglesitemaps.interfaces import IBlackoutFilter 
     5 
    46 
    57class IdBlackoutFilter(object): 
     
    1416    def filterOut(self, fdata, fargs): 
    1517        """Filter-out fdata list by id in fargs.""" 
    16         for b in fdata: 
    17             if (b.getId or b.id) != fargs: 
    18                 yield b 
     18        return ifilter(lambda b,fa=fargs:(b.getId or b.id) != fargs, 
     19                       fdata) 
    1920 
    2021 
     
    3031    def filterOut(self, fdata, fargs): 
    3132        """Filter-out fdata list by path in fargs.""" 
    32         if not (fargs.startswith("/") or fargs.startswith("./")): 
    33             for b in fdata: 
    34                 yield b 
    35              
    3633        if fargs.startswith("/"): 
    3734            # absolute path filter 
     
    3936                         name=u"plone_portal_state").portal().getId() 
    4037            test_path = '/' + portal_id + fargs 
    41         else: 
     38        elif fargs.startswith("./"): 
    4239            # relative path filter 
    4340            container_path = '/'.join(self.context.getPhysicalPath()[:-1]) 
    4441            test_path = container_path + fargs[1:] 
     42        else: 
     43            # unrecognized starting point 
     44            return fdata 
    4545 
    46         for b in fdata: 
    47             if b.getPath() != test_path: 
    48                 yield b  
    49  
     46        return ifilter(lambda b,tp=test_path: b.getPath() != tp, 
     47                       fdata) 
Note: See TracChangeset for help on using the changeset viewer.