[Zope] use path function on a python script

Dieter Maurer dieter at handshake.de
Sun Oct 12 02:06:58 EDT 2008


Garito wrote at 2008-10-11 16:39 +0200:
>Did you imagine another way to do what I need to do?

I have not followed intensively "what you need to do".
Thus, what follows may not be adequate.

When I remember right, then a PageTemplate's namespace is passed
on to a "Script (Python)" when this script binds "namespace".
Thus, this way you get access to the variables defined in the template.

A simple path "var/s1/.../sn" is roughly requivalent to

  x = var.restricedTraverse("s1/.../sn")
  if callable(x): x = x() # "callable" may not be available in "Script (Python)"

If the path contains "?var", these must be resolved beforehand.

More complex paths "p1 | p2 | ... pn" are roughly equivalent
to

	exc = None
	for p in (p1, p2, ... pn):
	  try: return path1(p, ...)
	  except <some standard exceptions>:
	    exc = sys.exc_info()
	if exc is not None: raise exc[0], exc[1], exc[2]

The most difficult part are for paths where "pn" is not a path
expression but an arbitrary one. In this case, the concrete
TALES implementation will be required for an interpretation.


Along this outline, a function "path(path_expr, variable_binding)"
can be defined which roughly behaves like "path(path_expr)" in
a PageTemplate with the current variable binding expressed
as "variable_binding".

For simple cases, this function could be implemented in untrusted
code. Complex cases will require access to the TALES implementation
and therefore probably trusted code.



-- 
Dieter


More information about the Zope mailing list