Edgewall Software

Opened 17 years ago

Closed 17 years ago

#84 closed defect (fixed)

Support for <?python ?> processing instruction

Reported by: cmlenz Owned by: cmlenz
Priority: major Milestone: 0.4
Component: Template processing Version: devel
Keywords: Cc:

Description

Genshi should support the <?python ?> processing instruction as it is offered by Kid:

http://kid-templating.org/language.html#embedding-code-blocks-python

Attachments (4)

python_pi.diff (16.4 KB) - added by cmlenz 17 years ago.
First draft of the implementation
python_pi.2.diff (18.1 KB) - added by cmlenz 17 years ago.
Updated patch, supports more Python statements
python_pi.3.diff (23.2 KB) - added by cmlenz 17 years ago.
Updated patch, candidate for merge
python_pi.5.diff (22.0 KB) - added by cmlenz 17 years ago.
Updated patch

Download all attachments as: .zip

Change History (11)

Changed 17 years ago by cmlenz

First draft of the implementation

comment:1 Changed 17 years ago by cmlenz

  • Status changed from new to assigned

I've attached a patch that enables basic support for this feature.

Known issues:

  • A lot of Python statements won't work yet, as the ASTTransformer hasn't been updated to support them yet
  • The PI do not work in Python 2.3, as that version does not support providing a custom mapping object to exec and eval().
  • The indentation of code blocks in processing instructions isn't currently normalized, so lines have to start at column 0 for multi-line suites.

Changed 17 years ago by cmlenz

Updated patch, supports more Python statements

Changed 17 years ago by cmlenz

Updated patch, candidate for merge

comment:2 Changed 17 years ago by cmlenz

Another day, another patch.

This should fix all the issues noted above AFAICT, with one exception: the global statement does not work, nor am I sure how it could be made to work right now.

Anyway, I think this is ready for being merged into trunk. Testing/feedback would be highly appreciated!

comment:3 Changed 17 years ago by cboos

Testing r467 + attachment:python_pi.3.diff, while viewing a custom query:

NameError: name '$append0' is not defined

File "C:\Workspace\src\trac\trunk\trac\web\main.py", line 394, in dispatch_request
  dispatcher.dispatch(req)
File "C:\Workspace\src\trac\trunk\trac\web\main.py", line 226, in dispatch
  content_type)
File "C:\Workspace\src\trac\trunk\trac\web\chrome.py", line 540, in render_template
  return stream.render(method, doctype=doctype)
File "c:\workspace\src\trac\genshi\trunk\genshi\core.py", line 146, in render
  output = u''.join(list(generator))
File "c:\workspace\src\trac\genshi\trunk\genshi\output.py", line 202, in __call__
  for kind, data, pos in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\output.py", line 488, in __call__
  for kind, data, pos in chain(stream, [(None, None, None)]):
File "c:\workspace\src\trac\genshi\trunk\genshi\output.py", line 438, in __call__
  for kind, data, pos in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\core.py", line 207, in _ensure
  for event in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\core.py", line 207, in _ensure
  for event in stream:
File "C:\Workspace\src\trac\trunk\trac\web\chrome.py", line 560, in _strip_accesskeys
  for kind, data, pos in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\core.py", line 207, in _ensure
  for event in stream:
File "C:\Workspace\src\trac\trunk\trac\web\chrome.py", line 549, in _generate
  for kind, data, pos in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\template\markup.py", line 236, in _include
  for event in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\template\markup.py", line 306, in _match
  content = list(self._include(content, ctxt))
File "c:\workspace\src\trac\genshi\trunk\genshi\template\markup.py", line 236, in _include
  for event in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\template\markup.py", line 281, in _match
  for event in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\template\markup.py", line 270, in _strip
  event = stream.next()
File "c:\workspace\src\trac\genshi\trunk\genshi\template\markup.py", line 226, in _exec
  for event in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\template\core.py", line 332, in _eval
  ctxt):
File "c:\workspace\src\trac\genshi\trunk\genshi\template\core.py", line 342, in _eval
  result = data.evaluate(ctxt)
File "c:\workspace\src\trac\genshi\trunk\genshi\template\eval.py", line 128, in evaluate
  '_lookup_item': _lookup_item}, _locals(data))
File "C:\Workspace\src\trac\trunk\templates\query.html", line 77, in <Expression u"any([(value == option) == (constraint.mode == "")                                               for value in constraint["values"]]) and "checked" or None">
  <input type="checkbox" id="${field_name}_$option" name="${field_name}"

(works fine with r467)

comment:4 Changed 17 years ago by cboos

Same "NameError: name '$append0' is not defined" error for View Tickets, i.e. /report

...
File "c:\workspace\src\trac\genshi\trunk\genshi\template\core.py", line 363, in _flatten
  for event in stream:
File "c:\workspace\src\trac\genshi\trunk\genshi\template\directives.py", line 666, in __call__
  value = expr.evaluate(ctxt)
File "c:\workspace\src\trac\genshi\trunk\genshi\template\eval.py", line 128, in evaluate
  '_lookup_item': _lookup_item}, _locals(data))
File "report_view.html", line 39, in <Expression "?">

What's the meaning of "?" in Expression again?

comment:5 Changed 17 years ago by karlb@…

Seems to work great. Some things become much easier or clearer with this PI. Thanks!

Changed 17 years ago by cmlenz

Updated patch

comment:6 Changed 17 years ago by cboos

attachment:python_pi.5.diff seems to work just fine with Trac (couldn't reproduce the issues I had in comment:3 and 4.

comment:7 Changed 17 years ago by cmlenz

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

Latest patch, slightly modified, applied in [497].

Note: See TracTickets for help on using tickets.