From 596097e0bc2b22d53232fcf4d20ddad3f3f80f1b Mon Sep 17 00:00:00 2001 From: Barry Warsaw Date: Thu, 12 Jun 2008 02:38:51 +0000 Subject: Patch by Humberto Diogenes for issue 2849, removing rfc822 module from the standard library. There are still a few cases of it in Demo and Tools, but that's fine for now. These should eventually get cleaned up. mimetools still has an import of rfc822, but mimetools itself should go away. --- Lib/cgi.py | 25 ++++++++++++++----------- Lib/test/test_cgi.py | 2 +- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/Lib/cgi.py b/Lib/cgi.py index 93747ce..caf54bd 100755 --- a/Lib/cgi.py +++ b/Lib/cgi.py @@ -32,13 +32,12 @@ __version__ = "2.6" # ======= from operator import attrgetter +from io import StringIO import sys import os import urllib import mimetools -import rfc822 -import collections -from io import StringIO +import email.parser __all__ = ["MiniFieldStorage", "FieldStorage", "parse", "parse_qs", "parse_qsl", "parse_multipart", @@ -404,7 +403,7 @@ class FieldStorage: disposition_options: dictionary of corresponding options - headers: a dictionary(-like) object (sometimes rfc822.Message or a + headers: a dictionary(-like) object (sometimes email.message.Message or a subclass thereof) containing *all* headers The class is subclassable, mostly for the purpose of overriding @@ -633,13 +632,17 @@ class FieldStorage: raise ValueError('Invalid boundary in multipart form: %r' % (ib,)) self.list = [] klass = self.FieldStorageClass or self.__class__ - part = klass(self.fp, {}, ib, - environ, keep_blank_values, strict_parsing) - # Throw first part away - while not part.done: - headers = rfc822.Message(self.fp) - part = klass(self.fp, headers, ib, - environ, keep_blank_values, strict_parsing) + parser = email.parser.FeedParser() + # Create bogus content-type header for proper multipart parsing + parser.feed('Content-Type: %s; boundary=%s\r\n\r\n' % (self.type, ib)) + parser.feed(self.fp.read()) + full_msg = parser.close() + # Get subparts + msgs = full_msg.get_payload() + for msg in msgs: + fp = StringIO(msg.get_payload()) + part = klass(fp, msg, ib, environ, keep_blank_values, + strict_parsing) self.list.append(part) self.skip_lines() diff --git a/Lib/test/test_cgi.py b/Lib/test/test_cgi.py index f9b336f..0d9b227 100644 --- a/Lib/test/test_cgi.py +++ b/Lib/test/test_cgi.py @@ -234,7 +234,7 @@ Content-Disposition: form-data; name="submit" self.assertEquals(len(fs.list), 4) expect = [{'name':'id', 'filename':None, 'value':'1234'}, {'name':'title', 'filename':None, 'value':''}, - {'name':'file', 'filename':'test.txt','value':'Testing 123.\n'}, + {'name':'file', 'filename':'test.txt', 'value':'Testing 123.'}, {'name':'submit', 'filename':None, 'value':' Add '}] for x in range(len(fs.list)): for k, exp in expect[x].items(): -- cgit v0.12