From: Niall Douglas (s [underscore] sourceforge {at} nedprod [dot] com) Date: Mon, 20 Feb 2012 15:34:59 +0000 (+0000) Subject: Added BE_INPUT_ENCODING and BE_OUTPUT_ENCODING to allow charset for stdin and stdout... X-Git-Tag: 1.1.0~153 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=323da0a602bb689eecd6137dc3c676b3360a92b9;p=be.git Added BE_INPUT_ENCODING and BE_OUTPUT_ENCODING to allow charset for stdin and stdout to be overridden. This is necessary on Windows as there is no way for external programs to set stdin or stdout charsets :( --- diff --git a/libbe/util/encoding.py b/libbe/util/encoding.py index ee51993..a33678f 100644 --- a/libbe/util/encoding.py +++ b/libbe/util/encoding.py @@ -34,6 +34,10 @@ if libbe.TESTING == True: ENCODING = os.environ.get('BE_ENCODING', None) "override get_encoding() output" +INPUT_ENCODING = os.environ.get('BE_INPUT_ENCODING', None) +"override get_input_encoding() output" +OUTPUT_ENCODING = os.environ.get('BE_OUTPUT_ENCODING', None) +"override get_output_encoding() output" def get_encoding(): """ @@ -46,9 +50,13 @@ def get_encoding(): return encoding def get_input_encoding(): + if INPUT_ENCODING != None: + return INPUT_ENCODING return sys.__stdin__.encoding or get_encoding() def get_output_encoding(): + if OUTPUT_ENCODING != None: + return OUTPUT_ENCODING return sys.__stdout__.encoding or get_encoding() def get_text_file_encoding():