Skip to content

Commit 89a8100

Browse files
authored
Replace remaining occurrences of dispatch with transport (#1010)
* Replace remaining occurrences of dispatch with transport * Remove unused AsyncDispatcher Was removed in #804 * Remove hard_limit warning in test
1 parent 8ed6904 commit 89a8100

File tree

10 files changed

+79
-80
lines changed

10 files changed

+79
-80
lines changed

httpx/_models.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,6 @@
5454
warn_deprecated,
5555
)
5656

57-
if typing.TYPE_CHECKING: # pragma: no cover
58-
from ._dispatch.base import AsyncDispatcher # noqa: F401
59-
6057

6158
class URL:
6259
def __init__(

httpx/_transports/asgi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,17 @@ class ASGITransport(httpcore.AsyncHTTPTransport):
3434
client = httpx.AsyncClient(app=app)
3535
```
3636
37-
Alternatively, you can setup the dispatch instance explicitly.
37+
Alternatively, you can setup the transport instance explicitly.
3838
This allows you to include any additional configuration arguments specific
3939
to the ASGITransport class:
4040
4141
```
42-
dispatch = httpx.ASGITransport(
42+
transport = httpx.ASGITransport(
4343
app=app,
4444
root_path="/submount",
4545
client=("1.2.3.4", 123)
4646
)
47-
client = httpx.AsyncClient(dispatch=dispatch)
47+
client = httpx.AsyncClient(transport=transport)
4848
```
4949
5050
Arguments:

httpx/_transports/wsgi.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,17 @@ class WSGITransport(httpcore.SyncHTTPTransport):
2525
client = httpx.Client(app=app)
2626
```
2727
28-
Alternatively, you can setup the dispatch instance explicitly.
28+
Alternatively, you can setup the transport instance explicitly.
2929
This allows you to include any additional configuration arguments specific
3030
to the WSGITransport class:
3131
3232
```
33-
dispatch = httpx.WSGITransport(
33+
transport = httpx.WSGITransport(
3434
app=app,
3535
script_name="/submount",
3636
remote_addr="1.2.3.4"
3737
)
38-
client = httpx.Client(dispatch=dispatch)
38+
client = httpx.Client(transport=transport)
3939
```
4040
4141
Arguments:

tests/client/test_auth.py

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ def get_header_value(headers, key, default=None):
2727
return default
2828

2929

30-
class MockDispatch(httpcore.AsyncHTTPTransport):
30+
class MockTransport(httpcore.AsyncHTTPTransport):
3131
def __init__(self, auth_header: bytes = b"", status_code: int = 200) -> None:
3232
self.auth_header = auth_header
3333
self.status_code = status_code
@@ -50,7 +50,7 @@ async def request(
5050
return b"HTTP/1.1", self.status_code, b"", response_headers, response_stream
5151

5252

53-
class MockDigestAuthDispatch(httpcore.AsyncHTTPTransport):
53+
class MockDigestAuthTransport(httpcore.AsyncHTTPTransport):
5454
def __init__(
5555
self,
5656
algorithm: str = "SHA-256",
@@ -119,7 +119,7 @@ async def test_basic_auth() -> None:
119119
url = "https://example.org/"
120120
auth = ("tomchristie", "password123")
121121

122-
client = AsyncClient(dispatch=MockDispatch())
122+
client = AsyncClient(transport=MockTransport())
123123
response = await client.get(url, auth=auth)
124124

125125
assert response.status_code == 200
@@ -130,7 +130,7 @@ async def test_basic_auth() -> None:
130130
async def test_basic_auth_in_url() -> None:
131131
url = "https://tomchristie:[email protected]/"
132132

133-
client = AsyncClient(dispatch=MockDispatch())
133+
client = AsyncClient(transport=MockTransport())
134134
response = await client.get(url)
135135

136136
assert response.status_code == 200
@@ -142,7 +142,7 @@ async def test_basic_auth_on_session() -> None:
142142
url = "https://example.org/"
143143
auth = ("tomchristie", "password123")
144144

145-
client = AsyncClient(dispatch=MockDispatch(), auth=auth)
145+
client = AsyncClient(transport=MockTransport(), auth=auth)
146146
response = await client.get(url)
147147

148148
assert response.status_code == 200
@@ -157,7 +157,7 @@ def auth(request: Request) -> Request:
157157
request.headers["Authorization"] = "Token 123"
158158
return request
159159

160-
client = AsyncClient(dispatch=MockDispatch())
160+
client = AsyncClient(transport=MockTransport())
161161
response = await client.get(url, auth=auth)
162162

163163
assert response.status_code == 200
@@ -169,7 +169,7 @@ async def test_netrc_auth() -> None:
169169
os.environ["NETRC"] = "tests/.netrc"
170170
url = "http://netrcexample.org"
171171

172-
client = AsyncClient(dispatch=MockDispatch())
172+
client = AsyncClient(transport=MockTransport())
173173
response = await client.get(url)
174174

175175
assert response.status_code == 200
@@ -183,7 +183,7 @@ async def test_auth_header_has_priority_over_netrc() -> None:
183183
os.environ["NETRC"] = "tests/.netrc"
184184
url = "http://netrcexample.org"
185185

186-
client = AsyncClient(dispatch=MockDispatch())
186+
client = AsyncClient(transport=MockTransport())
187187
response = await client.get(url, headers={"Authorization": "Override"})
188188

189189
assert response.status_code == 200
@@ -195,13 +195,13 @@ async def test_trust_env_auth() -> None:
195195
os.environ["NETRC"] = "tests/.netrc"
196196
url = "http://netrcexample.org"
197197

198-
client = AsyncClient(dispatch=MockDispatch(), trust_env=False)
198+
client = AsyncClient(transport=MockTransport(), trust_env=False)
199199
response = await client.get(url)
200200

201201
assert response.status_code == 200
202202
assert response.json() == {"auth": None}
203203

204-
client = AsyncClient(dispatch=MockDispatch(), trust_env=True)
204+
client = AsyncClient(transport=MockTransport(), trust_env=True)
205205
response = await client.get(url)
206206

207207
assert response.status_code == 200
@@ -222,7 +222,7 @@ async def test_auth_hidden_header() -> None:
222222
url = "https://example.org/"
223223
auth = ("example-username", "example-password")
224224

225-
client = AsyncClient(dispatch=MockDispatch())
225+
client = AsyncClient(transport=MockTransport())
226226
response = await client.get(url, auth=auth)
227227

228228
assert "'authorization': '[secure]'" in str(response.request.headers)
@@ -232,7 +232,7 @@ async def test_auth_hidden_header() -> None:
232232
async def test_auth_invalid_type() -> None:
233233
url = "https://example.org/"
234234
client = AsyncClient(
235-
dispatch=MockDispatch(), auth="not a tuple, not a callable", # type: ignore
235+
transport=MockTransport(), auth="not a tuple, not a callable", # type: ignore
236236
)
237237
with pytest.raises(TypeError):
238238
await client.get(url)
@@ -243,7 +243,7 @@ async def test_digest_auth_returns_no_auth_if_no_digest_header_in_response() ->
243243
url = "https://example.org/"
244244
auth = DigestAuth(username="tomchristie", password="password123")
245245

246-
client = AsyncClient(dispatch=MockDispatch())
246+
client = AsyncClient(transport=MockTransport())
247247
response = await client.get(url, auth=auth)
248248

249249
assert response.status_code == 200
@@ -258,7 +258,7 @@ async def test_digest_auth_200_response_including_digest_auth_header() -> None:
258258
auth_header = b'Digest realm="[email protected]",qop="auth",nonce="abc",opaque="xyz"'
259259

260260
client = AsyncClient(
261-
dispatch=MockDispatch(auth_header=auth_header, status_code=200)
261+
transport=MockTransport(auth_header=auth_header, status_code=200)
262262
)
263263
response = await client.get(url, auth=auth)
264264

@@ -272,7 +272,7 @@ async def test_digest_auth_401_response_without_digest_auth_header() -> None:
272272
url = "https://example.org/"
273273
auth = DigestAuth(username="tomchristie", password="password123")
274274

275-
client = AsyncClient(dispatch=MockDispatch(auth_header=b"", status_code=401))
275+
client = AsyncClient(transport=MockTransport(auth_header=b"", status_code=401))
276276
response = await client.get(url, auth=auth)
277277

278278
assert response.status_code == 401
@@ -300,7 +300,7 @@ async def test_digest_auth(
300300
url = "https://example.org/"
301301
auth = DigestAuth(username="tomchristie", password="password123")
302302

303-
client = AsyncClient(dispatch=MockDigestAuthDispatch(algorithm=algorithm))
303+
client = AsyncClient(transport=MockDigestAuthTransport(algorithm=algorithm))
304304
response = await client.get(url, auth=auth)
305305

306306
assert response.status_code == 200
@@ -330,7 +330,7 @@ async def test_digest_auth_no_specified_qop() -> None:
330330
url = "https://example.org/"
331331
auth = DigestAuth(username="tomchristie", password="password123")
332332

333-
client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=""))
333+
client = AsyncClient(transport=MockDigestAuthTransport(qop=""))
334334
response = await client.get(url, auth=auth)
335335

336336
assert response.status_code == 200
@@ -361,7 +361,7 @@ async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str)
361361
url = "https://example.org/"
362362
auth = DigestAuth(username="tomchristie", password="password123")
363363

364-
client = AsyncClient(dispatch=MockDigestAuthDispatch(qop=qop))
364+
client = AsyncClient(transport=MockDigestAuthTransport(qop=qop))
365365
response = await client.get(url, auth=auth)
366366

367367
assert response.status_code == 200
@@ -372,7 +372,7 @@ async def test_digest_auth_qop_including_spaces_and_auth_returns_auth(qop: str)
372372
async def test_digest_auth_qop_auth_int_not_implemented() -> None:
373373
url = "https://example.org/"
374374
auth = DigestAuth(username="tomchristie", password="password123")
375-
client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="auth-int"))
375+
client = AsyncClient(transport=MockDigestAuthTransport(qop="auth-int"))
376376

