# Emulate the bare minimum for idna for the Swarming bot.
# In practice, we do not need it, and it's very large.
def encode(host, uts46):
  return unicode(host)

# Emulate the bare minimum for idna for the Swarming bot.
# In practice, we do not need it, and it's very large.
# See https://pypi.org/project/idna/

from encodings import idna


def encode(host, uts46=False):  # pylint: disable=unused-argument
  # Used by urllib3
  return idna.ToASCII(host)


def decode(host):
  # Used by cryptography/hazmat/backends/openssl/x509.py
  return idna.ToUnicode(host)

Change idna stub to use python's default
[client] Change idna stub to use python's default

Fix a regression from 690b8ae29be2ca3b4782fa6ad0e7f2454443c38d which broke
select bots running inside docker.

The new stub is still simpler than https://pypi.org/project/idna/ and lighter
weight but much better than ignoring the "xn-" encoding as this was done
previously. As per the project home page:

  This acts as a suitable replacement for the “encodings.idna” module that comes
  with the Python standard library, but only supports the old, deprecated IDNA
  specification (RFC 3490).

In practice, we don't expect to use non-ASCII hostnames, so it's not a big deal
for us.

decode() is required by openssl/x509.py.

TBR=jchinlee@chromium.org
Bug: 916644
Change-Id: Ia999a56b981d943e2f3d942f83e40d40e1bb805b
Reviewed-on: https://chromium-review.googlesource.com/c/infra/luci/luci-py/+/1573244
Reviewed-by: Marc-Antoine Ruel <d2bf0fc09b08f7b0888b3ddab32b3e89c7122c8b@chromium.org>
Commit-Queue: Marc-Antoine Ruel <d2bf0fc09b08f7b0888b3ddab32b3e89c7122c8b@chromium.org>
