Repository navigation
Remove mimetools usage from the stdlib #47097
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
| BPO | 2848 |
|---|---|
| Nosy | @warsaw, @brettcannon, @rhettinger, @hdiogenes, @benjaminp, @merwok |
| Files |
Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
assignee = 'https://github.com/warsaw'
closed_at = <Date 2010-07-17.22:23:17.091>
created_at = <Date 2008-05-14.00:59:34.517>
labels = ['type-bug', 'library']
title = 'Remove mimetools usage from the stdlib'
updated_at = <Date 2010-07-17.22:23:17.088>
user = 'https://github.com/brettcannon'bugs.python.org fields:
activity = <Date 2010-07-17.22:23:17.088>
actor = 'eric.araujo'
assignee = 'barry'
closed = True
closed_date = <Date 2010-07-17.22:23:17.091>
closer = 'eric.araujo'
components = ['Library (Lib)']
creation = <Date 2008-05-14.00:59:34.517>
creator = 'brett.cannon'
dependencies = []
files = ['10516', '10537', '10538', '10541', '10542', '10583', '10598']
hgrepos = []
issue_num = 2848
keywords = ['patch']
message_count = 23.0
messages = ['66809', '66973', '67176', '67177', '67681', '67682', '67684', '67686', '67791', '67793', '67794', '67797', '67970', '67971', '68050', '68051', '68052', '68058', '68060', '68093', '77153', '77179', '110608']
nosy_count = 7.0
nosy_names = ['barry', 'brett.cannon', 'rhettinger', 'hdiogenes', 'benjamin.peterson', 'eric.araujo', 'bboissin']
pr_nums = []
priority = 'normal'
resolution = 'out of date'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue2848'
versions = ['Python 2.7']Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Activity
brettcannon commentedon May 14, 2008
The mimetools module has been deprecated for ages, but it is still used in
multiple places (a quick grep lists
cgi,httplib,urllib,urllib2,test_cookielib,test_multifile,test_urllib,test_urllib2,test_urllib2net,test_urllib_localnet,test_urllibnet,test_xmlrpc). All uses need to be removed beforethe module can go from Py3K.
benjaminp commentedon May 16, 2008
mimetools.Message is compatible with email.message.Message, right?
brettcannon commentedon May 22, 2008
I don't know how compatible it is.
rhettinger commentedon May 22, 2008
The APIs are bit different, but it should be possible to migrate from
the old to the new. All the key functionality is there.
Barry, any thoughts on transitioning away from the deprecated modules?
hdiogenes commentedon Jun 4, 2008
The only use of mimetools inside cgi is in parse_multipart, which is
untested and has huge warnings like these ones:
"""
XXX This does not parse nested multipart parts -- use FieldStorage for
that.
XXX This should really be subsumed by FieldStorage altogether -- no
point in having two implementations of the same parsing algorithm.
Also, FieldStorage protects itself better against certain DoS attacks
by limiting the size of the data read in one chunk. The API here
does not support that kind of protection. This also affects parse()
since it can call parse_multipart().
"""
hdiogenes commentedon Jun 4, 2008
I'm sending a patch that removes mimetools from urllib and test_urllib. It
now returns an email.message.Message instead of mimetools.Message.
I also moved some imports to the top of the file. If that's a problem, I
can send another patch.
hdiogenes commentedon Jun 4, 2008
It's relatively easy to replace mimetools in most places: it's just a
matter of changing mimetools.Message to email.message_from_file, but it
gets a lot more complicated when there's inheritance involved.
The problem is that mimetools.Message is both a parser and a Message
representation, and AFAIK there's no single class in
emailwhich doesboth -- the functionality is split between the Parser and Message classes.
Inheritance happens in two places:
pydoc.Messageandhttp.client.HTTPMessage, and I couldn't find a solution for thosecases yet. Any help would be appreciated.
rhettinger commentedon Jun 4, 2008
One idea: in http.client.HTTPMessage, inherit from email.Message,
modify the addheaders/addcontinue/readheaders methods to use the
methods in Message. Then, change the instantiation in HTTPResponse to
self.msg = email.parser.Parser(_class=HTTPMessage).parsestr(io.BytesIO
()).
Something similar may apply to pydoc. FYI, I believe there is a
pending discussion about whether to keep pydoc in Py3.0.
hdiogenes commentedon Jun 7, 2008
Attached a patch to rename all calls to the mimetools-specific
.getheader() to .get(), which works on both libraries (mimetools and
email.Message). That eases transition without breaking any tests.
hdiogenes commentedon Jun 7, 2008
As we're moving away from using .getheader() everywhere (file 10538), I
think it's a good time to make HTTPResponse conform to PEP-8 and define
.get_header (with underscore) instead.
rhettinger commentedon Jun 7, 2008
-1 on the get_header() change. I would like this patch to be as
minimal as possible. The new spelling is a bit awkward and it
introduces an unnecessary change that could break code.
2 remaining items
rhettinger commentedon Jun 11, 2008
Barry, can you take a look at this?
Ideally, it should go it before the beta
so it can get thoroughly exercised.
warsaw commentedon Jun 12, 2008
This patch works for me in Python 3.0. It's basically Humberto's patch
with the two failing tests fixed.
warsaw commentedon Jun 12, 2008
Actually, try this one.
warsaw commentedon Jun 12, 2008
r64164 in Python 3.0. This doesn't apply cleanly to Python 2.6; could
someone please back port it?
benjaminp commentedon Jun 12, 2008
On Wed, Jun 11, 2008 at 11:09 PM, Barry A. Warsaw
<report@bugs.python.org> wrote:
Why does it need to be in 2.6? mimetools is still there.
warsaw commentedon Jun 12, 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On Jun 12, 2008, at 8:57 AM, Benjamin Peterson wrote:
I guess you're right, it doesn't.
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (Darwin)
iQCVAwUBSFEfD3EjvBPtnXfVAQKrBwQAoOOjFenHlq0DVEtfeVSuG5/rPWHrzfQw
OwoSlYWa5zkqWqjFdRG780rElbfAjgtz3J7Od8HENxUfsHBvH3bFM0PZCLSQRZMI
UVP8dM1KIcBDOZoQPMoahM1Q7l16iCsayhauWEnJP2MIVje7D/rXO9jjpkQixRyi
3wkfmkNin0k=
=gAB6
-----END PGP SIGNATURE-----
benjaminp commentedon Jun 12, 2008
This is done.
bboissin commentedon Dec 6, 2008
Because it outputs a warning with python2.6 -3, it's annoying for people
trying to port their application to python3k
brettcannon commentedon Dec 6, 2008
Benoit has a good point, so I have opened this issue again so we can get
2.7 even closer to 3.x compatibility.
merwok commentedon Jul 17, 2010
Closing as outdated since 2.7 has been release with some mimetools usage left.