Mercurial > cpython-lru_cache-weakref
changeset 47632:18eaa1d5f394
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.
| author | Barry Warsaw <barry@python.org> |
|---|---|
| date | Thu, 12 Jun 2008 02:38:51 +0000 |
| parents | 38d176ebb2fa |
| children | 5af15089a100 |
| files | Lib/cgi.py Lib/test/test_cgi.py |
| diffstat | 2 files changed, 15 insertions(+), 12 deletions(-) [+] |
line wrap: on
line diff
--- a/Lib/cgi.py Thu Jun 12 01:50:39 2008 +0000 +++ b/Lib/cgi.py Thu Jun 12 02:38:51 2008 +0000 @@ -32,13 +32,12 @@ # ======= 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 @@ 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 @@ 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()
--- a/Lib/test/test_cgi.py Thu Jun 12 01:50:39 2008 +0000 +++ b/Lib/test/test_cgi.py Thu Jun 12 02:38:51 2008 +0000 @@ -234,7 +234,7 @@ 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():
