(name: str)
| 328 | |
| 329 | |
| 330 | def _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 | |
| 349 | def _encode_target(target: str) -> str: |
no test coverage detected