This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author r.david.murray
Recipients barry, flox, janssen, martin.panter, mgiuca, orsenthil, r.david.murray
Date 2015-02-18.23:06:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1424300765.01.0.781603670866.issue3609@psf.upfronthosting.co.za>
In-reply-to
Content
There is no reason to move this to the email package.  email can already parse headers just fine.  It might be useful to have a parse_header utility method, though, since currently the easiest way to parse a single header using the email package is:

  >>> from email.policy import HTTP
  >>> from email.parser import Parser
  >>> m = Parser(policy=HTTP).parsestr('Content-Type: text/plain; filename="foo"\n\n')
  >>> m['Content-Type'].content_type
  'text/plain'
  >>> m['Content-type'].params
  mappingproxy({'filename': 'foo'})

Which isn't as straightforward as the parse_header API when you are only interested in a single header.

It might also be useful to have the email MIME headers grow a 'value' attribute to return whatever the value is (in this case, text/plain), so it can be accessed regardless of the header type.

I would make parse_header be a utility method of the policy, I think.  Then the email API would be:

  from email.policy import HTTP
  h = HTTP.parse_header('Content-Type: ...')
  value, params = h.value, h.params

It would then be trivial to implement the backward compatibility shim for the CGI parse_header method using the above.
History
Date User Action Args
2015-02-18 23:06:05r.david.murraysetrecipients: + r.david.murray, barry, janssen, orsenthil, mgiuca, flox, martin.panter
2015-02-18 23:06:05r.david.murraysetmessageid: <1424300765.01.0.781603670866.issue3609@psf.upfronthosting.co.za>
2015-02-18 23:06:04r.david.murraylinkissue3609 messages
2015-02-18 23:06:04r.david.murraycreate