From 81b91ee00fda45c453a92ef3909b80dcc8e71578 Mon Sep 17 00:00:00 2001 From: Ryan Pessa Date: Fri, 8 Jan 2016 13:19:39 -0600 Subject: [PATCH] fix logger unicode errors on py2 --- pythonforandroid/logger.py | 11 +++++++++-- pythonforandroid/util.py | 5 +++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/pythonforandroid/logger.py b/pythonforandroid/logger.py index d3ab179ef9..1f8871fdd7 100644 --- a/pythonforandroid/logger.py +++ b/pythonforandroid/logger.py @@ -92,8 +92,12 @@ def shorten_string(string, max_width): return string visible = max_width - 16 - int(log10(string_len)) # expected suffix len "...(and XXXXX more)" - return u''.join((string[:visible], u'...(and ', str(string_len - visible), - u' more)')) + if not isinstance(string, unistr): + visstring = unistr(string[:visible], errors='ignore') + else: + visstring = string[:visible] + return u''.join((visstring, u'...(and ', + unistr(string_len - visible), u' more)')) def get_console_width(): @@ -204,3 +208,6 @@ def printtail(out, name, forecolor, tail_n=0, raise return output + + +from pythonforandroid.util import unistr diff --git a/pythonforandroid/util.py b/pythonforandroid/util.py index a2218c9c27..400bd28092 100644 --- a/pythonforandroid/util.py +++ b/pythonforandroid/util.py @@ -15,6 +15,11 @@ IS_PY3 = sys.version_info[0] >= 3 +if IS_PY3: + unistr = str +else: + unistr = unicode + class ChromeDownloader(FancyURLopener): version = (