def _normalize_host(host, enable_long_host=False, encode_with_idna=None,<EOL>scheme=None):
if encode_with_idna is not None:<EOL><INDENT>enable_idna = encode_with_idna<EOL><DEDENT>else:<EOL><INDENT>enable_idna = scheme.lower() in IDNA_SCHEMES if scheme else False<EOL><DEDENT>if enable_idna:<EOL><INDENT>try:<EOL><INDENT>host = '<STR_LIT:.>'.join(segment.encode('<STR_LIT>').decode()<EOL>for segment in host.split('<STR_LIT:.>'))<EOL><DEDENT>except UnicodeError as exc:<EOL><INDENT>raise ValueError('<STR_LIT>'.format(exc))<EOL><DEDENT><DEDENT>else:<EOL><INDENT>host = parse.quote(host.encode('<STR_LIT:utf-8>'), safe=HOST_SAFE_CHARS)<EOL><DEDENT>if len(host) > <NUM_LIT:255> and not enable_long_host:<EOL><INDENT>raise ValueError('<STR_LIT>')<EOL><DEDENT>return host<EOL>
Normalize a host for a URL.

:param str host: the host name to normalize

:keyword bool enable_long_host: if this keyword is specified
    and it is :data:`True`, then the host name length restriction
    from :rfc:`3986#section-3.2.2` is relaxed.
:keyword bool encode_with_idna: if this keyword is specified
    and it is :data:`True`, then the ``host`` parameter will be
    encoded using IDN.  If this value is provided as :data:`False`,
    then the percent-encoding scheme is used instead.  If this
    parameter is omitted or included with a different value, then
    the ``host`` parameter is processed using :data:`IDNA_SCHEMES`.
:keyword str scheme: if this keyword is specified, then it is
    used to determine whether to apply IDN rules or not.  This
    parameter is ignored if `encode_with_idna` is not :data:`None`.

:return: the normalized and encoded string ready for inclusion
    into a URL