Skip to content

Commit

Permalink
Small speed up to human_repr (#1274)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 15, 2024
1 parent 84677e9 commit 32a35be
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -1034,9 +1034,7 @@ def _parse_host(
return False, lower_host, is_ascii, "", "", ""

@classmethod
def _encode_host(
cls, host: str, human: bool = False, validate_host: bool = True
) -> str:
def _encode_host(cls, host: str, validate_host: bool = True) -> str:
"""Encode host part of URL."""
looks_like_ip, lower_host, is_ascii, raw_ip, sep, zone = cls._parse_host(host)
if looks_like_ip:
Expand Down Expand Up @@ -1080,7 +1078,7 @@ def _encode_host(
_host_validate(lower_host)
return lower_host

return lower_host if human else _idna_encode(lower_host)
return _idna_encode(lower_host)

@classmethod
@lru_cache # match the same size as urlsplit
Expand Down Expand Up @@ -1584,9 +1582,8 @@ def human_repr(self) -> str:
"""Return decoded human readable string for URL representation."""
user = _human_quote(self.user, "#/:?@[]")
password = _human_quote(self.password, "#/:?@[]")
host = self.host
if host:
host = self._encode_host(host, human=True)
if (host := self.host) and ":" in host:
host = f"[{host}]"
path = _human_quote(self.path, "#?")
if TYPE_CHECKING:
assert path is not None
Expand Down

0 comments on commit 32a35be

Please sign in to comment.