summaryrefslogtreecommitdiffstats
path: root/Lib/cgi.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2008-06-12 02:38:51 (GMT)
committerBarry Warsaw <barry@python.org>2008-06-12 02:38:51 (GMT)
commit596097e0bc2b22d53232fcf4d20ddad3f3f80f1b (patch)
treeb7fa762dd86aee2e6fce9de45c1fa7a67e751462 /Lib/cgi.py
parenta5b41eb1e63495c068949a62da630d00a672cfb6 (diff)
downloadcpython-596097e0bc2b22d53232fcf4d20ddad3f3f80f1b.zip
cpython-596097e0bc2b22d53232fcf4d20ddad3f3f80f1b.tar.gz
cpython-596097e0bc2b22d53232fcf4d20ddad3f3f80f1b.tar.bz2
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.
Diffstat (limited to 'Lib/cgi.py')
-rwxr-xr-xLib/cgi.py25
1 files changed, 14 insertions, 11 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()