Hi folks, I'm trying to build a lightweight templating system around docutils. I'm using a (slightly modified, I use core.publish_file) version of Nicola Paolucci's recipe to create an HTML fragment from a reST file, which works fine as long as there are no errors. If there are errors, I want the option of allowing the error to be processed normally (resulting in an HTML fragment with embedded error messages) or throw an exception (so I can trap it and display the text instead). I've found that if the docutils processor is running on a file, I cannot get it to throw an exception all the way out to the calling method (it traps and processes it internally), while if I use a StringIO it causes exceptions that don't show up in the file processing. Docutils appears to be using the file object as it's state machine and calling methods which aren't part of the StringIO. Finally, if I use a StringIO, I have trouble with the include directive. If I can get core.publish_file (with a real file) to optionally throw an exception on error, I think that would be all I need. Failing that I need to teach core.publish_string (or core.publish_file with StringIO "file") to optionally *not* throw an exception *and* pass it a parameter for the relative path for include directives to work. Naturally, I'd prefer the first path. TIA --Dethe
Dethe Elza wrote:
I'm trying to build a lightweight templating system around docutils. ... If there are errors, I want the option of allowing the error to be processed normally (resulting in an HTML fragment with embedded error messages) or throw an exception (so I can trap it and display the text instead).
Use the "--traceback" option ("traceback" setting) to allow exceptions to propagate to the calling code. The program logic for exception handling is in docutils.core.Publisher.publish(). Use "--report" and/or "--halt" options ("report_level" & "halt_level" settings) for fine control. See <http://docutils.sf.net/docs/config.html>, "[general]" section, for details.
I've found that if the docutils processor is running on a file, I cannot get it to throw an exception all the way out to the calling method (it traps and processes it internally), while if I use a StringIO it causes exceptions that don't show up in the file processing.
I suspect this may be a red herring. What Python version? There's a StringIO bug in Python 2.1 or 2.2.
Docutils appears to be using the file object as it's state machine and calling methods which aren't part of the StringIO. Finally, if I use a StringIO, I have trouble with the include directive.
I don't follow. Please provide some supporting evidence. -- David Goodger http://starship.python.net/~goodger For hire: http://starship.python.net/~goodger/cv Docutils: http://docutils.sourceforge.net/ (includes reStructuredText: http://docutils.sf.net/rst.html)
participants (2)
-
David Goodger -
Dethe Elza