Edgewall Software

Opened 18 years ago

Closed 18 years ago

#45 closed defect (fixed)

<py:for> directive doesn't handle a structured list of variable

Reported by: cboos Owned by: cmlenz
Priority: minor Milestone: 0.3
Component: Template processing Version: devel
Keywords: py:for Cc:

Description

I've got a backtrace while trying to enumerate the items of a dict:

<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:py="http://markup.edgewall.org/" >

    <!--! This doesn't work -->
    <py:for each="idx, (k, v) in enumerate(dict(a=1, b=2).items())">
      <p>$idx: key=$k value=$v</p>
    </py:for>

    <!--! This is a workaround -->
    <py:for each="idx, kv in enumerate(dict(a=1, b=2).items())">
      <p>$idx: key=${kv[0]} value=${kv[1]}</p>
    </py:for>

  </body>
</html>

This is either a bug, or a documentation issue, i.e. I think it's not absolutely necessary to support this, as the workaround is easy.

Would be nice to have it, though, or at least to have a better error message.

Change History (3)

comment:1 Changed 18 years ago by cboos

  • Version changed from 0.2 to devel

The backtrace in question:

Traceback (most recent call last):
  File "<string>", line 1, in ?
  File "C:\Workspace\src\trac\Markup\trunk\markup\core.py", line 141, in render
    output = u''.join(list(generator))
  File "c:\workspace\src\trac\markup\trunk\markup\output.py", line 112, in __call__
    kind, data, pos = stream.next()
  File "c:\workspace\src\trac\markup\trunk\markup\output.py", line 529, in next
    return self.iterable.next()
  File "c:\workspace\src\trac\markup\trunk\markup\output.py", line 474, in __call__
    for kind, data, pos in chain(stream, [(None, None, None)]):
  File "C:\Workspace\src\trac\Markup\trunk\markup\core.py", line 202, in _ensure
    for event in stream:
  File "C:\Workspace\src\trac\Markup\trunk\markup\filters.py", line 147, in __call__
    for kind, data, pos in stream:
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 1022, in _match
    kind, data, pos = stream.next()
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 998, in _match
    for kind, data, pos in stream:
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 928, in _eval
    for kind, data, pos in stream:
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 986, in _flatten
    for event in self._flatten(substream, ctxt):
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 980, in _flatten
    for kind, data, pos in stream:
  File "c:\workspace\src\trac\markup\trunk\markup\template.py", line 413, in __call__
    scope[name] = item[idx]
IndexError: tuple index out of range

(using r260)

comment:2 Changed 18 years ago by cmlenz

  • Milestone set to 0.3

Yeah, would be nice if that worked as expected.

comment:3 Changed 18 years ago by cmlenz

  • Resolution set to fixed
  • Status changed from new to closed

Should be fixed in [276].

Note: See TracTickets for help on using tickets.