Commit 2e7ac9cc authored by Fred Drake's avatar Fred Drake

parent 317719b8
...@@ -89,7 +89,7 @@ Page Template-specific implementation of TALES, with handlers ...@@ -89,7 +89,7 @@ Page Template-specific implementation of TALES, with handlers
for Python expressions, string literals, and paths. for Python expressions, string literals, and paths.
""" """
__version__='$Revision: 1.15 $'[11:-2] __version__='$Revision: 1.16 $'[11:-2]
import re, sys import re, sys
from TALES import Engine, CompilerError, _valid_name, NAME_RE, \ from TALES import Engine, CompilerError, _valid_name, NAME_RE, \
...@@ -171,7 +171,7 @@ class PathExpr: ...@@ -171,7 +171,7 @@ class PathExpr:
dp.reverse() dp.reverse()
return base, path, dp return base, path, dp
def _eval(self, (base, path, dp), econtext, def _eval(self, (base, path, dp), econtext, securityManager,
list=list, isinstance=isinstance, StringType=type('')): list=list, isinstance=isinstance, StringType=type('')):
path = list(path) # Copy! path = list(path) # Copy!
contexts = econtext.contexts contexts = econtext.contexts
...@@ -193,14 +193,18 @@ class PathExpr: ...@@ -193,14 +193,18 @@ class PathExpr:
has, ob = var.has_get(base) has, ob = var.has_get(base)
if not has: if not has:
ob = contexts[base] ob = contexts[base]
return restrictedTraverse(ob, path) if path:
return restrictedTraverse(ob, path, securityManager)
else:
return ob
except (AttributeError, KeyError, TypeError, IndexError, except (AttributeError, KeyError, TypeError, IndexError,
'Unauthorized'), e: 'Unauthorized'), e:
return Undefined(self._s, sys.exc_info()) return Undefined(self._s, sys.exc_info())
def __call__(self, econtext): def __call__(self, econtext):
securityManager = getSecurityManager()
for pathinfo in self._paths: for pathinfo in self._paths:
ob = self._eval(pathinfo, econtext) ob = self._eval(pathinfo, econtext, securityManager)
exists = not isinstance(ob, Undefined) exists = not isinstance(ob, Undefined)
if exists: if exists:
...@@ -271,13 +275,9 @@ class NotExpr: ...@@ -271,13 +275,9 @@ class NotExpr:
return '<NotExpr %s>' % `self._s` return '<NotExpr %s>' % `self._s`
def restrictedTraverse(self, path, def restrictedTraverse(self, path, securityManager,
get=getattr, has=hasattr, N=None, M=[]): get=getattr, has=hasattr, N=None, M=[]):
if not path: return self
securityManager = getSecurityManager()
i = 0 i = 0
if not path[0]: if not path[0]:
# If the path starts with an empty string, go to the root first. # If the path starts with an empty string, go to the root first.
......
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