Fix output of unicode strings with Python 3

This commit is contained in:
Louis Sautier 2016-02-14 19:52:25 +01:00
parent 7b09d8759f
commit 9b735542ed
No known key found for this signature in database
GPG Key ID: 2CDF7FDA862B29FB
1 changed files with 5 additions and 3 deletions

View File

@ -108,6 +108,8 @@ except ImportError:
def write(data): def write(data):
if not isinstance(data, basestring): if not isinstance(data, basestring):
data = str(data) data = str(data)
if isinstance(data, unicode):
data = data.encode('utf-8', 'ignore')
fp.write(data) fp.write(data)
want_unicode = False want_unicode = False
@ -635,7 +637,7 @@ def speedtest():
line = ('%(id)4s) %(sponsor)s (%(name)s, %(country)s) ' line = ('%(id)4s) %(sponsor)s (%(name)s, %(country)s) '
'[%(d)0.2f km]' % server) '[%(d)0.2f km]' % server)
serverList.append(line) serverList.append(line)
print_('\n'.join(serverList).encode('utf-8', 'ignore')) print_('\n'.join(serverList))
sys.exit(0) sys.exit(0)
else: else:
servers = closestServers(config['client']) servers = closestServers(config['client'])
@ -703,8 +705,8 @@ def speedtest():
best = getBestServer(servers) best = getBestServer(servers)
if not args.simple: if not args.simple:
print_(('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: ' print_('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
'%(latency)s ms' % best).encode('utf-8', 'ignore')) '%(latency)s ms' % best)
else: else:
print_('Ping: %(latency)s ms' % best) print_('Ping: %(latency)s ms' % best)