classification
Title: email.encoders.encode7or8bit does not work with binary data
Type: behavior Stage: resolved
Components: email Versions: Python 3.2, Python 3.3, Python 3.4
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: barry, python-dev, r.david.murray
Priority: normal Keywords:

Created on 2013-02-09 18:19 by r.david.murray, last changed 2013-02-11 16:21 by r.david.murray. This issue is now closed.

Messages (3)
msg181748 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-02-09 18:19
Reported by Serhiy in issue 16564:


>>> import io, email
>>> bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'
>>> msg = email.mime.application.MIMEApplication(bytesdata, _encoder=encoders.encode_7or8bit)
>>> s = io.BytesIO()
>>> g = email.generator.BytesGenerator(s)
>>> g.flatten(msg)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/serhiy/py/cpython3.2/Lib/email/generator.py", line 91, in flatten
    self._write(msg)
  File "/home/serhiy/py/cpython3.2/Lib/email/generator.py", line 137, in _write
    self._dispatch(msg)
  File "/home/serhiy/py/cpython3.2/Lib/email/generator.py", line 163, in _dispatch
    meth(msg)
  File "/home/serhiy/py/cpython3.2/Lib/email/generator.py", line 393, in _handle_text
    if _has_surrogates(msg._payload):
TypeError: can't use a string pattern on a bytes-like object
msg181905 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-02-11 16:19
New changeset f83581135ec4 by R David Murray in branch '3.2':
#17171: fix email.encoders.encode_7or8bit when applied to binary data.
http://hg.python.org/cpython/rev/f83581135ec4

New changeset cabcddbed377 by R David Murray in branch '3.3':
Merge: #17171: fix email.encoders.encode_7or8bit when applied to binary data.
http://hg.python.org/cpython/rev/cabcddbed377

New changeset a80b67611c6d by R David Murray in branch 'default':
Merge: #17171: fix email.encoders.encode_7or8bit when applied to binary data.
http://hg.python.org/cpython/rev/a80b67611c6d

New changeset e44fa71d76fe by R David Murray in branch '2.7':
#17171: backport behavior-confirming test from python3.
http://hg.python.org/cpython/rev/e44fa71d76fe
msg181906 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-02-11 16:21
Since this was straightforwardly similar to the issue 16564 fix I didn't bother with a review.  The 2.7 commit is backporting the behavior-confirming test, just for thoroughness.
History
Date User Action Args
2013-02-11 16:21:56r.david.murraysetstatus: open -> closed
resolution: fixed
messages: + msg181906

stage: needs patch -> resolved
2013-02-11 16:19:59python-devsetnosy: + python-dev
messages: + msg181905
2013-02-11 15:36:04r.david.murraysettype: behavior
2013-02-09 18:19:45r.david.murraycreate