Skip to content
Myr

fixed __repr__ function of Headers and Url classes (#222)

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 2ed70eb · Browse files · 2 files+31 added−3 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+31 added−3 removed

  • tests:+18 added−0 removed
  • other:+13 added−3 removed

2 files+31 added−3 removed

modified:httpx/models.py+13 added-3 removed
208 unmodified lines
209210 def __repr__(self) -> str:211 class_name = self.__class__.__name__212 url_str = str(self)213 if self._uri_reference.userinfo:214 url_str = (215 rfc3986.urlparse(url_str)216 .copy_with(userinfo=f"{self.username}:[secure]")217 .unsplit()218 )219 return f"{class_name}({url_str!r})"220221222class Origin:
271 unmodified lines
494 encoding_str = ""495 if self.encoding != "ascii":496 encoding_str = f", encoding={self.encoding!r}"497498 sensitive_headers = {"authorization", "proxy-authorization"}499 as_list = [500 (k, "[secure]" if k in sensitive_headers else v) for k, v in self.items()501 ]502492 as_dict = dict(self.items())493 if len(as_dict) == len(self):503 as_dict = dict(as_list)504 if len(as_dict) == len(as_list):505 return f"{class_name}({as_dict!r}{encoding_str})"495 as_list = self.items()506 return f"{class_name}({as_list!r}{encoding_str})"507508509class BaseRequest:
711 unmodified lines
modified:tests/client/test_auth.py+18 added
1import json2import os34from httpx import (5 URL,6 AsyncDispatcher,7 AsyncRequest,8 AsyncResponse,9 CertTypes,
90 unmodified lines
100 assert response.status_code == 200101 assert response.json() == {102 "auth": "Basic ZXhhbXBsZS11c2VybmFtZTpleGFtcGxlLXBhc3N3b3Jk"103 }104105106def test_auth_hidden_url():107 url = "http://example-username:example-password@example.org/"108 expected = "URL('http://example-username:[secure]@example.org/')"109 assert url == URL(url)110 assert expected == repr(URL(url))111112113def test_auth_hidden_header():114 url = "https://example.org/"115 auth = ("example-username", "example-password")116117 with Client(dispatch=MockDispatch()) as client:118 response = client.get(url, auth=auth)119120 assert "'authorization': '[secure]'" in str(response.request.headers)