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

2001-12-06 Thread Brad Clements

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,[EMAIL PROTECTED]   (315)268-1000
http://www.murkworks.com  (315)268-9812 Fax
netmeeting: ils://ils.murkworks.com   AOL-IM: BKClements


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



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

2001-12-06 Thread Romain Slootmaekers



indeed. in 
lib/python/AccessControl/ZopeGuards.py

the guarded_reduce isn't there

those who are are:
['cmp', 'round', 'AttributeError', 'random', 'str', 'range',
'ArithmeticError', 'whrandom', 'unichr', 'list', 'FloatingPointError',
'getattr', 'hasattr', 'setattr', 'IndexError', 'TypeError', 'delattr',
'AssertionError', 'divmod', 'ord', 'ZeroDivisionError', '__import__',
'callable', 'len', 'repr', 'max', 'tuple', 'StandardError', 'string',
'hash', 'isinstance', 'Exception', 'map', 'math', 'oct', 'OverflowError',
'IOError', 'test', 'filter', 'abs', 'chr', 'NameError', 'long', 'hex',
'complex', 'EOFError', 'min', 'reorder', 'OSError', 'same_type',
'RuntimeError', 'LookupError', 'apply', 'EnvironmentError', 'unicode',
'ValueError', 'issubclass', 'ImportError', 'None', 'KeyError', 'float',
'SyntaxError', 'pow', 'int', 'sequence', 'DateTime']

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

Sloot.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



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

2001-12-06 Thread Romain Slootmaekers



On Thu, 6 Dec 2001, Brad Clements wrote:

> On 6 Dec 2001 at 16:12, Romain Slootmaekers wrote:
> 
> > > reduce(operator.add,[0,1,2,3,4])
> > > 
> > try "_.reduce()"
> 
> This is in a Python Script, I'm not using the DTML namespace.
> 
> Note that map() and filter() work without a problem, so why not reduce() ?
> 
> > this shkould be clear enough as a message.
> > zope can't find the reduce function.
> 
> right, but it can find the other built-in functions okay.
> 

try in your script:
print filter
return printed

and after that works 

try :
print reduce
return printed

someone probably just forgot to implement the guarded_reduce method




___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



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

2001-12-06 Thread Brad Clements

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

> > reduce(operator.add,[0,1,2,3,4])
> > 
> try "_.reduce()"

This is in a Python Script, I'm not using the DTML namespace.

Note that map() and filter() work without a problem, so why not reduce() ?

> this shkould be clear enough as a message.
> zope can't find the reduce function.

right, but it can find the other built-in functions okay.


Brad Clements,[EMAIL PROTECTED]   (315)268-1000
http://www.murkworks.com  (315)268-9812 Fax
netmeeting: ils://ils.murkworks.com   AOL-IM: BKClements


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



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

2001-12-06 Thread Romain Slootmaekers



On Thu, 6 Dec 2001, Brad Clements wrote:

> In Zope 2.4.3 binary on Linux
> 
> import operator
> 
> reduce(operator.add,[0,1,2,3,4])
> 
try "_.reduce()"


> gives me Error Value: global name 'reduce' is not defined

this shkould be clear enough as a message.
zope can't find the reduce function.


> 
> Is this a faq?

probably.

have fun,

Sloot.


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )



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

2001-12-06 Thread Brad Clements

In Zope 2.4.3 binary on Linux

import operator

reduce(operator.add,[0,1,2,3,4])

gives me Error Value: global name 'reduce' is not defined

Is this a faq?


Brad Clements,[EMAIL PROTECTED]   (315)268-1000
http://www.murkworks.com  (315)268-9812 Fax
netmeeting: ils://ils.murkworks.com   AOL-IM: BKClements


___
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://lists.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope )