[ZPT] CVS: Packages/ZTUtils - Zope.py:1.2.2.1
Evan Simpson
evan@zope.com
Mon, 15 Oct 2001 10:58:06 -0400
Update of /cvs-repository/Packages/ZTUtils
In directory cvs.zope.org:/tmp/cvs-serv5878
Modified Files:
Tag: ztutils-1_1_0
Zope.py
Log Message:
Merge fixes from trunk
=== Packages/ZTUtils/Zope.py 1.2 => 1.2.2.1 ===
from Batch import Batch
from Products.ZCatalog.Lazy import Lazy
-from AccessControl.ZopeGuards import guarded_getitem
-from AccessControl import getSecurityManager, Unauthorized
+from AccessControl import getSecurityManager
from string import split, join
from types import StringType, ListType, IntType, FloatType
from DateTime import DateTime
+try:
+ from AccessControl.ZopeGuards import guarded_getitem
+except ImportError:
+ Unauthorized = 'Unauthorized'
+ def guarded_getitem(object, index):
+ v = object[index]
+ if getSecurityManager().validate(object, object, index, v):
+ return v
+ raise Unauthorized, 'unauthorized access to element %s' % `i`
+else:
+ from AccessControl import Unauthorized
+
class LazyFilter(Lazy):
# A LazyFilter that checks with the security policy
@@ -128,24 +139,27 @@
e=self._eindex
skip = self._skip
while i > ind:
+ e = e + 1
try:
- e=e+1
try: v = guarded_getitem(s, e)
- except Unauthorized, vv:
+ except 'Unauthorized', vv:
if skip is None:
msg = '(item %s): %s' % (index, vv)
raise Unauthorized, msg, sys.exc_info()[2]
- continue
- if skip and not getSecurityManager().checkPermission(skip, v):
- continue
- if test is None or test(v):
- data.append(v)
- ind=ind+1
+ skip_this = 1
+ else:
+ skip_this = 0
except IndexError:
del self._test
del self._seq
del self._eindex
raise IndexError, index
+ if skip_this: continue
+ if skip and not getSecurityManager().checkPermission(skip, v):
+ continue
+ if test is None or test(v):
+ data.append(v)
+ ind=ind+1
self._eindex=e
return data[i]
@@ -278,8 +292,9 @@
addition to their simple marshal string. Dictionaries will be
flattened and marshalled using ":record".
'''
-
- for i in range(len(pairs)):
+ i = len(pairs)
+ while i > 0:
+ i = i - 1
k, v = pairs[i]
m = ''
sublist = None