[issue20121] quopri_codec newline handling

2015-01-19 Thread Martin Panter
Martin Panter added the comment: Here is patch v2, which fixes some more bugs I uncovered in the quoted-printable encoders: * The binascii version would unnecessarily break a 76-character line (maximum length) if it would end with an =XX escape code * The native Python version would insert sof

[issue20121] quopri_codec newline handling

2015-01-17 Thread Martin Panter
Martin Panter added the comment: Here is a patch that clarifies in the documentation and test suite how newlines work in the “quopri” and “binascii” modules. It also fixes the native Python implementation to support CRLFs. * \n is used by default (e.g. for soft line breaks if the input has no

[issue20121] quopri_codec newline handling

2014-12-17 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Pure Python implementation returns different result. >>> import quopri >>> quopri.encodestring(b'\r\n') b'\r\n' >>> quopri.a2b_qp = quopri.b2a_qp = None >>> quopri.encodestring(b'\r\n') b'=0D\n' See also issue18022. -- nosy: +serhiy.storchaka __

[issue20121] quopri_codec newline handling

2014-12-17 Thread Martin Panter
Martin Panter added the comment: Okay so maybe the documentation should include these restrictions on encoding: * The data being encoded should only include \r or \n bytes that are part of \n or \r\n newline sequences. Encoding arbitrary non-text data is not supported. * The two kinds of newlin

[issue20121] quopri_codec newline handling

2014-12-17 Thread Marc-Andre Lemburg
Marc-Andre Lemburg added the comment: I agree with Vajrasky: a patch for the documentation would probably be a good idea. Note that mixing line end conventions in a single text is never a good idea. If you stick to one line end convention, there's no problem with the codec, AFAICT. >>> codecs

[issue20121] quopri_codec newline handling

2014-12-17 Thread Martin Panter
Martin Panter added the comment: RFC 1521 says that a text newline should be encoded as CRLF, and that any combination of 0x0D and 0x0A bytes that do not represent newlines should be encoded like other control characters as =0D and =0A. Since in Python 3 the codec outputs bytes, I don’t think

[issue20121] quopri_codec newline handling

2014-01-05 Thread Vajrasky Kok
Vajrasky Kok added the comment: The quopri_codec uses binascii.b2a_qp method. >>> binascii.b2a_qp('\r\n\n\n\n') '\r\n\r\n\r\n\r\n' The logic in b2a_qp when dealing with newlines is check whether the first line uses \r\n or \n. If it uses \r\n, then all remaning lines' new lines will be conver

[issue20121] quopri_codec newline handling

2014-01-04 Thread R. David Murray
Changes by R. David Murray : -- nosy: +r.david.murray ___ Python tracker ___ ___ Python-bugs-list mailing list Unsubscribe: https://m

[issue20121] quopri_codec newline handling

2014-01-04 Thread Fred Stober
New submission from Fred Stober: While trying to encode some binary data, I encountered this behaviour of the quopri_codec: >>> '\r\n\n'.encode('quopri_codec').decode('quopri_codec') '\r\n\r\n' >>> '\n\r\n'.encode('quopri_codec').decode('quopri_codec') '\n\n' If this behaviour is really intend