Skip to content
Myr

added authority copy feature in URL.copy_with (#436)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Can Sarıgöl · committed by Tom Christie · parent f504399 · Browse files · 2 files+36 added−0 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+36 added−0 removed

  • tests:+14 added−0 removed
  • other:+22 added−0 removed

2 files+36 added−0 removed

modified:httpx/models.py+22 added
205 unmodified lines
206 def origin(self) -> "Origin":207 return Origin(self)208209 def copy_with(self, **kwargs: typing.Any) -> "URL":210 if (211 "username" in kwargs212 or "password" in kwargs213 or "host" in kwargs214 or "port" in kwargs215 ):216 host = kwargs.pop("host", self.host)217 port = kwargs.pop("port", self.port)218 username = kwargs.pop("username", self.username)219 password = kwargs.pop("password", self.password)220221 authority = host222 if port is not None:223 authority += f":{port}"224 if username is not None:225 userpass = username226 if password is not None:227 userpass += f":{password}"228 authority = f"{userpass}@{authority}"229230 kwargs["authority"] = authority231232 return URL(self._uri_reference.copy_with(**kwargs).unsplit())233234 def join(self, relative_url: URLTypes) -> "URL":235 """
1079 unmodified lines
modified:tests/models/test_url.py+14 added
188 unmodified lines
189 assert origin.scheme == "https"190 assert origin.is_ssl191 assert origin.host == "example.com"192 assert origin.port == 443193194195def test_url_copywith_for_authority():196 copy_with_kwargs = {197 "username": "username",198 "password": "password",199 "port": 444,200 "host": "example.net",201 }202 url = URL("https://example.org")203 new = url.copy_with(**copy_with_kwargs)204 for k, v in copy_with_kwargs.items():205 assert getattr(new, k) == v206 assert str(new) == "https://username:password@example.net:444"