From bcd7ba792889ab804e8c312535afdfd17474b10f Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Thu, 8 Sep 2011 16:03:09 -0400 Subject: [PATCH] Adjust encoding detection (using sys.getfilesystemencoding for file contents). --- libbe/util/encoding.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libbe/util/encoding.py b/libbe/util/encoding.py index 22a2e30..3fde8cb 100644 --- a/libbe/util/encoding.py +++ b/libbe/util/encoding.py @@ -41,19 +41,22 @@ def get_encoding(): if ENCODING != None: return ENCODING encoding = locale.getpreferredencoding() or sys.getdefaultencoding() - if sys.platform != 'win32' or sys.version_info[:2] > (2, 3): - encoding = locale.getlocale(locale.LC_TIME)[1] or encoding - # Python 2.3 on windows doesn't know about 'XYZ' alias for 'cpXYZ' return encoding def get_input_encoding(): - return get_encoding() + return sys.__stdin__.encoding or get_encoding() def get_output_encoding(): return sys.__stdout__.encoding or get_encoding() def get_filesystem_encoding(): - return get_encoding() + """Return the encoding that should be used for file contents + + Note that `sys.getfilesystemencoding` returns the prefered + encoding for file *names*, and we're assuming that this is also + the prefered encoding for their contents. + """ + return sys.getfilesystemencoding() or get_encoding() def get_argv_encoding(): return get_encoding() -- 2.26.2