From 56b6bf72f440a40cb0c58a2552b721bf5f437a8d Mon Sep 17 00:00:00 2001 From: Miroslav Stampar Date: Sat, 29 Nov 2014 23:33:24 +0100 Subject: [PATCH] Patch for an Issue #978 --- lib/core/common.py | 5 ++++- lib/core/convert.py | 10 +++++++--- lib/parse/cmdline.py | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/core/common.py b/lib/core/common.py index f954af023..4b40747a0 100755 --- a/lib/core/common.py +++ b/lib/core/common.py @@ -2068,7 +2068,10 @@ def getUnicode(value, encoding=None, noneToNull=False): try: return unicode(value, encoding or kb.get("pageEncoding") or UNICODE_ENCODING) except UnicodeDecodeError, ex: - value = value[:ex.start] + "".join(INVALID_UNICODE_CHAR_FORMAT % ord(_) for _ in value[ex.start:ex.end]) + value[ex.end:] + try: + return unicode(value, UNICODE_ENCODING) + except: + value = value[:ex.start] + "".join(INVALID_UNICODE_CHAR_FORMAT % ord(_) for _ in value[ex.start:ex.end]) + value[ex.end:] else: try: return unicode(value) diff --git a/lib/core/convert.py b/lib/core/convert.py index d0646e21b..5979c9d91 100644 --- a/lib/core/convert.py +++ b/lib/core/convert.py @@ -145,17 +145,21 @@ def htmlunescape(value): return retVal def singleTimeWarnMessage(message): # Cross-linked function - raise NotImplementedError + sys.stdout.write(message) + sys.stdout.write("\n") + sys.stdout.flush() def stdoutencode(data): retVal = None try: + data = data or "" + # Reference: http://bugs.python.org/issue1602 if IS_WIN: - output = data.encode("ascii", "replace") + output = data.encode(sys.stdout.encoding, "replace") - if output != data: + if '?' in output: warnMsg = "cannot properly display Unicode characters " warnMsg += "inside Windows OS command prompt " warnMsg += "(http://bugs.python.org/issue1602). All " diff --git a/lib/parse/cmdline.py b/lib/parse/cmdline.py index 81fade009..c916b3278 100644 --- a/lib/parse/cmdline.py +++ b/lib/parse/cmdline.py @@ -791,7 +791,7 @@ def cmdLineParser(): advancedHelp = True for arg in sys.argv: - argv.append(getUnicode(arg, encoding=sys.stdin.encoding)) + argv.append(getUnicode(arg, encoding=sys.getfilesystemencoding())) checkDeprecatedOptions(argv)