def _hostAsBytesAndText(host):
        """
        For various reasons (documented in the C{@ivar}'s in the class
        docstring) we need both a textual and a binary representation of the
        hostname given to the constructor.  For compatibility and convenience,
        we accept both textual and binary representations of the hostname, save
        the form that was passed, and convert into the other form.  This is
        mostly just because L{HostnameAddress} chose somewhat poorly to define
        its attribute as bytes; hopefully we can find a compatible way to clean
        this up in the future and just operate in terms of text internally.

        @param host: A hostname to convert.
        @type host: L{bytes} or C{str}

        @return: a 3-tuple of C{(invalid, bytes, text)} where C{invalid} is a
            boolean indicating the validity of the hostname, C{bytes} is a
            binary representation of C{host}, and C{text} is a textual
            representation of C{host}.
        """
        if isinstance(host, bytes):
            if isIPAddress(host) or isIPv6Address(host):
                return False, host, host.decode("ascii")
            else:
                try:
                    return False, host, _idnaText(host)
                except UnicodeError:
                    # Convert the host to _some_ kind of text, to handle below.
                    host = host.decode("charmap")
        else:
            host = normalize('NFC', host)
            if isIPAddress(host) or isIPv6Address(host):
                return False, host.encode("ascii"), host
            else:
                try:
                    return False, _idnaBytes(host), host
                except UnicodeError:
                    pass
        # `host` has been converted to text by this point either way; it's
        # invalid as a hostname, and so may contain unprintable characters and
        # such. escape it with backslashes so the user can get _some_ guess as
        # to what went wrong.
        asciibytes = host.encode('ascii', 'backslashreplace')
        return True, asciibytes, asciibytes.decode('ascii')

        For various reasons (documented in the C{@ivar}'s in the class
        docstring) we need both a textual and a binary representation of the
        hostname given to the constructor.  For compatibility and convenience,
        we accept both textual and binary representations of the hostname, save
        the form that was passed, and convert into the other form.  This is
        mostly just because L{HostnameAddress} chose somewhat poorly to define
        its attribute as bytes; hopefully we can find a compatible way to clean
        this up in the future and just operate in terms of text internally.

        @param host: A hostname to convert.
        @type host: L{bytes} or C{str}

        @return: a 3-tuple of C{(invalid, bytes, text)} where C{invalid} is a
            boolean indicating the validity of the hostname, C{bytes} is a
            binary representation of C{host}, and C{text} is a textual
            representation of C{host}.
        
stackoverflow/venv/lib/python3.6/site-packages/twisted/internet/endpoints.py