# HG changeset patch # User Paul Boddie # Date 1481668194 -3600 # Node ID 18c564471d4a7df9674ac32ea5eba8aba5e0aaad # Parent 9e1d8b186e5c7710895ba1e9b0b02f26b8c0f0b0 Support encoding to streams using the original encoding of Unicode objects if no stream encoding is set. diff -r 9e1d8b186e5c -r 18c564471d4a lib/__builtins__/file.py --- a/lib/__builtins__/file.py Tue Dec 13 23:28:09 2016 +0100 +++ b/lib/__builtins__/file.py Tue Dec 13 23:29:54 2016 +0100 @@ -76,9 +76,10 @@ check_string(s) - # Encode text as bytes if necessary. + # Encode text as bytes if necessary. When the encoding is not set, any + # original encoding of the text will be applied. - if self.encoding and _isinstance(s, utf8string): + if _isinstance(s, utf8string): s = s.encode(self.encoding) fwrite(self.__data__, s)