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.
Created on 2015年08月05日 15:18 by Sebastian Kreft, last changed 2022年04月11日 14:58 by admin. This issue is now closed.
| Messages (4) | |||
|---|---|---|---|
| msg248047 - (view) | Author: Sebastian Kreft (Sebastian Kreft) | Date: 2015年08月05日 15:18 | |
The return type of email.header.decode_header is not consistent. When there are encoded parts the return type is a list of (bytes, charset or None) (Note that the documentation says it is a list of (str, charset)). However, when there are no encoded parts the return type is [(str, None)]. Note that, at the end of the function, there is a routine that converts everything to bytes.
Compare:
In [01]: email.header.decode_header('=?UTF-8?Q?foo?=bar')
Out[01]: [(b'foo', 'utf-8'), (b'bar', None)]
In [02]: email.header.decode_header('foobar')
Out[02]: [('foobar', None)]
|
|||
| msg248049 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2015年08月05日 15:49 | |
Yeah, don't use that, use the new APIs. |
|||
| msg248734 - (view) | Author: Sebastian Kreft (Sebastian Kreft) | Date: 2015年08月17日 16:05 | |
And what would the new API be? There is nothing pointing to it either in the documentation https://docs.python.org/3.4/library/email.header.html or source code. |
|||
| msg248735 - (view) | Author: R. David Murray (r.david.murray) * (Python committer) | Date: 2015年08月17日 16:10 | |
Right, it's provisional in 3.4. I'm working on the doc rewrite now (although I suppose there's a chance it won't get accepted for 3.5, I expect it to). Take a look at https://docs.python.org/3/library/email.policy.html. Basically, if you use EmailMessage instead of Message (and therefore policy.default instead of policy.compat32) header parsing and decoding is handled for you. |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022年04月11日 14:58:19 | admin | set | github: 68985 |
| 2019年06月03日 09:30:24 | SilentGhost | link | issue37139 superseder |
| 2015年08月17日 16:10:37 | r.david.murray | set | messages: + msg248735 |
| 2015年08月17日 16:05:45 | Sebastian Kreft | set | messages: + msg248734 |
| 2015年08月05日 15:49:44 | r.david.murray | set | status: open -> closed superseder: email.header.decode_header sometimes returns bytes, sometimes str messages: + msg248049 resolution: duplicate stage: resolved |
| 2015年08月05日 15:31:06 | serhiy.storchaka | set | nosy:
+ barry, r.david.murray type: behavior components: + email |
| 2015年08月05日 15:18:45 | Sebastian Kreft | create | |