merge #12890: don't emit <p> tags in text mode when logdir specified.

Patch by Jeff McNeil.
This commit is contained in:
R David Murray 2012-10-27 14:57:22 -04:00
commit dcd34a6419
4 changed files with 37 additions and 11 deletions

View file

@ -292,14 +292,19 @@ class Hook:
if self.logdir is not None: if self.logdir is not None:
suffix = ['.txt', '.html'][self.format=="html"] suffix = ['.txt', '.html'][self.format=="html"]
(fd, path) = tempfile.mkstemp(suffix=suffix, dir=self.logdir) (fd, path) = tempfile.mkstemp(suffix=suffix, dir=self.logdir)
try: try:
file = os.fdopen(fd, 'w') file = os.fdopen(fd, 'w')
file.write(doc) file.write(doc)
file.close() file.close()
msg = '<p> %s contains the description of this error.' % path msg = '%s contains the description of this error.' % path
except: except:
msg = '<p> Tried to save traceback to %s, but failed.' % path msg = 'Tried to save traceback to %s, but failed.' % path
self.file.write(msg + '\n')
if self.format == 'html':
self.file.write('<p>%s</p>\n' % msg)
else:
self.file.write(msg + '\n')
try: try:
self.file.flush() self.file.flush()
except: pass except: pass

View file

@ -1,7 +1,9 @@
from test.support import run_unittest from test.support import run_unittest
from test.script_helper import assert_python_failure, temp_dir
import unittest import unittest
import sys import sys
import subprocess import subprocess
import tempfile
import cgitb import cgitb
class TestCgitb(unittest.TestCase): class TestCgitb(unittest.TestCase):
@ -36,16 +38,31 @@ class TestCgitb(unittest.TestCase):
self.assertIn("ValueError", text) self.assertIn("ValueError", text)
self.assertIn("Hello World", text) self.assertIn("Hello World", text)
def test_hook(self): def test_syshook_no_logdir_default_format(self):
proc = subprocess.Popen([sys.executable, '-c', with temp_dir() as tracedir:
('import cgitb;' rc, out, err = assert_python_failure(
'cgitb.enable();' '-c',
'raise ValueError("Hello World")')], ('import cgitb; cgitb.enable(logdir="%s"); '
stdout=subprocess.PIPE) 'raise ValueError("Hello World")') % tracedir)
out = proc.stdout.read().decode(sys.getfilesystemencoding()) out = out.decode(sys.getfilesystemencoding())
self.addCleanup(proc.stdout.close)
self.assertIn("ValueError", out) self.assertIn("ValueError", out)
self.assertIn("Hello World", out) self.assertIn("Hello World", out)
# By default we emit HTML markup.
self.assertIn('<p>', out)
self.assertIn('</p>', out)
def test_syshook_no_logdir_text_format(self):
# Issue 12890: we were emitting the <p> tag in text mode.
with temp_dir() as tracedir:
rc, out, err = assert_python_failure(
'-c',
('import cgitb; cgitb.enable(format="text", logdir="%s"); '
'raise ValueError("Hello World")') % tracedir)
out = out.decode(sys.getfilesystemencoding())
self.assertIn("ValueError", out)
self.assertIn("Hello World", out)
self.assertNotIn('<p>', out)
self.assertNotIn('</p>', out)
def test_main(): def test_main():

View file

@ -769,6 +769,7 @@ Mark Mc Mahon
Gordon McMillan Gordon McMillan
Andrew McNamara Andrew McNamara
Caolan McNamara Caolan McNamara
Jeff McNeil
Craig McPheeters Craig McPheeters
Lambert Meertens Lambert Meertens
Bill van Melle Bill van Melle

View file

@ -62,6 +62,9 @@ Core and Builtins
Library Library
------- -------
- Issue #12890: cgitb no longer prints spurious <p> tags in text
mode when the logdir option is specified.
- Issue #16307: Fix multiprocessing.Pool.map_async not calling its callbacks. - Issue #16307: Fix multiprocessing.Pool.map_async not calling its callbacks.
Patch by Janne Karila. Patch by Janne Karila.