(cls, parts: 'Parts')
| 340 | |
| 341 | @classmethod |
| 342 | def validate_host(cls, parts: 'Parts') -> Tuple[str, Optional[str], str, bool]: |
| 343 | tld, host_type, rebuild = None, None, False |
| 344 | for f in ('domain', 'ipv4', 'ipv6'): |
| 345 | host = parts[f] # type: ignore[literal-required] |
| 346 | if host: |
| 347 | host_type = f |
| 348 | break |
| 349 | |
| 350 | if host is None: |
| 351 | if cls.host_required: |
| 352 | raise errors.UrlHostError() |
| 353 | elif host_type == 'domain': |
| 354 | is_international = False |
| 355 | d = ascii_domain_regex().fullmatch(host) |
| 356 | if d is None: |
| 357 | d = int_domain_regex().fullmatch(host) |
| 358 | if d is None: |
| 359 | raise errors.UrlHostError() |
| 360 | is_international = True |
| 361 | |
| 362 | tld = d.group('tld') |
| 363 | if tld is None and not is_international: |
| 364 | d = int_domain_regex().fullmatch(host) |
| 365 | assert d is not None |
| 366 | tld = d.group('tld') |
| 367 | is_international = True |
| 368 | |
| 369 | if tld is not None: |
| 370 | tld = tld[1:] |
| 371 | elif cls.tld_required: |
| 372 | raise errors.UrlHostTldError() |
| 373 | |
| 374 | if is_international: |
| 375 | host_type = 'int_domain' |
| 376 | rebuild = True |
| 377 | host = host.encode('idna').decode('ascii') |
| 378 | if tld is not None: |
| 379 | tld = tld.encode('idna').decode('ascii') |
| 380 | |
| 381 | return host, tld, host_type, rebuild # type: ignore |
| 382 | |
| 383 | @staticmethod |
| 384 | def get_default_parts(parts: 'Parts') -> 'Parts': |
no test coverage detected