If we got bogus XML that can't be parsed, provide a better error message instead of a trace. Fixes #77
This commit is contained in:
parent
c0cd0d1666
commit
3558b22de1
|
@ -315,19 +315,23 @@ def getConfig():
|
||||||
return None
|
return None
|
||||||
uh.close()
|
uh.close()
|
||||||
try:
|
try:
|
||||||
root = ET.fromstring(''.encode().join(configxml))
|
try:
|
||||||
config = {
|
root = ET.fromstring(''.encode().join(configxml))
|
||||||
'client': root.find('client').attrib,
|
config = {
|
||||||
'times': root.find('times').attrib,
|
'client': root.find('client').attrib,
|
||||||
'download': root.find('download').attrib,
|
'times': root.find('times').attrib,
|
||||||
'upload': root.find('upload').attrib}
|
'download': root.find('download').attrib,
|
||||||
except AttributeError:
|
'upload': root.find('upload').attrib}
|
||||||
root = DOM.parseString(''.join(configxml))
|
except AttributeError:
|
||||||
config = {
|
root = DOM.parseString(''.join(configxml))
|
||||||
'client': getAttributesByTagName(root, 'client'),
|
config = {
|
||||||
'times': getAttributesByTagName(root, 'times'),
|
'client': getAttributesByTagName(root, 'client'),
|
||||||
'download': getAttributesByTagName(root, 'download'),
|
'times': getAttributesByTagName(root, 'times'),
|
||||||
'upload': getAttributesByTagName(root, 'upload')}
|
'download': getAttributesByTagName(root, 'download'),
|
||||||
|
'upload': getAttributesByTagName(root, 'upload')}
|
||||||
|
except SyntaxError:
|
||||||
|
print_('Failed to parse speedtest.net configuration')
|
||||||
|
sys.exit(1)
|
||||||
del root
|
del root
|
||||||
del configxml
|
del configxml
|
||||||
return config
|
return config
|
||||||
|
@ -348,11 +352,15 @@ def closestServers(client, all=False):
|
||||||
return None
|
return None
|
||||||
uh.close()
|
uh.close()
|
||||||
try:
|
try:
|
||||||
root = ET.fromstring(''.encode().join(serversxml))
|
try:
|
||||||
elements = root.getiterator('server')
|
root = ET.fromstring(''.encode().join(serversxml))
|
||||||
except AttributeError:
|
elements = root.getiterator('server')
|
||||||
root = DOM.parseString(''.join(serversxml))
|
except AttributeError:
|
||||||
elements = root.getElementsByTagName('server')
|
root = DOM.parseString(''.join(serversxml))
|
||||||
|
elements = root.getElementsByTagName('server')
|
||||||
|
except SyntaxError:
|
||||||
|
print_('Failed to parse list of speedtest.net servers')
|
||||||
|
sys.exit(1)
|
||||||
servers = {}
|
servers = {}
|
||||||
for server in elements:
|
for server in elements:
|
||||||
try:
|
try:
|
||||||
|
|
Loading…
Reference in New Issue