[Zope-dev] reduce() doesn't work in Python Scripts

Brad Clements bkc@murkworks.com
Thu, 6 Dec 2001 11:25:05 -0500


On 6 Dec 2001 at 16:57, Romain Slootmaekers wrote:

> 
> In retrospect, I should have posted only 1 message instead of 3 :)
> 

And I should have submitted a patch to the collector instead of posting here. :-(

Just not sure what is the "right" way to do this, here's my first pass:


def guarded_reduce(f,seq,**kw):
    skip_unauthorized = kw.get('skip_unauthorized')
    v = getSecurityManager().validate
    safelist = []
    if kw.has_key('init'):
        i = kw['init']
        if v(accessed=kw,name='init',value=i):
            safelist.append(i)
        elif not skip_unauthorized:
            raise Unauthorized, 'unauthorized access to init'
    for el in seq:
        if v(seq, seq, None, el):
            safelist.append(el)
        elif not skip_unauthorized:
            raise Unauthorized, 'unauthorized access to element'
        
    return reduce(f,safelist)

Brad Clements,                bkc@murkworks.com   (315)268-1000
http://www.murkworks.com                          (315)268-9812 Fax
netmeeting: ils://ils.murkworks.com               AOL-IM: BKClements