| 344 | |
| 345 | |
| 346 | class _BaseMultiHostUrl: |
| 347 | _constraints: ClassVar[UrlConstraints] = UrlConstraints() |
| 348 | _url: _CoreMultiHostUrl |
| 349 | |
| 350 | def __init__(self, url: str | _CoreMultiHostUrl | _BaseMultiHostUrl) -> None: |
| 351 | self._url = _build_type_adapter(self.__class__).validate_python(url)._url |
| 352 | |
| 353 | @property |
| 354 | def scheme(self) -> str: |
| 355 | """The scheme part of the URL. |
| 356 | |
| 357 | e.g. `https` in `https://foo.com,bar.com/path?query#fragment` |
| 358 | """ |
| 359 | return self._url.scheme |
| 360 | |
| 361 | @property |
| 362 | def path(self) -> str | None: |
| 363 | """The path part of the URL, or `None`. |
| 364 | |
| 365 | e.g. `/path` in `https://foo.com,bar.com/path?query#fragment` |
| 366 | """ |
| 367 | return self._url.path |
| 368 | |
| 369 | @property |
| 370 | def query(self) -> str | None: |
| 371 | """The query part of the URL, or `None`. |
| 372 | |
| 373 | e.g. `query` in `https://foo.com,bar.com/path?query#fragment` |
| 374 | """ |
| 375 | return self._url.query |
| 376 | |
| 377 | def query_params(self) -> list[tuple[str, str]]: |
| 378 | """The query part of the URL as a list of key-value pairs. |
| 379 | |
| 380 | e.g. `[('foo', 'bar')]` in `https://foo.com,bar.com/path?foo=bar#fragment` |
| 381 | """ |
| 382 | return self._url.query_params() |
| 383 | |
| 384 | @property |
| 385 | def fragment(self) -> str | None: |
| 386 | """The fragment part of the URL, or `None`. |
| 387 | |
| 388 | e.g. `fragment` in `https://foo.com,bar.com/path?query#fragment` |
| 389 | """ |
| 390 | return self._url.fragment |
| 391 | |
| 392 | def hosts(self) -> list[MultiHostHost]: |
| 393 | '''The hosts of the `MultiHostUrl` as [`MultiHostHost`][pydantic_core.MultiHostHost] typed dicts. |
| 394 | |
| 395 | ```python |
| 396 | from pydantic_core import MultiHostUrl |
| 397 | |
| 398 | mhu = MultiHostUrl('https://foo.com:123,foo:bar@bar.com/path') |
| 399 | print(mhu.hosts()) |
| 400 | """ |
| 401 | [ |
| 402 | {'username': None, 'password': None, 'host': 'foo.com', 'port': 123}, |
| 403 | {'username': 'foo', 'password': 'bar', 'host': 'bar.com', 'port': 443} |
nothing calls this directly
no test coverage detected