Edgewall Software

Opened 18 years ago

Closed 18 years ago

#114 closed defect (fixed)

Can't reference template variables from inside functions defined in <?python ... ?> block

Reported by: arnarbi+genshi@… Owned by: cmlenz
Priority: critical Milestone: 0.4.1
Component: Expression evaluation Version: 0.4
Keywords: Cc:

Description

As discussed on IRC between me and cmlenz, here's an example that fails with "NameError?: global name 'name' is not defined":

# -*- encoding: UTF-8 -*-

from genshi.template import MarkupTemplate

tmpl = MarkupTemplate('''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:py="http://genshi.edgewall.org/"
      xmlns:xi="http://www.w3.org/2001/XInclude">
<head></head>
<body>

<?python
def get_var():
    return name
?>

${get_var()}

</body>
</html>
''')

stream = tmpl.generate(name='world')

print stream.render()

Attachments (1)

genshibug.py (656 bytes) - added by arnarbi+genshi@… 18 years ago.
A test case

Download all attachments as: .zip

Change History (6)

comment:1 Changed 18 years ago by arnarbi+genshi@…

A workaround is to use

_lookup_name(data, "name")

inside the function.

comment:2 Changed 18 years ago by cmlenz

  • Milestone changed from 0.5 to 0.4.1
  • Priority changed from major to critical
  • Status changed from new to assigned
  • Version changed from devel to 0.4

This seems to be fixed by the second patch to #113.

comment:3 Changed 18 years ago by cmlenz

(and the first one too, I guess the problem is that return statements aren't transformed)

Changed 18 years ago by arnarbi+genshi@…

A test case

comment:4 Changed 18 years ago by cmlenz

I've attached an updated patch to #113 which fixes the second test case, too.

comment:5 Changed 18 years ago by cmlenz

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

Okay, this should be fixed by [573] (and [574] for 0.4.x).

Note: See TracTickets for help on using tickets.