Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added a method for converting a server dictionary to a server list #789

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion speedtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,6 +1437,14 @@ def get_closest_servers(self, limit=5):
printer('Closest Servers:\n%r' % self.closest, debug=True)
return self.closest

@staticmethod
def get_normalize_servers(dict_servers):
"""
Converting a server dictionary to a server list
"""

return [server for _, servers in dict_servers.items() for server in servers]

def get_best_server(self, servers=None):
"""Perform a speedtest.net "ping" to determine which speedtest.net
server has the lowest latency
Expand All @@ -1445,7 +1453,11 @@ def get_best_server(self, servers=None):
if not servers:
if not self.closest:
servers = self.get_closest_servers()
servers = self.closest
else:
servers = self.closest

if type(servers) is dict:
servers = self.get_normalize_servers(servers)

if self._source_address:
source_address_tuple = (self._source_address, 0)
Expand Down