MCPcopy
hub / github.com/urllib3/urllib3 / _idna_encode

Function _idna_encode

src/urllib3/util/url.py:330–346  ·  view source on GitHub ↗
(name: str)

Source from the content-addressed store, hash-verified

328
329
330def _idna_encode(name: str) -> bytes:
331 if not name.isascii():
332 try:
333 import idna
334 except ImportError:
335 raise LocationParseError(
336 "Unable to parse URL without the 'idna' module"
337 ) from None
338
339 try:
340 return idna.encode(name.lower(), strict=True, std3_rules=True)
341 except idna.IDNAError:
342 raise LocationParseError(
343 f"Name '{name}' is not a valid IDNA label"
344 ) from None
345
346 return name.lower().encode("ascii")
347
348
349def _encode_target(target: str) -> str:

Callers 1

_normalize_hostFunction · 0.85

Calls 1

LocationParseErrorClass · 0.85

Tested by

no test coverage detected