summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorR David Murray <rdmurray@bitdance.com>2012-10-27 18:57:22 (GMT)
committerR David Murray <rdmurray@bitdance.com>2012-10-27 18:57:22 (GMT)
commitdcd34a6419393c03d0ae6df4f250e6e03e95d1f1 (patch)
treea1fc6fccd14d69de0cb2aeca8d55e4fd10b81cf6
parent450371305fd40d35beff7aa812daed9abe38dedd (diff)
parentc4b8e05092b5aa018dd74f8563037b23d3c6756e (diff)
downloadcpython-dcd34a6419393c03d0ae6df4f250e6e03e95d1f1.zip
cpython-dcd34a6419393c03d0ae6df4f250e6e03e95d1f1.tar.gz
cpython-dcd34a6419393c03d0ae6df4f250e6e03e95d1f1.tar.bz2
merge #12890: don't emit <p> tags in text mode when logdir specified.
Patch by Jeff McNeil.
-rw-r--r--Lib/cgitb.py11
-rw-r--r--Lib/test/test_cgitb.py33
-rw-r--r--Misc/ACKS1
-rw-r--r--Misc/NEWS3
4 files changed, 37 insertions, 11 deletions
diff --git a/Lib/cgitb.py b/Lib/cgitb.py
index e3ce2cb..6eb52e7 100644
--- a/Lib/cgitb.py
+++ b/Lib/cgitb.py
@@ -292,14 +292,19 @@ class Hook:
if self.logdir is not None:
suffix = ['.txt', '.html'][self.format=="html"]
(fd, path) = tempfile.mkstemp(suffix=suffix, dir=self.logdir)
+
try:
file = os.fdopen(fd, 'w')
file.write(doc)
file.close()
- msg = '<p> %s contains the description of this error.' % path
+ msg = '%s contains the description of this error.' % path
except:
- msg = '<p> Tried to save traceback to %s, but failed.' % path
- self.file.write(msg + '\n')
+ msg = 'Tried to save traceback to %s, but failed.' % path
+
+ if self.format == 'html':
+ self.file.write('<p>%s</p>\n' % msg)
+ else:
+ self.file.write(msg + '\n')
try:
self.file.flush()
except: pass
diff --git a/Lib/test/test_cgitb.py b/Lib/test/test_cgitb.py
index 16a4b1a..4017772 100644
--- a/Lib/test/test_cgitb.py
+++ b/Lib/test/test_cgitb.py
@@ -1,7 +1,9 @@
from test.support import run_unittest
+from test.script_helper import assert_python_failure, temp_dir
import unittest
import sys
import subprocess
+import tempfile
import cgitb
class TestCgitb(unittest.TestCase):
@@ -36,16 +38,31 @@ class TestCgitb(unittest.TestCase):
self.assertIn("ValueError", text)
self.assertIn("Hello World", text)
- def test_hook(self):
- proc = subprocess.Popen([sys.executable, '-c',
- ('import cgitb;'
- 'cgitb.enable();'
- 'raise ValueError("Hello World")')],
- stdout=subprocess.PIPE)
- out = proc.stdout.read().decode(sys.getfilesystemencoding())
- self.addCleanup(proc.stdout.close)
+ def test_syshook_no_logdir_default_format(self):
+ with temp_dir() as tracedir:
+ rc, out, err = assert_python_failure(
+ '-c',
+ ('import cgitb; cgitb.enable(logdir="%s"); '
+ 'raise ValueError("Hello World")') % tracedir)
+ out = out.decode(sys.getfilesystemencoding())
self.assertIn("ValueError", 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():
diff --git a/Misc/ACKS b/Misc/ACKS
index f6030a4..26907e2 100644
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -769,6 +769,7 @@ Mark Mc Mahon
Gordon McMillan
Andrew McNamara
Caolan McNamara
+Jeff McNeil
Craig McPheeters
Lambert Meertens
Bill van Melle
diff --git a/Misc/NEWS b/Misc/NEWS
index a82b6ca..c8eb19d 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -62,6 +62,9 @@ Core and Builtins
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.
Patch by Janne Karila.