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