Skip to content

Remove mimetools usage from the stdlib #47097

Closed

Description

@brettcannon
BPO 2848
Nosy @warsaw, @brettcannon, @rhettinger, @hdiogenes, @benjaminp, @merwok
Files
  • remove_mimetools_from_urllib.patch: Remove mimetools from (test_)urllib (updated)
  • email.parser-small_fix.patch: Simple patch to remove outdated workaround from email Parser
  • replace_getheaders_by_get.patch: Start using methods compatible with both mimetools and email.Message
  • rename_HTTPResponse.getheaders.patch: Suggestion: rename HTTPResponse.getheader() to .get_header()
  • remove_mimetools_from_http.client.patch: Breaks tests because FeedParser closes the socket.
  • remove_mimetools.patch: Completely removes dependencies on mimetools (but breaks two tests).
  • applied_mimetools.patch
  • 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']

    Activity

    1. brettcannon commented on May 14, 2008

      @brettcannon
      MemberAuthor

      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 before
      the module can go from Py3K.

    2. added
      stdlibStandard Library Python modules in the Lib/ directory
      type-bugAn unexpected behavior, bug, or error
      on May 14, 2008
    3. benjaminp commented on May 16, 2008

      @benjaminp
      Contributor

      mimetools.Message is compatible with email.message.Message, right?

    4. brettcannon commented on May 22, 2008

      @brettcannon
      MemberAuthor

      I don't know how compatible it is.

    5. rhettinger commented on May 22, 2008

      @rhettinger
      Contributor

      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?

    6. hdiogenes commented on Jun 4, 2008

      hdiogenesmannequin
      Mannequin

      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().
      """

    7. hdiogenes commented on Jun 4, 2008

      hdiogenesmannequin
      Mannequin

      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.

    8. hdiogenes commented on Jun 4, 2008

      hdiogenesmannequin
      Mannequin

      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 email which does
      both -- the functionality is split between the Parser and Message classes.

      Inheritance happens in two places: pydoc.Message and
      http.client.HTTPMessage, and I couldn't find a solution for those
      cases yet. Any help would be appreciated.

    9. rhettinger commented on Jun 4, 2008

      @rhettinger
      Contributor

      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.

    10. hdiogenes commented on Jun 7, 2008

      hdiogenesmannequin
      Mannequin

      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.

    11. hdiogenes commented on Jun 7, 2008

      hdiogenesmannequin
      Mannequin

      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.

    12. rhettinger commented on Jun 7, 2008

      @rhettinger
      Contributor

      -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.

    13. 2 remaining items

    14. rhettinger commented on Jun 11, 2008

      @rhettinger
      Contributor

      Barry, can you take a look at this?
      Ideally, it should go it before the beta
      so it can get thoroughly exercised.

    15. warsaw commented on Jun 12, 2008

      @warsaw
      Member

      This patch works for me in Python 3.0. It's basically Humberto's patch
      with the two failing tests fixed.

    16. warsaw commented on Jun 12, 2008

      @warsaw
      Member

      Actually, try this one.

    17. warsaw commented on Jun 12, 2008

      @warsaw
      Member

      r64164 in Python 3.0. This doesn't apply cleanly to Python 2.6; could
      someone please back port it?

    18. benjaminp commented on Jun 12, 2008

      @benjaminp
      Contributor

      On Wed, Jun 11, 2008 at 11:09 PM, Barry A. Warsaw
      <report@bugs.python.org> wrote:

      Barry A. Warsaw <barry@python.org> added the comment:

      r64164 in Python 3.0. This doesn't apply cleanly to Python 2.6; could
      someone please back port it?

      Why does it need to be in 2.6? mimetools is still there.

    19. warsaw commented on Jun 12, 2008

      @warsaw
      Member

      -----BEGIN PGP SIGNED MESSAGE-----
      Hash: SHA1

      On Jun 12, 2008, at 8:57 AM, Benjamin Peterson wrote:

      Benjamin Peterson <musiccomposition@gmail.com> added the comment:

      On Wed, Jun 11, 2008 at 11:09 PM, Barry A. Warsaw
      <report@bugs.python.org> wrote:
      >
      > Barry A. Warsaw <barry@python.org> added the comment:
      >
      > r64164 in Python 3.0. This doesn't apply cleanly to Python 2.6;
      > could
      > someone please back port it?

      Why does it need to be in 2.6? mimetools is still there.

      I guess you're right, it doesn't.

      • -Barry

      -----BEGIN PGP SIGNATURE-----
      Version: GnuPG v1.4.9 (Darwin)

      iQCVAwUBSFEfD3EjvBPtnXfVAQKrBwQAoOOjFenHlq0DVEtfeVSuG5/rPWHrzfQw
      OwoSlYWa5zkqWqjFdRG780rElbfAjgtz3J7Od8HENxUfsHBvH3bFM0PZCLSQRZMI
      UVP8dM1KIcBDOZoQPMoahM1Q7l16iCsayhauWEnJP2MIVje7D/rXO9jjpkQixRyi
      3wkfmkNin0k=
      =gAB6
      -----END PGP SIGNATURE-----

    20. benjaminp commented on Jun 12, 2008

      @benjaminp
      Contributor

      This is done.

    21. bboissin commented on Dec 6, 2008

      bboissinmannequin
      Mannequin

      Why does it need to be in 2.6? mimetools is still there.

      Because it outputs a warning with python2.6 -3, it's annoying for people
      trying to port their application to python3k

    22. brettcannon commented on Dec 6, 2008

      @brettcannon
      MemberAuthor

      Benoit has a good point, so I have opened this issue again so we can get
      2.7 even closer to 3.x compatibility.

    23. merwok commented on Jul 17, 2010

      @merwok
      Member

      Closing as outdated since 2.7 has been release with some mimetools usage left.

    24. transferred this issue fromon Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions