summaryrefslogtreecommitdiff
path: root/sleekxmpp/clientxmpp.py
diff options
context:
space:
mode:
Diffstat (limited to 'sleekxmpp/clientxmpp.py')
-rw-r--r--sleekxmpp/clientxmpp.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py
index 04c19d3f..95ae108b 100644
--- a/sleekxmpp/clientxmpp.py
+++ b/sleekxmpp/clientxmpp.py
@@ -153,18 +153,23 @@ class ClientXMPP(BaseXMPP):
addresses = {}
intmax = 0
+ topprio = 65535
for answer in answers:
- intmax += answer.priority
- addresses[intmax] = (answer.target.to_text()[:-1],
+ topprio = min(topprio, answer.priority)
+ for answer in answers:
+ if answer.priority == topprio:
+ intmax += answer.weight
+ addresses[intmax] = (answer.target.to_text()[:-1],
answer.port)
+
#python3 returns a generator for dictionary keys
- priorities = [x for x in addresses.keys()]
- priorities.sort()
+ items = [x for x in addresses.keys()]
+ items.sort()
picked = random.randint(0, intmax)
- for priority in priorities:
- if picked <= priority:
- address = addresses[priority]
+ for item in items:
+ if picked <= item:
+ address = addresses[item]
break
if not address: