This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author abbeyj
Recipients abbeyj, mrabarnett, vstinner
Date 2009-07-31.18:02:47
SpamBayes Score 1.0314241e-08
Marked as misclassified No
Message-id <1249063369.43.0.0234458666003.issue5093@psf.upfronthosting.co.za>
In-reply-to
Content
In what case(s) do you propose the output to be encoded in UTF-8?  If
output is to a terminal and that terminal is set to Latin-1 or cp437 or
whatever then outputting UTF-8 in that case will only show garbage
characters to the user.

If output is to a file then using the encoding of the input file makes
the most sense to me.  Assume you have a simple program encoded in
Latin-1 that prints out a string with some non-ASCII characters.  The
patch is printed in UTF-8 encoding and redirected to a file.  The patch
program has no idea what encodings are used and it will just compare the
bytes in the original to the bytes in the patch file.  These won't match
since the encodings are different and he patch will fail.

If the output is to a pipe then I'm not sure what the right thing is. 
It may be intended for display on the screen with something like `less`
or it may not.  I don't think there's a good solution for this.

So following the above logic the patch attached here does the following:
1) If output is to a terminal (sys.stdout.encoding is set) then use that
encoding for output
2) Otherwise if an encoding was determined for the input file, use that
encoding for output
3) If all else fails, use 'ascii' encoding.  If the input contained
non-ASCII characters and no encoding has been determined for the input
then this will cause an exception to be raised.  I think this can only
happen when reading the input file from stdin.  Perhaps that case needs
to be looked at for how to detect the encoding of stdin.
History
Date User Action Args
2009-07-31 18:02:50abbeyjsetrecipients: + abbeyj, vstinner, mrabarnett
2009-07-31 18:02:49abbeyjsetmessageid: <1249063369.43.0.0234458666003.issue5093@psf.upfronthosting.co.za>
2009-07-31 18:02:48abbeyjlinkissue5093 messages
2009-07-31 18:02:47abbeyjcreate