http://www.mediawiki.org/wiki/Special:Code/pywikipedia/10046
Revision: 10046 Author: valhallasw Date: 2012-03-26 08:10:48 +0000 (Mon, 26 Mar 2012) Log Message: ----------- - Consistent use of self.encoding fixes output on unix (without colors) and input on windows (when config.encoding != 'utf-8') - Removed double readline from win32 _raw_input
Modified Paths: -------------- trunk/pywikipedia/userinterfaces/terminal_interface_base.py trunk/pywikipedia/userinterfaces/terminal_interface_unix.py trunk/pywikipedia/userinterfaces/terminal_interface_win32.py
Modified: trunk/pywikipedia/userinterfaces/terminal_interface_base.py =================================================================== --- trunk/pywikipedia/userinterfaces/terminal_interface_base.py 2012-03-26 00:17:53 UTC (rev 10045) +++ trunk/pywikipedia/userinterfaces/terminal_interface_base.py 2012-03-26 08:10:48 UTC (rev 10046) @@ -39,6 +39,7 @@ self.stdin = sys.stdin self.stdout = sys.stdout self.stderr = sys.stderr + self.encoding = config.console_encoding
def printNonColorized(self, text, targetStream): # We add *** after the text as a whole if anything needed to be colorized. @@ -68,7 +69,7 @@ # Encode our unicode string in the encoding used by the user's console, # and decode it back to unicode. Then we can see which characters # can't be represented in the console encoding. - codecedText = text.encode(config.console_encoding, 'replace').decode(config.console_encoding) + codecedText = text.encode(self.encoding, 'replace').decode(self.encoding) transliteratedText = '' # Note: A transliteration replacement might be longer than the original # character, e.g. ч is transliterated to ch. @@ -122,7 +123,7 @@ text = getpass.getpass('') else: text = self._raw_input() - text = unicode(text, config.console_encoding) + text = unicode(text, self.encoding) return text
def inputChoice(self, question, options, hotkeys, default = None):
Modified: trunk/pywikipedia/userinterfaces/terminal_interface_unix.py =================================================================== --- trunk/pywikipedia/userinterfaces/terminal_interface_unix.py 2012-03-26 00:17:53 UTC (rev 10045) +++ trunk/pywikipedia/userinterfaces/terminal_interface_unix.py 2012-03-26 08:10:48 UTC (rev 10046) @@ -45,4 +45,4 @@ # just to be sure, reset the color text += unixColors['default']
- targetStream.write(text.encode(config.console_encoding, 'replace')) + targetStream.write(text.encode(self.encoding, 'replace'))
Modified: trunk/pywikipedia/userinterfaces/terminal_interface_win32.py =================================================================== --- trunk/pywikipedia/userinterfaces/terminal_interface_win32.py 2012-03-26 00:17:53 UTC (rev 10045) +++ trunk/pywikipedia/userinterfaces/terminal_interface_win32.py 2012-03-26 08:10:48 UTC (rev 10046) @@ -87,7 +87,7 @@ data = self.stdin.readline() if '\x1a' in data: raise EOFError() - return self.stdin.readline().strip() + return data.strip()
if ctypes_found: Win32UI = Win32CtypesUI