A URL, as new URL(text, base) parses it; raises ValueError
when text is not a URL. str(url) is its href, so
f"{url}/items" builds a URL text. Two URLs are equal when their
href is, as Effect's Equal compares URLs.
http.url has Effect's functions over it (set_hash, mutate,
...).
Attributes#
| Attribute | Type | Description |
|---|---|---|
record | UrlRecord | |
href | str | |
protocol | str | The scheme and |
username | str | |
password | str | |
host | str | The host and the port, if any ( |
hostname | str | |
port | str | The port, |
pathname | str | |
search | str |
|
hash | str |
|
origin | str | |
search_params | tuple[tuple[str, str], ...] | The query's name-value pairs, as |
Functions#
__init__#
__init__(text, base=None) -> None| Parameter | Type | Description |
|---|---|---|
text | str | |
base | str | Url | None = None |
def __init__(self, text: str, base: str | Url | None = None) -> None:
record = _parse(text, base)
if record is None:
suffix = "" if base is None else f" with base {str(base)!r}"
raise ValueError(f"Invalid URL: {text!r}{suffix}")
object.__setattr__(self, "record", record)
object.__setattr__(self, "_href", record.href())from_record#
from_record(record) -> Self| Parameter | Type | Description |
|---|---|---|
record | UrlRecord |
Returns Self
@classmethod
def from_record(cls, record: UrlRecord) -> Self:
url = cls.__new__(cls)
object.__setattr__(url, "record", record)
object.__setattr__(url, "_href", record.href())
return urlparse#
parse(text, base=None) -> Url | NoneURL.parse: the URL, or None when text is not one.
| Parameter | Type | Description |
|---|---|---|
text | str | |
base | str | Url | None = None |
Returns Url | None
@classmethod
def parse(cls, text: str, base: str | Url | None = None) -> Url | None:
"""``URL.parse``: the URL, or ``None`` when ``text`` is not one."""
record = _parse(text, base)
return None if record is None else cls.from_record(record)can_parse#
can_parse(text, base=None) -> boolURL.canParse.
| Parameter | Type | Description |
|---|---|---|
text | str | |
base | str | Url | None = None |
Returns bool
@staticmethod
def can_parse(text: str, base: str | Url | None = None) -> bool:
"""``URL.canParse``."""
return _parse(text, base) is not Noneto_json#
to_json() -> strURL.toJSON: the href.
Returns str
def to_json(self) -> str:
"""``URL.toJSON``: the ``href``."""
return self._href