From: W. Trevor King Date: Thu, 8 Sep 2011 20:03:09 +0000 (-0400) Subject: Adjust encoding detection (using sys.getfilesystemencoding for file contents). X-Git-Tag: 1.1.0~175^2~5 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=bcd7ba792889ab804e8c312535afdfd17474b10f;p=be.git Adjust encoding detection (using sys.getfilesystemencoding for file contents). --- 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()