Issue1379416
Created on 2005-12-13 11:09 by xnovakj, last changed 2009-03-23 10:12 by xnovakj.
|
msg27063 - (view) |
Author: Jan Novak (xnovakj) |
Date: 2005-12-13 11:09 |
|
Python: 2.4
Module: email.Header
Method: encode()
In some cases returns unicode (example on line 5)
1>> from email.Header import Header
2>> Header(unicode('abcá','iso-8859-2'),'utf-8').encode()
'=?utf-8?b?YWJjw6E=?='
3>> Header('abc','utf-8').encode()
'=?utf-8?q?abc?='
4>> Header(u'abc','utf-8').encode()
'abc' ???
5>> Header('abc','iso-8859-2').encode()
u'=?iso-8859-2?q?abc?=' (P2.4)
6>> Header('abc','iso-8859-2').encode()
'=?iso-8859-2?q?abc?=' (P2.3)
|
|
msg84003 - (view) |
Author: Jan Novak (xnovakj) |
Date: 2009-03-23 10:12 |
|
I made some new tests in P2.6.1
>>> import email.charset
>>> 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:
self.input_charset->conv->self.output_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
input_charset = unicode(input_charset, 'ascii')
because this construction returns unicode
>>> print type(unicode('iso-8859-2','ascii'))
<type 'unicode'>
|
|
| Date |
User |
Action |
Args |
| 2009-03-30 22:56:23 | ajaksu2 | link | issue1685453 dependencies |
| 2009-03-23 10:12:25 | xnovakj | set | messages:
+ msg84003 title: email.Header encode() unicode P2.3xP2.4 -> email.Header encode() unicode P2.6 |
| 2009-03-20 23:31:10 | ajaksu2 | set | stage: test needed type: behavior components:
+ Library (Lib), - None versions:
+ Python 2.6 |
| 2005-12-13 11:09:30 | xnovakj | create | |
|