[Zope] use path function on a python script

Dieter Maurer dieter at handshake.de
Sat Oct 11 03:20:19 EDT 2008


Garito wrote at 2008-10-8 10:46 +0200:
>How can I import the TALES funcion path on a python script?

You cannot -- while it looks like a normal function, it not really is one.

"path" gets a string but interprets this string with knowledge
about the template's namespace. This shows you that some magic
must be in the background that provides the template namespace
to whatever implements "path".
This magic is unavailable in a "Script Python".


In fact, the "path" handling is prepared in
"Products.PageTemplates.PythonExpr.PythonExpr._bind_used_names"
by the following code:

        for vname in self._f_varnames:
            val = vars.get(vname, _marker)
            if val is _marker:
                has = val = getType(vname)
                if has:
                    val = ExprTypeProxy(vname, val, econtext)
                    names[vname] = val

The last two lines bind "path" to
"ExprTypeProxy('path', val, econtext)".
This is what comes nearest to "the TALES function path".
As you can see, it is not a simple function but one provided with lots of
context information (behind the scenes).
The "econtext" contains the template's namespace.



-- 
Dieter


More information about the Zope mailing list