Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/sivel/speedtest-cli.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatt Martz <matt@sivel.net>2017-05-12 21:01:59 +0300
committerMatt Martz <matt@sivel.net>2017-11-23 19:15:09 +0300
commitca72d40033fffc2aa056b2c4f7103c6eb51e5a06 (patch)
treed805f7d7f89070b211ab7a0250c6e966c869c1df
parent3ebb9734a2e6211d60e1e52fe2f1fdd53bfedb46 (diff)
Create a getter for Speedtest.best to raise an exception is get_best_server has not found a best server
-rwxr-xr-xspeedtest.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/speedtest.py b/speedtest.py
index 6419078..a586b19 100755
--- a/speedtest.py
+++ b/speedtest.py
@@ -321,6 +321,10 @@ class SpeedtestBestServerFailure(SpeedtestException):
"""Unable to determine best server"""
+class SpeedtestMissingBestServer(SpeedtestException):
+ """get_best_server not called or not able to determine best server"""
+
+
def create_connection(address, timeout=_GLOBAL_DEFAULT_TIMEOUT,
source_address=None):
"""Connect to *address* and return the socket object.
@@ -953,10 +957,19 @@ class Speedtest(object):
self.servers = {}
self.closest = []
- self.best = {}
+ self._best = {}
self.results = SpeedtestResults(opener=self._opener, secure=secure)
+ @property
+ def best(self):
+ if not self._best:
+ raise SpeedtestMissingBestServer(
+ 'get_best_server not called or not able to determine best '
+ 'server'
+ )
+ return self._best
+
def get_config(self):
"""Download the speedtest.net configuration and return only the data
we are interested in
@@ -1300,7 +1313,7 @@ class Speedtest(object):
self.results.ping = fastest
self.results.server = best
- self.best.update(best)
+ self._best.update(best)
printer('Best Server:\n%r' % best, debug=True)
return best