Edgewall Software
Modify

Opened 16 years ago

Closed 16 years ago

Last modified 16 years ago

#6591 closed defect (fixed)

Formatter is not correctly initialized on mimeview.rst

Reported by: Pedro Algarvio, aka, s0undt3ch <ufs@…> Owned by: Christian Boos
Priority: normal Milestone: 0.11
Component: rendering Version: devel
Severity: blocker Keywords:
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

On trac/mimeview/rst.py, Formatter is not correctly initialised.

The code bellow will fail to render correctly on trac .11 until fixed:

class Foo(object):
    pass

Line 147 should be:

processor = WikiProcessor(Formatter(self.env, context), language)

Not:

processor = WikiProcessor(Formatter(context), language)

Attachments (0)

Change History (5)

comment:1 by Pedro Algarvio, aka, s0undt3ch <ufs@…>, 16 years ago

While the above fixes the rst renderer, when relying on it on a seperate macro I get:

Traceback (most recent call last):
  File "/home/vampas/projects/trac11/trac/wiki/formatter.py", line 465, in _macro_formatter
    return macro.process(args, in_paragraph=True)
  File "/home/vampas/projects/trac11/trac/wiki/formatter.py", line 179, in process
    text = self.processor(text)
  File "/home/vampas/projects/trac11/trac/wiki/formatter.py", line 166, in _macro_processor
    text)
  File "/var/lib/trac/Pastie/plugins/PythonDoc.py", line 228, in expand_macro
    return instance.render()
  File "/var/lib/trac/Pastie/plugins/PythonDoc.py", line 71, in render
    html.DD(class_='module')(
  File "/home/vampas/projects/Genshi/genshi/builder.py", line 254, in __call__
    Fragment.__call__(self, *args)
  File "/home/vampas/projects/Genshi/genshi/builder.py", line 95, in __call__
    map(self.append, args)
  File "/home/vampas/projects/Genshi/genshi/builder.py", line 124, in append
    map(self.append, iter(node))
  File "/home/vampas/projects/Genshi/genshi/builder.py", line 124, in append
    map(self.append, iter(node))
  File "/var/lib/trac/Pastie/plugins/PythonDoc.py", line 55, in _dump_stmt
    for output in self._dump_node(child, parents + [node]):
  File "/var/lib/trac/Pastie/plugins/PythonDoc.py", line 138, in _dump_function
    yield html.DD(self._format_docstring(node.doc))
  File "/var/lib/trac/Pastie/plugins/PythonDoc.py", line 155, in _format_docstring
    return Markup(publish_parts(text, writer_name='html'))
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/core.py", line 431, in publish_parts
    enable_exit_status=enable_exit_status)
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/core.py", line 612, in publish_programmatically
    output = pub.publish(enable_exit_status=enable_exit_status)
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/core.py", line 204, in publish
    self.settings)
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/readers/__init__.py", line 71, in read
    self.parse()
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/readers/__init__.py", line 77, in parse
    self.parser.parse(self.input, document)
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/parsers/rst/__init__.py", line 155, in parse
    self.statemachine.run(inputlines, document, inliner=self.inliner)
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/parsers/rst/states.py", line 171, in run
    input_source=document['source'])
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/statemachine.py", line 233, in run
    context, next_state, result = self.check_line(
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/statemachine.py", line 422, in check_line
    return method(match, context, next_state)
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/parsers/rst/states.py", line 2199, in explicit_markup
    nodelist, blank_finish = self.explicit_construct(match)
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/parsers/rst/states.py", line 2211, in explicit_construct
    return method(self, expmatch)
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/parsers/rst/states.py", line 1972, in directive
    return self.run_directive(
  File "/usr/lib/python2.4/site-packages/docutils-0.4-py2.4.egg/docutils/parsers/rst/states.py", line 2018, in run_directive
    self.state_machine)
  File "/home/vampas/projects/trac11/trac/mimeview/rst.py", line 177, in code_block
    reference = code_formatter(language, text)
  File "/home/vampas/projects/trac11/trac/mimeview/rst.py", line 148, in code_formatter
    processor = WikiProcessor(Formatter(self.env, context), language)
  File "/home/vampas/projects/trac11/trac/wiki/formatter.py", line 229, in __init__
    self.req = context.req
  File "/home/vampas/projects/trac11/trac/web/api.py", line 171, in __getattr__
    raise AttributeError(name)
AttributeError: req

a print of the context __dict__ keys:

'session', 'incookie', 'tz', 'chrome', 'args', '_outcharset', 'base_url', 'perm', 'outcookie', 'callbacks', '_start_response', 'href', 'environ', '_outheaders', 'authname', 'abs_href', '_status', '_response', '_write', '_inheaders', 'form_token']

While when rendering a {{{#!rst}}} block on a wiki page:

['req', 'href', 'resource', 'perm', 'parent']

comment:2 by osimons, 16 years ago

Resolution: fixed
Status: newclosed

I spotted PythonDoc.py in that Traceback. Is that the macro cmlenz has for Genshi and Babel docs? Is that macro 0.11 compatible?

The Trac patch was good anyway, and looks like a miss from context-refactoring. Committed as [6377].

Closing the ticket as Trac rst code rendering is now working again, and as I'm quite certain the macro problem is an issue with the macro and not Trac.

in reply to:  2 ; comment:3 by Pedro Algarvio, aka, s0undt3ch <ufs@…>, 16 years ago

Replying to osimons:

I spotted PythonDoc.py in that Traceback. Is that the macro cmlenz has for Genshi and Babel docs? Is that macro 0.11 compatible?

It is, and no, not .11 compatible, I had to change it a bit

The Trac patch was good anyway, and looks like a miss from context-refactoring. Committed as [6377].

Closing the ticket as Trac rst code rendering is now working again, and as I'm quite certain the macro problem is an issue with the macro and not Trac.

The macro still throws some issues, yet, another question, has it been thought, to integrate pygments rst-directive since it would handle all sorts of code blocks and still render as plain-text if lexer not found?

in reply to:  3 ; comment:4 by osimons, 16 years ago

Replying to Pedro Algarvio, aka, s0undt3ch <ufs@ufsoft.org>:

… has it been thought, to integrate pygments rst-directive since it would handle all sorts of code blocks and still render as plain-text if lexer not found?

Well, pygments is only the default/recommended source code renderer for 0.11 - enscript and clearsilver are still supported and in wide-spread use.

I do see the rationale of having a plain-text pre-formatted fallback through - in some cases. For source code that could make sense, for macros at least they should throw an error like they usually do when something is wrong. However, currently we do not differentiate between them, and have no idea what a missing processor would intend to be doing.

That suggested directive would make it possible to differentiate, but then we would have a directive that worked in rst without an equivalent in standard Trac. That is not ideal either.

in reply to:  4 comment:5 by osimons, 16 years ago

Replying to osimons:

… enscript and clearsilver ….

Enscript and SilverCity of course… :-)

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Christian Boos.
The resolution will be deleted. Next status will be 'reopened'.
to The owner will be changed from Christian Boos to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.