377377
with pytest.raises(NotImplementedError):
378378
await client.get(url, auth=auth)
@@ -382,7 +382,7 @@ async def test_digest_auth_qop_auth_int_not_implemented() -> None:
382382
async def test_digest_auth_qop_must_be_auth_or_auth_int() -> None:
383383
url = "https://example.org/"
384384
auth = DigestAuth(username="tomchristie", password="password123")
385-
client = AsyncClient(dispatch=MockDigestAuthDispatch(qop="not-auth"))
385+
client = AsyncClient(transport=MockDigestAuthTransport(qop="not-auth"))
386386

387387
with pytest.raises(ProtocolError):
388388
await client.get(url, auth=auth)
@@ -393,7 +393,9 @@ async def test_digest_auth_incorrect_credentials() -> None:
393393
url = "https://example.org/"
394394
auth = DigestAuth(username="tomchristie", password="password123")
395395

396-
client = AsyncClient(dispatch=MockDigestAuthDispatch(send_response_after_attempt=2))
396+
client = AsyncClient(
397+
transport=MockDigestAuthTransport(send_response_after_attempt=2)
398+
)
397399
response = await client.get(url, auth=auth)
398400

399401
assert response.status_code == 401
@@ -417,7 +419,7 @@ async def test_digest_auth_raises_protocol_error_on_malformed_header(
417419
url = "https://example.org/"
418420
auth = DigestAuth(username="tomchristie", password="password123")
419421
client = AsyncClient(
420-
dispatch=MockDispatch(auth_header=auth_header, status_code=401)
422+
transport=MockTransport(auth_header=auth_header, status_code=401)
421423
)
422424

423425
with pytest.raises(ProtocolError):
@@ -460,7 +462,7 @@ def auth_flow(
460462

461463
url = "https://example.org/"
462464
auth = RepeatAuth(repeat=2)
463-
client = AsyncClient(dispatch=MockDispatch(auth_header=b"abc"))
465+
client = AsyncClient(transport=MockTransport(auth_header=b"abc"))
464466

465467
response = await client.get(url, auth=auth)
466468
assert response.status_code == 200
@@ -481,7 +483,7 @@ def auth_flow(
481483
async def test_digest_auth_unavailable_streaming_body():
482484
url = "https://example.org/"
483485
auth = DigestAuth(username="tomchristie", password="password123")
484-
client = AsyncClient(dispatch=MockDispatch())
486+
client = AsyncClient(transport=MockTransport())
485487

486488
async def streaming_body():
487489
yield b"Example request body" # pragma: nocover
@@ -520,7 +522,7 @@ def auth_flow(
520522

521523
url = "https://example.org/"
522524
auth = ResponseBodyAuth("xyz")
523-
client = AsyncClient(dispatch=MockDispatch())
525+
client = AsyncClient(transport=MockTransport())
524526

525527
response = await client.get(url, auth=auth)
526528
assert response.status_code == 200

tests/client/test_cookies.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def get_header_value(headers, key, default=None):
1616
return default
1717

1818

19-
class MockDispatch(httpcore.AsyncHTTPTransport):
19+
class MockTransport(httpcore.AsyncHTTPTransport):
2020
async def request(
2121
self,
2222
method: bytes,
@@ -48,7 +48,7 @@ async def test_set_cookie() -> None:
4848
url = "http://example.org/echo_cookies"
4949
cookies = {"example-name": "example-value"}
5050

51-
client = AsyncClient(dispatch=MockDispatch())
51+
client = AsyncClient(transport=MockTransport())
5252
response = await client.get(url, cookies=cookies)
5353

5454
assert response.status_code == 200
@@ -84,7 +84,7 @@ async def test_set_cookie_with_cookiejar() -> None:
8484
)
8585
cookies.set_cookie(cookie)
8686

87-
client = AsyncClient(dispatch=MockDispatch())
87+
client = AsyncClient(transport=MockTransport())
8888
response = await client.get(url, cookies=cookies)
8989

9090
assert response.status_code == 200
@@ -120,7 +120,7 @@ async def test_setting_client_cookies_to_cookiejar() -> None:
120120
)
121121
cookies.set_cookie(cookie)
122122

123-
client = AsyncClient(dispatch=MockDispatch())
123+
client = AsyncClient(transport=MockTransport())
124124
client.cookies = cookies # type: ignore
125125
response = await client.get(url)
126126

@@ -138,7 +138,7 @@ async def test_set_cookie_with_cookies_model() -> None:
138138
cookies = Cookies()
139139
cookies["example-name"] = "example-value"
140140

141-
client = AsyncClient(dispatch=MockDispatch())
141+
client = AsyncClient(transport=MockTransport())
142142
response = await client.get(url, cookies=cookies)
143143

144144
assert response.status_code == 200
@@ -149,7 +149,7 @@ async def test_set_cookie_with_cookies_model() -> None:
149149
async def test_get_cookie() -> None:
150150
url = "http://example.org/set_cookie"
151151

152-
client = AsyncClient(dispatch=MockDispatch())
152+
client = AsyncClient(transport=MockTransport())
153153
response = await client.get(url)
154154

155155
assert response.status_code == 200
@@ -162,7 +162,7 @@ async def test_cookie_persistence() -> None:
162162
"""
163163
Ensure that Client instances persist cookies between requests.
164164
"""
165-
client = AsyncClient(dispatch=MockDispatch())
165+
client = AsyncClient(transport=MockTransport())
166166

167167
response = await client.get("http://example.org/echo_cookies")
168168
assert response.status_code == 200

0 commit comments

Comments
 (0)