Skip to content
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

Closed
xnovakj mannequin opened this issue Dec 13, 2005 · 6 comments
Closed

email.Header encode() unicode P2.6 #42687

xnovakj mannequin opened this issue Dec 13, 2005 · 6 comments
Assignees
Labels
stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error

Comments

@xnovakj
Copy link
Mannequin

xnovakj mannequin commented Dec 13, 2005

BPO 1379416
Nosy @warsaw, @ezio-melotti, @bitdancer
Files
  • header_encode_test.diff
  • header_charset_fix.diff
  • 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:

    assignee = 'https://github.com/bitdancer'
    closed_at = <Date 2010-12-27.19:18:53.320>
    created_at = <Date 2005-12-13.11:09:30.000>
    labels = ['type-bug', 'library']
    title = 'email.Header encode() unicode P2.6'
    updated_at = <Date 2010-12-27.19:18:53.318>
    user = 'https://bugs.python.org/xnovakj'

    bugs.python.org fields:

    activity = <Date 2010-12-27.19:18:53.318>
    actor = 'r.david.murray'
    assignee = 'r.david.murray'
    closed = True
    closed_date = <Date 2010-12-27.19:18:53.320>
    closer = 'r.david.murray'
    components = ['Library (Lib)']
    creation = <Date 2005-12-13.11:09:30.000>
    creator = 'xnovakj'
    dependencies = []
    files = ['18652', '18653']
    hgrepos = []
    issue_num = 1379416
    keywords = ['patch']
    message_count = 6.0
    messages = ['27063', '84003', '97359', '114997', '115009', '124724']
    nosy_count = 5.0
    nosy_names = ['barry', 'exarkun', 'xnovakj', 'ezio.melotti', 'r.david.murray']
    pr_nums = []
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'behavior'
    url = 'https://bugs.python.org/issue1379416'
    versions = ['Python 2.7']

    @xnovakj
    Copy link
    Mannequin Author

    xnovakj mannequin commented Dec 13, 2005

    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)

    @xnovakj xnovakj mannequin assigned warsaw Dec 13, 2005
    @devdanzin devdanzin mannequin added stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error labels Mar 20, 2009
    @xnovakj
    Copy link
    Mannequin Author

    xnovakj mannequin commented Mar 23, 2009

    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'>

    @xnovakj xnovakj mannequin changed the title email.Header encode() unicode P2.3xP2.4 email.Header encode() unicode P2.6 Mar 23, 2009
    @xnovakj xnovakj mannequin changed the title email.Header encode() unicode P2.3xP2.4 email.Header encode() unicode P2.6 Mar 23, 2009
    @exarkun
    Copy link
    Mannequin

    exarkun mannequin commented Jan 7, 2010

    Any hope of this being fixed?

    @warsaw warsaw assigned bitdancer and unassigned warsaw May 5, 2010
    @BreamoreBoy
    Copy link
    Mannequin

    BreamoreBoy mannequin commented Aug 26, 2010

    I believe that RDM is working on this sort of issue as part of email6.

    @bitdancer
    Copy link
    Member

    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.

    @bitdancer
    Copy link
    Member

    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.

    @ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Labels
    stdlib Python modules in the Lib dir type-bug An unexpected behavior, bug, or error
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants