# 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
def getaddrinfo(host, port, family = None,
                socktype = socket.SOCK_STREAM, proto = 0, allow_cname = True):
    """Resolve host and port into addrinfo struct.

    Does the same thing as socket.getaddrinfo, but using `dns.resolver`,
    so the cache content from the SRV query can be used.

    :Parameters:
        - `host`: service domain name.
        - `port`: service port number or name.
        - `family`: address family (`AF_INET` for IPv4, `AF_INET6` for IPv6 or
          `AF_UNSPEC` for either, `None` for the auto-configured default).
        - `socktype`: socket type.
        - `proto`: protocol number or name.
        - `allow_cname`: when False CNAME responses are not allowed.
    :Types:
        - `host`: `unicode` or `str`
        - `port`: `int` or `str`
        - `family`: `int`
        - `socktype`: `int`
        - `proto`: `int` or `str`
        - `allow_cname`: `bool`

    :return: list of (family, socktype, proto, canonname, sockaddr).
    :returntype: `list` of (`int`, `int`, `int`, `str`, (`str`, `int`))"""
    if family is None:
        family = default_address_family
    ret=[]
    if proto==0:
        proto=socket.getprotobyname("tcp")

# 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

def getaddrinfo(host, port, family = None,
                socktype = socket.SOCK_STREAM, proto = 0, allow_cname = True):
    """Resolve host and port into addrinfo struct.

    Does the same thing as socket.getaddrinfo, but using `dns.resolver`,
    so the cache content from the SRV query can be used.

    :Parameters:
        - `host`: service domain name.
        - `port`: service port number or name.
        - `family`: address family (`AF_INET` for IPv4, `AF_INET6` for IPv6 or
          `AF_UNSPEC` for either, `None` for the auto-configured default).
        - `socktype`: socket type.
        - `proto`: protocol number or name.
        - `allow_cname`: when False CNAME responses are not allowed.
    :Types:
        - `host`: `unicode` or `str`
        - `port`: `int` or `str`
        - `family`: `int`
        - `socktype`: `int`
        - `proto`: `int` or `str`
        - `allow_cname`: `bool`

    :return: list of (family, socktype, proto, canonname, sockaddr).
    :returntype: `list` of (`int`, `int`, `int`, `str`, (`str`, `int`))"""
    if family is None:
        family = default_address_family
    ret=[]
    if proto==0:
        proto=socket.getprotobyname("tcp")

    elif type(proto)!=int: