diff options
author | Lance Stout <lancestout@gmail.com> | 2011-07-27 19:36:04 -0700 |
---|---|---|
committer | Lance Stout <lancestout@gmail.com> | 2011-07-27 19:36:04 -0700 |
commit | d7fe724145c2e01d1028dab773fb49414c6856dd (patch) | |
tree | 460331e5949b92637c79275aed001c85125f7afe /sleekxmpp/clientxmpp.py | |
parent | 20df6348a4c8262a40578d84c934f9a15431d925 (diff) | |
parent | e022b2a36c342b6a83d7c7f0a39dfb851cdfd2de (diff) | |
download | slixmpp-d7fe724145c2e01d1028dab773fb49414c6856dd.tar.gz slixmpp-d7fe724145c2e01d1028dab773fb49414c6856dd.tar.bz2 slixmpp-d7fe724145c2e01d1028dab773fb49414c6856dd.tar.xz slixmpp-d7fe724145c2e01d1028dab773fb49414c6856dd.zip |
Merge branch 'develop' into exceptions
Diffstat (limited to 'sleekxmpp/clientxmpp.py')
-rw-r--r-- | sleekxmpp/clientxmpp.py | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/sleekxmpp/clientxmpp.py b/sleekxmpp/clientxmpp.py index 77710541..91106076 100644 --- a/sleekxmpp/clientxmpp.py +++ b/sleekxmpp/clientxmpp.py @@ -168,18 +168,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: |