Some fixes for python2.4
This commit is contained in:
parent
dfeb19ff68
commit
5cba294b76
|
@ -47,6 +47,7 @@ import socket
|
||||||
|
|
||||||
# Used for bound_interface
|
# Used for bound_interface
|
||||||
socket_socket = socket.socket
|
socket_socket = socket.socket
|
||||||
|
socket.setdefaulttimeout(10)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import xml.etree.cElementTree as ET
|
import xml.etree.cElementTree as ET
|
||||||
|
@ -311,6 +312,10 @@ class HTTPUploaderData(object):
|
||||||
def __len__(self):
|
def __len__(self):
|
||||||
return self.length
|
return self.length
|
||||||
|
|
||||||
|
def to_string(self):
|
||||||
|
self.total.append(self.length)
|
||||||
|
return self.read(self.length)
|
||||||
|
|
||||||
|
|
||||||
class HTTPUploader(threading.Thread):
|
class HTTPUploader(threading.Thread):
|
||||||
"""Thread class for uploading to a URL"""
|
"""Thread class for uploading to a URL"""
|
||||||
|
@ -318,6 +323,7 @@ class HTTPUploader(threading.Thread):
|
||||||
def __init__(self, i, url, start, size, timeout):
|
def __init__(self, i, url, start, size, timeout):
|
||||||
self.url = url
|
self.url = url
|
||||||
self.data = HTTPUploaderData(size, start, timeout)
|
self.data = HTTPUploaderData(size, start, timeout)
|
||||||
|
self.size = size
|
||||||
self.result = None
|
self.result = None
|
||||||
self.starttime = start
|
self.starttime = start
|
||||||
self.timeout = timeout
|
self.timeout = timeout
|
||||||
|
@ -328,12 +334,19 @@ class HTTPUploader(threading.Thread):
|
||||||
try:
|
try:
|
||||||
if ((time.time() - self.starttime) <= self.timeout and
|
if ((time.time() - self.starttime) <= self.timeout and
|
||||||
not shutdown_event.isSet()):
|
not shutdown_event.isSet()):
|
||||||
req = Request(self.url, self.data)
|
try:
|
||||||
req.add_header('User-Agent', USER_AGENT)
|
req = Request(self.url, self.data)
|
||||||
f = urlopen(req)
|
req.add_header('User-Agent', USER_AGENT)
|
||||||
|
f = urlopen(req)
|
||||||
|
except TypeError:
|
||||||
|
req.data = self.data.read(self.size)
|
||||||
|
f = urlopen(req)
|
||||||
f.read(11)
|
f.read(11)
|
||||||
f.close()
|
f.close()
|
||||||
self.result = sum(self.data.total)
|
try:
|
||||||
|
self.result = sum(self.data.total)
|
||||||
|
except AttributeError:
|
||||||
|
self.result = self.size
|
||||||
else:
|
else:
|
||||||
self.result = 0
|
self.result = 0
|
||||||
except:
|
except:
|
||||||
|
@ -342,6 +355,20 @@ class HTTPUploader(threading.Thread):
|
||||||
del self.data
|
del self.data
|
||||||
|
|
||||||
|
|
||||||
|
class DataDescriptor(object):
|
||||||
|
def __init__(self, value=None):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def __get__(self, instance, cls):
|
||||||
|
return self.value
|
||||||
|
|
||||||
|
def __set__(self, value):
|
||||||
|
self.value = value
|
||||||
|
|
||||||
|
def __delete__(self):
|
||||||
|
self.value = 0
|
||||||
|
|
||||||
|
|
||||||
class SpeedtestResults(object):
|
class SpeedtestResults(object):
|
||||||
"""Class for holding the results of a speedtest, including:
|
"""Class for holding the results of a speedtest, including:
|
||||||
|
|
||||||
|
@ -357,59 +384,11 @@ class SpeedtestResults(object):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __init__(self, download=0, upload=0, ping=0, server=dict()):
|
def __init__(self, download=0, upload=0, ping=0, server=dict()):
|
||||||
self._download = download
|
self.download = DataDescriptor(download)
|
||||||
self._upload = upload
|
self.upload = DataDescriptor(upload)
|
||||||
self._ping = ping
|
self.ping = DataDescriptor(ping)
|
||||||
self._server = server
|
self.server = DataDescriptor(server)
|
||||||
self._share = None
|
self.share = DataDescriptor(None)
|
||||||
|
|
||||||
@property
|
|
||||||
def download(self):
|
|
||||||
"""Get upload speed result"""
|
|
||||||
|
|
||||||
return self._download
|
|
||||||
|
|
||||||
@download.setter
|
|
||||||
def download(self, value):
|
|
||||||
"""Setter for download speed value"""
|
|
||||||
|
|
||||||
self._download = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def upload(self):
|
|
||||||
"""Get upload speed result"""
|
|
||||||
|
|
||||||
return self._upload
|
|
||||||
|
|
||||||
@upload.setter
|
|
||||||
def upload(self, value):
|
|
||||||
"""Setter for upload speed value"""
|
|
||||||
|
|
||||||
self._upload = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def ping(self):
|
|
||||||
"""Get ping/latency value"""
|
|
||||||
|
|
||||||
return self._ping
|
|
||||||
|
|
||||||
@ping.setter
|
|
||||||
def ping(self, value):
|
|
||||||
"""Setter for ping/latency value"""
|
|
||||||
|
|
||||||
self._ping = value
|
|
||||||
|
|
||||||
@property
|
|
||||||
def server(self):
|
|
||||||
"""Get data for server used in the test"""
|
|
||||||
|
|
||||||
return self._server
|
|
||||||
|
|
||||||
@server.setter
|
|
||||||
def server(self, value):
|
|
||||||
"""Setter for server data"""
|
|
||||||
|
|
||||||
self._server = value
|
|
||||||
|
|
||||||
def dict(self):
|
def dict(self):
|
||||||
"""Return dictionary of result data"""
|
"""Return dictionary of result data"""
|
||||||
|
@ -1034,8 +1013,8 @@ def shell():
|
||||||
try:
|
try:
|
||||||
unicode()
|
unicode()
|
||||||
printer(('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
printer(('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
||||||
'%(latency)s ms' %
|
'%(latency)s ms' %
|
||||||
results.server).encode('utf-8', 'ignore'), quiet)
|
results.server).encode('utf-8', 'ignore'), quiet)
|
||||||
except NameError:
|
except NameError:
|
||||||
printer('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
printer('Hosted by %(sponsor)s (%(name)s) [%(d)0.2f km]: '
|
||||||
'%(latency)s ms' % results.server, quiet)
|
'%(latency)s ms' % results.server, quiet)
|
||||||
|
|
Loading…
Reference in New Issue