Some fixes for the --mini option.
* Don't fetch speedtest.net configs when using a custom mini server. It don't makes sense and slows down the whole thing. * Add a mising decode() in the variable data, and set both decodes() to ignore encoding errors.
This commit is contained in:
parent
72da41e4fc
commit
b04887ae1a
|
@ -568,39 +568,41 @@ def speedtest():
|
||||||
source = args.source
|
source = args.source
|
||||||
socket.socket = bound_socket
|
socket.socket = bound_socket
|
||||||
|
|
||||||
if not args.simple:
|
if not args.mini:
|
||||||
print_('Retrieving speedtest.net configuration...')
|
if not args.simple:
|
||||||
try:
|
print_('Retrieving speedtest.net configuration...')
|
||||||
config = getConfig()
|
try:
|
||||||
except URLError:
|
config = getConfig()
|
||||||
print_('Cannot retrieve speedtest configuration')
|
except URLError:
|
||||||
sys.exit(1)
|
print_('Cannot retrieve speedtest configuration')
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
if not args.simple:
|
if not args.mini:
|
||||||
print_('Retrieving speedtest.net server list...')
|
if not args.simple:
|
||||||
if args.list or args.server:
|
print_('Retrieving speedtest.net server list...')
|
||||||
servers = closestServers(config['client'], True)
|
if args.list or args.server:
|
||||||
if args.list:
|
servers = closestServers(config['client'], True)
|
||||||
serverList = []
|
if args.list:
|
||||||
for server in servers:
|
serverList = []
|
||||||
line = ('%(id)4s) %(sponsor)s (%(name)s, %(country)s) '
|
for server in servers:
|
||||||
'[%(d)0.2f km]' % server)
|
line = ('%(id)4s) %(sponsor)s (%(name)s, %(country)s) '
|
||||||
serverList.append(line)
|
'[%(d)0.2f km]' % server)
|
||||||
# Python 2.7 and newer seem to be ok with the resultant encoding
|
serverList.append(line)
|
||||||
# from parsing the XML, but older versions have some issues.
|
# Python 2.7 and newer seem to be ok with the resultant encoding
|
||||||
# This block should detect whether we need to encode or not
|
# from parsing the XML, but older versions have some issues.
|
||||||
try:
|
# This block should detect whether we need to encode or not
|
||||||
unicode()
|
try:
|
||||||
print_('\n'.join(serverList).encode('utf-8', 'ignore'))
|
unicode()
|
||||||
except NameError:
|
print_('\n'.join(serverList).encode('utf-8', 'ignore'))
|
||||||
print_('\n'.join(serverList))
|
except NameError:
|
||||||
except IOError:
|
print_('\n'.join(serverList))
|
||||||
pass
|
except IOError:
|
||||||
sys.exit(0)
|
pass
|
||||||
else:
|
sys.exit(0)
|
||||||
servers = closestServers(config['client'])
|
else:
|
||||||
|
servers = closestServers(config['client'])
|
||||||
|
|
||||||
if not args.simple:
|
if not args.simple and not args.mini:
|
||||||
print_('Testing from %(isp)s (%(ip)s)...' % config['client'])
|
print_('Testing from %(isp)s (%(ip)s)...' % config['client'])
|
||||||
|
|
||||||
if args.server:
|
if args.server:
|
||||||
|
@ -624,9 +626,9 @@ def speedtest():
|
||||||
print_('Invalid Speedtest Mini URL')
|
print_('Invalid Speedtest Mini URL')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
text = f.read()
|
text = f.read().decode(errors="ignore")
|
||||||
f.close()
|
f.close()
|
||||||
extension = re.findall('upload_extension: "([^"]+)"', text.decode())
|
extension = re.findall('upload_extension: "([^"]+)"', text)
|
||||||
if not extension:
|
if not extension:
|
||||||
for ext in ['php', 'asp', 'aspx', 'jsp']:
|
for ext in ['php', 'asp', 'aspx', 'jsp']:
|
||||||
try:
|
try:
|
||||||
|
@ -636,7 +638,7 @@ def speedtest():
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
data = f.read().strip()
|
data = f.read().decode(errors="ignore").strip()
|
||||||
if (f.code == 200 and
|
if (f.code == 200 and
|
||||||
len(data.splitlines()) == 1 and
|
len(data.splitlines()) == 1 and
|
||||||
re.match('size=[0-9]', data)):
|
re.match('size=[0-9]', data)):
|
||||||
|
|
Loading…
Reference in New Issue