Commit 67f9aa36 authored by Hanno Schlichting's avatar Hanno Schlichting

Avoid some really old-style pseudo performance hacks

parent dfb397dc
...@@ -167,8 +167,8 @@ class ZCatalog(Folder, Persistent, Implicit): ...@@ -167,8 +167,8 @@ class ZCatalog(Folder, Persistent, Implicit):
def manage_edit(self, RESPONSE, URL1, threshold=1000, REQUEST=None): def manage_edit(self, RESPONSE, URL1, threshold=1000, REQUEST=None):
""" edit the catalog """ """ edit the catalog """
if type(threshold) is not type(1): if not isinstance(threshold, int):
threshold=int(threshold) threshold = int(threshold)
self.threshold = threshold self.threshold = threshold
RESPONSE.redirect( RESPONSE.redirect(
...@@ -923,40 +923,42 @@ class td(RestrictedDTML, TemplateDict): ...@@ -923,40 +923,42 @@ class td(RestrictedDTML, TemplateDict):
pass pass
def expr_match(ob, ed, c=InstanceDict, r=0): def expr_match(ob, ed):
e, md, push, pop = ed e, md, push, pop = ed
push(c(ob, md)) push(InstanceDict(ob, md))
r = 0
try: try:
r = e.eval(md) r = e.eval(md)
finally: finally:
pop() pop()
return r return r
_marker = object()
def mtime_match(ob, t, q, fn=hasattr):
if not fn(ob, '_p_mtime'):
return 0
return q=='<' and (ob._p_mtime < t) or (ob._p_mtime > t)
def mtime_match(ob, t, q):
mtime = getattr(ob, '_p_mtime', _marker)
if mtime is _marker():
return False
return q=='<' and (mtime < t) or (mtime > t)
def role_match(ob, permission, roles, lt=type([]), tt=type(())):
pr = []
fn = pr.append
while 1: def role_match(ob, permission, roles):
if hasattr(ob, permission): pr = []
p=getattr(ob, permission) while True:
if type(p) is lt: p = getattr(ob, permission, _marker)
map(fn, p) if p is not _marker:
if isinstance(p, list):
pr.append(p)
ob = aq_parent(ob) ob = aq_parent(ob)
if ob is not None: if ob is not None:
continue continue
break break
if type(p) is tt: if isinstance(p, tuple):
map(fn, p) pr.append(p)
break break
if p is None: if p is None:
map(fn, ('Manager', 'Anonymous')) pr.append(('Manager', 'Anonymous'))
break break
ob = aq_parent(ob) ob = aq_parent(ob)
...@@ -965,6 +967,6 @@ def role_match(ob, permission, roles, lt=type([]), tt=type(())): ...@@ -965,6 +967,6 @@ def role_match(ob, permission, roles, lt=type([]), tt=type(())):
break break
for role in roles: for role in roles:
if not (role in pr): if role not in pr:
return 0 return False
return 1 return True
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment