From: cdeler Date: Thu, 6 Aug 2020 11:09:21 +0000 (+0300) Subject: #1066 make BaseClient's timeout accessible using getters and setters (#1135) X-Git-Tag: 0.14.0~5 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7123b0f7bac34f4b0af4c3c4fe2ef63ab4f238ff;p=thirdparty%2Fhttpx.git #1066 make BaseClient's timeout accessible using getters and setters (#1135) --- diff --git a/httpx/_client.py b/httpx/_client.py index 645c83e0..1829b957 100644 --- a/httpx/_client.py +++ b/httpx/_client.py @@ -75,7 +75,7 @@ class BaseClient: self._params = QueryParams(params) self._headers = Headers(headers) self._cookies = Cookies(cookies) - self.timeout = Timeout(timeout) + self._timeout = Timeout(timeout) self.max_redirects = max_redirects self._trust_env = trust_env self._netrc = NetRCInfo() @@ -109,6 +109,14 @@ class BaseClient: proxy = Proxy(url=proxies) if isinstance(proxies, (str, URL)) else proxies return {"all": proxy} + @property + def timeout(self) -> Timeout: + return self._timeout + + @timeout.setter + def timeout(self, timeout: TimeoutTypes) -> None: + self._timeout = Timeout(timeout) + @property def base_url(self) -> URL: """ diff --git a/tests/client/test_properties.py b/tests/client/test_properties.py index 35327747..b0f42efb 100644 --- a/tests/client/test_properties.py +++ b/tests/client/test_properties.py @@ -1,4 +1,4 @@ -from httpx import URL, AsyncClient, Cookies, Headers +from httpx import URL, AsyncClient, Cookies, Headers, Timeout def test_client_base_url(): @@ -36,3 +36,16 @@ def test_client_cookies(): mycookies = list(client.cookies.jar) assert len(mycookies) == 1 assert mycookies[0].name == "a" and mycookies[0].value == "b" + + +def test_client_timeout(): + expected_timeout = 12.0 + client = AsyncClient() + + client.timeout = expected_timeout # type: ignore + + assert isinstance(client.timeout, Timeout) + assert client.timeout.connect == expected_timeout + assert client.timeout.read == expected_timeout + assert client.timeout.write == expected_timeout + assert client.timeout.pool == expected_timeout