New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
email.Header encode() unicode P2.6 #42687
Comments
Python: 2.4 1>> from email.Header import Header 2>> Header(unicode('abcá','iso-8859-2'),'utf-8').encode() 3>> Header('abc','utf-8').encode() 4>> Header(u'abc','utf-8').encode() 5>> Header('abc','iso-8859-2').encode() 6>> Header('abc','iso-8859-2').encode() |
I made some new tests in P2.6.1
>>> c=email.charset.Charset('utf-8')
>>> print c.input_charset, type(c.input_charset)
utf-8 <type 'unicode'>
>>> print c.output_charset, type(c.output_charset)
utf-8 <type 'str'> but >>> c=email.charset.Charset('iso-8859-2')
>>> print c.input_charset, type(c.input_charset)
iso-8859-2 <type 'unicode'>
>>> print c.output_charset, type(c.output_charset)
iso-8859-2 <type 'unicode'> but if you use alias latin-2 it's OK >>> c=email.charset.Charset('latin-2')
>>> print c.input_charset, type(c.input_charset)
iso-8859-2 <type 'str'>
>>> print c.output_charset, type(c.output_charset)
iso-8859-2 <type 'str'>
>>> Error is here for unicode input-charset: module email/charset.py line 219 if not conv:
conv = self.input_charset for the charsets where aren't output conversions CHARSETS = {
# input header enc body enc output conv
'iso-8859-1': (QP, QP, None),
'iso-8859-2': (QP, QP, None), and if you don't use alias ALIASES = {
'latin_1': 'iso-8859-1',
'latin-1': 'iso-8859-1',
'latin_2': 'iso-8859-2',
'latin-2': 'iso-8859-2', But the realy source of this error is on line 208 because this construction returns unicode >>> print type(unicode('iso-8859-2','ascii'))
<type 'unicode'> |
Any hope of this being fixed? |
I believe that RDM is working on this sort of issue as part of email6. |
I've attached a fix and test. I've uploaded them separately since the fix only applies to 2.7, but I want to put the test into 3.x as well. |
Committed to 2.7 in r87515. On second thought there's no reason to forward port the test because Python3 doesn't have the equivalent type-promotion issues. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: