# Path: pyxmpp/exceptions.py
# class DNSError(FatalStreamError):
#     """Raised when no host name could be resolved for the target."""
#     pass
# 
# class UnexpectedCNAMEError(DNSError):
#     """Raised when CNAME record was found when A or AAAA was expected."""
#     pass


import re
import socket
import dns.resolver
import dns.name
import dns.exception
import random
import logging
from socket import AF_UNSPEC, AF_INET, AF_INET6
from .exceptions import DNSError, UnexpectedCNAMEError
    while len(records)>1:
        weight_sum=0
        for rr in records:
            weight_sum+=rr.weight+0.1
        thres=random.random()*weight_sum
        weight_sum=0
        for rr in records:
            weight_sum+=rr.weight+0.1
            if thres<weight_sum:
                records.remove(rr)
                ret.append(rr)
                break
    ret.append(records[0])
    return ret

def reorder_srv(records):
    """Reorder SRV records using their priorities and weights.

    :Parameters:
        - `records`: SRV records to shuffle.
    :Types:
        - `records`: `list` of `dns.rdtypes.IN.SRV`

    :return: reordered records.
    :returntype: `list` of `dns.rdtypes.IN.SRV`"""
    records=list(records)
    records.sort()
    ret=[]
    tmp=[]
    for rr in records:

# Path: pyxmpp/exceptions.py
# class DNSError(FatalStreamError):
#     """Raised when no host name could be resolved for the target."""
#     pass
# 
# class UnexpectedCNAMEError(DNSError):
#     """Raised when CNAME record was found when A or AAAA was expected."""
#     pass


# Path: pyxmpp/resolver.py
import re
import socket
import dns.resolver
import dns.name
import dns.exception
import random
import logging
from socket import AF_UNSPEC, AF_INET, AF_INET6
from .exceptions import DNSError, UnexpectedCNAMEError

    while len(records)>1:
        weight_sum=0
        for rr in records:
            weight_sum+=rr.weight+0.1
        thres=random.random()*weight_sum
        weight_sum=0
        for rr in records:
            weight_sum+=rr.weight+0.1
            if thres<weight_sum:
                records.remove(rr)
                ret.append(rr)
                break
    ret.append(records[0])
    return ret

def reorder_srv(records):
    """Reorder SRV records using their priorities and weights.

    :Parameters:
        - `records`: SRV records to shuffle.
    :Types:
        - `records`: `list` of `dns.rdtypes.IN.SRV`

    :return: reordered records.
    :returntype: `list` of `dns.rdtypes.IN.SRV`"""
    records=list(records)
    records.sort()
    ret=[]
    tmp=[]
    for rr in records:

        if not tmp or rr.priority==tmp[0].priority: