Comment 3 for bug 979598

Revision history for this message
David Coles (dcoles) wrote :

Matt: I think the intent here was that if you had already written the headers and some some HTML, then this might produce somewhat valid graphical output (due to the way it commenting out the headers and closes any potential open tags). It's ugly, but in most "you can get away with almost any broken HTML" browsers, it'll probably give you something a little visually cleaner.

Doing this correctly would require the cgitb module to be aware of the output state of the page (have headers been sent and what is the state of the HTML output), so it could generate a valid output - not possible in general CGI.

Marco:
A quick workaround is to monkey-patch the cgitb module:

>>> import cgitb
>>> cgitb._reset = cgitb.reset
>>> cgitb.reset = lambda: cgitb._reset().replace('<!--: spam\n','')>>> cgitb.enable()
>>> raise ValueError

Though this will cause an extra header to be printed in the output if you've already sent the CGI header.