]> granicus.if.org Git - python/commitdiff
merge from 3.2
authorSenthil Kumaran <senthil@uthcode.com>
Wed, 23 Jan 2013 11:00:26 +0000 (03:00 -0800)
committerSenthil Kumaran <senthil@uthcode.com>
Wed, 23 Jan 2013 11:00:26 +0000 (03:00 -0800)
Issue #12411: Fix to cgi.parse_multipart to correctly use bytes boundaries and
bytes data. Patch by Jonas Wagner.

1  2 
Lib/cgi.py
Lib/test/test_cgi.py
Misc/NEWS

diff --cc Lib/cgi.py
Simple merge
index 5510a0dccd32c88a346b5024388406568d76ca94,07e760b8e3142cfca298cc04438bb034d67d8160..cb28aa8712bdb886bcbf7a5934299d905114ff00
@@@ -4,7 -4,7 +4,8 @@@ import o
  import sys
  import tempfile
  import unittest
 +import warnings
+ from collections import namedtuple
  from io import StringIO, BytesIO
  
  class HackedSysModule:
@@@ -119,14 -119,27 +120,31 @@@ def gen_result(data, environ)
  
  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 &amp; string", cgi.escape("test & string"))
 -        self.assertEqual("&lt;test string&gt;", cgi.escape("<test string>"))
 -        self.assertEqual("&quot;test string&quot;", cgi.escape('"test string"', True))
 +        # cgi.escape() is deprecated.
 +        with warnings.catch_warnings():
 +            warnings.filterwarnings('ignore', 'cgi\.escape',
 +                                     DeprecationWarning)
 +            self.assertEqual("test &amp; string", cgi.escape("test & string"))
 +            self.assertEqual("&lt;test string&gt;", cgi.escape("<test string>"))
 +            self.assertEqual("&quot;test string&quot;", cgi.escape('"test string"', True))
  
      def test_strict(self):
          for orig, expect in parse_strict_test_cases:
diff --cc Misc/NEWS
index 5fdf5d1d5e1581d484d432385949499e8ce2f1a8,147b57c0cede6ad8aa73595564cffaa952d00d14..5b8ad786fe0dfc16b484329e0f146abbf003086a
+++ b/Misc/NEWS
@@@ -150,10 -202,9 +150,13 @@@ Core and Builtin
  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.