[ZPT] repeat attribute in python: expressions?

richard@bizarsoftware.com.au richard@bizarsoftware.com.au
Fri, 04 May 2001 17:07:39 +1000


<p tal:repeat="txt python:'one', 'two'"
tal:content="python:repeat.txt.index">foo</p>

doesn't work (NameError on repeat), whereas

<p tal:repeat="txt python:'one', 'two'"
tal:content="repeat/txt/index">foo</p>

does work. From poking around in PythonExpr, I have managed to hurt my
head, but not come up with a workable patch. I did get the code to the
point where it was actually getting the repeat attribute correctly, and
then the Iterator object out of the mapping ("python:repeat['txt'].index")
but then things started going South on me. For the morbidly curious, I
ended up with:

        def __call__(self, econtext):
            f = self._f

            # Bind template variables
            var = econtext.contexts['var']
            for vname in self._f_varnames:
                if var.has_key(vname):
                    val = var[vname]
                else:
                    val = econtext.contexts.get(vname, _marker)
                if val is not _marker:
                    f.func_globals[vname] = val


... which seems to mirror what is done in the PathExpr code, kinda. The bit
about "Work around lack of security declaration" was going to cause me
problems in the end, I was sure. In the end, I didn't get that far. The
above gets me to:

 Unauthorized on None in "<PythonExpr repeat['txt'].index>"


    Richard

-- 
Richard Jones
richard@bizarsoftware.com.au
Senior Software Developer, Bizar Software (www.bizarsoftware.com.au)