Skip to content

Commit 81b91ee

Browse files
committed
fix logger unicode errors on py2
1 parent 5ed46a7 commit 81b91ee

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

pythonforandroid/logger.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,12 @@ def shorten_string(string, max_width):
9292
return string
9393
visible = max_width - 16 - int(log10(string_len))
9494
# expected suffix len "...(and XXXXX more)"
95-
return u''.join((string[:visible], u'...(and ', str(string_len - visible),
96-
u' more)'))
95+
if not isinstance(string, unistr):
96+
visstring = unistr(string[:visible], errors='ignore')
97+
else:
98+
visstring = string[:visible]
99+
return u''.join((visstring, u'...(and ',
100+
unistr(string_len - visible), u' more)'))
97101

98102

99103
def get_console_width():
@@ -204,3 +208,6 @@ def printtail(out, name, forecolor, tail_n=0,
204208
raise
205209

206210
return output
211+
212+
213+
from pythonforandroid.util import unistr

pythonforandroid/util.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
IS_PY3 = sys.version_info[0] >= 3
1717

18+
if IS_PY3:
19+
unistr = str
20+
else:
21+
unistr = unicode
22+
1823

1924
class ChromeDownloader(FancyURLopener):
2025
version = (

0 commit comments

Comments
 (0)