Akira Li added the comment: > Akira, your patch does this: > > - self._writetranslate = newline != '' > - self._writenl = newline or os.linesep > + self._writetranslate = newline in (None, '\r', '\r\n') > + self._writenl = newline if newline is not None else os.linesep > > Any reason you made the second change? Why change the value assigned > to _writenl for newline='\n' when you don't want to actually change > the behavior for those cases? Just so you can double-check at write > time that _writetranslate is never set unless _writenl is '\r', > \r\n', or os.linesep?
If newline='\n' then writenl is '\n' with and without the patch. If newline='\n' then write('\n\r') writes '\n\r' with and without the patch. If newline='\n' then writetranslate=False (with the patch). It does not change the result for newline='\n' as it is documented now [1]: [newline] can be None, '', '\n', '\r', and '\r\n'. ... If newline is any of the other legal values [namely '\r', '\n', '\r\n'], any '\n' characters written are translated to the given string. [...] are added by me for clarity. [1] https://docs.python.org/3.4/library/io.html#io.TextIOWrapper writetranslate=False so that if newline='\0' then write('\0\n') would write '\0\n' i.e., embed '\n' are not corrupted if newline='\0'. That is why it is the "no translation" patch: + When writing output to the stream: + + - if newline is None, any '\n' characters written are translated to + the system default line separator, os.linesep + - if newline is '\r' or '\r\n', any '\n' characters written are + translated to the given string + - no translation takes place for any other newline value [any string]. ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue1152248> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com