import sys
import tempfile
import unittest
+import warnings
+ from collections import namedtuple
from io import StringIO, BytesIO
class HackedSysModule:
class CgiTests(unittest.TestCase):
+ def test_parse_multipart(self):
+ fp = BytesIO(POSTDATA.encode('latin1'))
+ env = {'boundary': BOUNDARY.encode('latin1'),
+ 'CONTENT-LENGTH': '558'}
+ result = cgi.parse_multipart(fp, env)
+ expected = {'submit': [b' Add '], 'id': [b'1234'],
+ 'file': [b'Testing 123.\n'], 'title': [b'']}
+ self.assertEqual(result, expected)
+
+ def test_fieldstorage_properties(self):
+ fs = cgi.FieldStorage()
+ self.assertFalse(fs)
+ self.assertIn("FieldStorage", repr(fs))
+ self.assertEqual(list(fs), list(fs.keys()))
+ fs.list.append(namedtuple('MockFieldStorage', 'name')('fieldvalue'))
+ self.assertTrue(fs)
+
def test_escape(self):
- self.assertEqual("test & string", cgi.escape("test & string"))
- self.assertEqual("<test string>", cgi.escape("<test string>"))
- self.assertEqual(""test string"", cgi.escape('"test string"', True))
+ # cgi.escape() is deprecated.
+ with warnings.catch_warnings():
+ warnings.filterwarnings('ignore', 'cgi\.escape',
+ DeprecationWarning)
+ self.assertEqual("test & string", cgi.escape("test & string"))
+ self.assertEqual("<test string>", cgi.escape("<test string>"))
+ self.assertEqual(""test string"", cgi.escape('"test string"', True))
def test_strict(self):
for orig, expect in parse_strict_test_cases:
Library
-------
+ - Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries
+ and bytes data. Patch by Jonas Wagner.
+
+- Issue #16957: shutil.which() no longer searches a bare file name in the
+ current directory on Unix and no longer searches a relative file path with
+ a directory part in PATH directories. Patch by Thomas Kluyver.
+
- Issue #1159051: GzipFile now raises EOFError when reading a corrupted file
with truncated header or footer.