# Path: paramiko/py3compat.py
# PY2 = sys.version_info[0] < 3
#         MAXSIZE = int((1 << 31) - 1)  # NOQA
#         MAXSIZE = int((1 << 63) - 1)  # NOQA
#     MAXSIZE = sys.maxsize  # NOQA
#     def bytestring(s):  # NOQA
#     def byte_mask(c, mask):
#     def b(s, encoding="utf8"):  # NOQA
#     def u(s, encoding="utf8"):  # NOQA
#     def b2s(s):
#     def is_callable(c):  # NOQA
#     def get_next(c):  # NOQA
#     def next(c):
#         def __len__(self):
#     def strftime(format, t):
#     def byte_ord(c):
#     def byte_chr(c):
#     def byte_mask(c, mask):
#     def b(s, encoding="utf8"):
#     def u(s, encoding="utf8"):
#     def b2s(s):
#     def is_callable(c):
#     def get_next(c):
#     class X(object):
#     class long(int):
# 
# Path: paramiko/ssh_exception.py
# class CouldNotCanonicalize(SSHException):
#     """
#     Raised when hostname canonicalization fails & fallback is disabled.
# 
#     .. versionadded:: 2.7
#     """
# 
#     pass
# 
# class ConfigParseError(SSHException):
#     """
#     A fatal error was encountered trying to parse SSH config data.
# 
#     Typically this means a config file violated the ``ssh_config``
#     specification in a manner that requires exiting immediately, such as not
#     matching ``key = value`` syntax or misusing certain ``Match`` keywords.
# 
#     .. versionadded:: 2.7
#     """
# 
#     pass


import fnmatch
import getpass
import os
import re
import shlex
import socket
    import invoke
from functools import partial
from .py3compat import StringIO
from .ssh_exception import CouldNotCanonicalize, ConfigParseError

        .. versionadded:: 2.7
        """
        found = False
        for domain in domains:
            candidate = "{}.{}".format(hostname, domain)
            family_specific = _addressfamily_host_lookup(candidate, options)
            if family_specific is not None:
                # TODO: would we want to dig deeper into other results? e.g. to
                # find something that satisfies PermittedCNAMEs when that is
                # implemented?
                found = family_specific[0]
            else:
                # TODO: what does ssh use here and is there a reason to use
                # that instead of gethostbyname?
                try:
                    found = socket.gethostbyname(candidate)
                except socket.gaierror:
                    pass
            if found:
                # TODO: follow CNAME (implied by found != candidate?) if
                # CanonicalizePermittedCNAMEs allows it
                return candidate
        # If we got here, it means canonicalization failed.
        # When CanonicalizeFallbackLocal is undefined or 'yes', we just spit
        # back the original hostname.
        if options.get("canonicalizefallbacklocal", "yes") == "yes":
            return hostname
        # And here, we failed AND fallback was set to a non-yes value, so we
        # need to get mad.

# Path: paramiko/py3compat.py
# PY2 = sys.version_info[0] < 3
#         MAXSIZE = int((1 << 31) - 1)  # NOQA
#         MAXSIZE = int((1 << 63) - 1)  # NOQA
#     MAXSIZE = sys.maxsize  # NOQA
#     def bytestring(s):  # NOQA
#     def byte_mask(c, mask):
#     def b(s, encoding="utf8"):  # NOQA
#     def u(s, encoding="utf8"):  # NOQA
#     def b2s(s):
#     def is_callable(c):  # NOQA
#     def get_next(c):  # NOQA
#     def next(c):
#         def __len__(self):
#     def strftime(format, t):
#     def byte_ord(c):
#     def byte_chr(c):
#     def byte_mask(c, mask):
#     def b(s, encoding="utf8"):
#     def u(s, encoding="utf8"):
#     def b2s(s):
#     def is_callable(c):
#     def get_next(c):
#     class X(object):
#     class long(int):
# 
# Path: paramiko/ssh_exception.py
# class CouldNotCanonicalize(SSHException):
#     """
#     Raised when hostname canonicalization fails & fallback is disabled.
# 
#     .. versionadded:: 2.7
#     """
# 
#     pass
# 
# class ConfigParseError(SSHException):
#     """
#     A fatal error was encountered trying to parse SSH config data.
# 
#     Typically this means a config file violated the ``ssh_config``
#     specification in a manner that requires exiting immediately, such as not
#     matching ``key = value`` syntax or misusing certain ``Match`` keywords.
# 
#     .. versionadded:: 2.7
#     """
# 
#     pass


# Path: paramiko/config.py
import fnmatch
import getpass
import os
import re
import shlex
import socket
    import invoke
from functools import partial
from .py3compat import StringIO
from .ssh_exception import CouldNotCanonicalize, ConfigParseError


        .. versionadded:: 2.7
        """
        found = False
        for domain in domains:
            candidate = "{}.{}".format(hostname, domain)
            family_specific = _addressfamily_host_lookup(candidate, options)
            if family_specific is not None:
                # TODO: would we want to dig deeper into other results? e.g. to
                # find something that satisfies PermittedCNAMEs when that is
                # implemented?
                found = family_specific[0]
            else:
                # TODO: what does ssh use here and is there a reason to use
                # that instead of gethostbyname?
                try:
                    found = socket.gethostbyname(candidate)
                except socket.gaierror:
                    pass
            if found:
                # TODO: follow CNAME (implied by found != candidate?) if
                # CanonicalizePermittedCNAMEs allows it
                return candidate
        # If we got here, it means canonicalization failed.
        # When CanonicalizeFallbackLocal is undefined or 'yes', we just spit
        # back the original hostname.
        if options.get("canonicalizefallbacklocal", "yes") == "yes":
            return hostname
        # And here, we failed AND fallback was set to a non-yes value, so we
        # need to get mad.

        raise CouldNotCanonicalize(hostname)