Added gzip support:
This commit is contained in:
parent
7b09d8759f
commit
aff490beea
|
@ -24,6 +24,9 @@ import socket
|
||||||
import timeit
|
import timeit
|
||||||
import platform
|
import platform
|
||||||
import threading
|
import threading
|
||||||
|
import urllib2
|
||||||
|
import StringIO
|
||||||
|
import gzip
|
||||||
|
|
||||||
__version__ = '0.3.4'
|
__version__ = '0.3.4'
|
||||||
|
|
||||||
|
@ -375,19 +378,18 @@ def getConfig():
|
||||||
we are interested in
|
we are interested in
|
||||||
"""
|
"""
|
||||||
|
|
||||||
request = build_request('://www.speedtest.net/speedtest-config.php')
|
request = build_request('://www.speedtest.net/speedtest-config.php', headers = {'user-agent':user_agent, 'accept-encoding': 'gzip'})
|
||||||
uh, e = catch_request(request)
|
uh = urllib2.build_opener()
|
||||||
if e:
|
|
||||||
print_('Could not retrieve speedtest.net configuration: %s' % e)
|
response = uh.open(request)
|
||||||
sys.exit(1)
|
|
||||||
|
text = gzip.GzipFile(fileobj=StringIO.StringIO(response.read())).read()
|
||||||
configxml = []
|
configxml = []
|
||||||
while 1:
|
configxml.append(text)
|
||||||
configxml.append(uh.read(10240))
|
|
||||||
if len(configxml[-1]) == 0:
|
if(int(response.code) != 200):
|
||||||
break
|
|
||||||
if int(uh.code) != 200:
|
|
||||||
return None
|
return None
|
||||||
uh.close()
|
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
root = ET.fromstring(''.encode().join(configxml))
|
root = ET.fromstring(''.encode().join(configxml))
|
||||||
|
|
Loading…
Reference in New Issue