Skip to content

Commit d5038e6

Browse files
committed
simplify unix_socket
1 parent 1593090 commit d5038e6

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

mureq.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
JsonValue = None | bool | int | float | str | list["JsonValue"] | dict[str, "JsonValue"]
4242

4343

44-
def request(method, url, *, read_limit=None, **kwargs):
44+
def request(method: str, url: str, *, read_limit: int | None = None, **kwargs) -> "Response":
4545
"""Request performs an HTTP request and reads the entire response body.
4646
4747
:param str method: HTTP method to request (e.g. 'GET', 'POST')
@@ -425,11 +425,11 @@ def _prepare_request(
425425
"""Parses the URL, returns the path and the right HTTPConnection subclass."""
426426
parsed_url = urllib.parse.urlparse(url)
427427

428-
is_unix = unix_socket is not None
429428
scheme = parsed_url.scheme.lower()
430429
if scheme.endswith("+unix"):
431430
scheme = scheme[:-5]
432-
is_unix = True
431+
if unix_socket is None:
432+
unix_socket = urllib.parse.unquote(parsed_url.netloc)
433433
if scheme == "https":
434434
raise ValueError("https+unix is not implemented")
435435

@@ -444,9 +444,6 @@ def _prepare_request(
444444
if parsed_url.port:
445445
port = parsed_url.port
446446

447-
if is_unix and unix_socket is None:
448-
unix_socket = urllib.parse.unquote(parsed_url.netloc)
449-
450447
path = parsed_url.path
451448
if parsed_url.query:
452449
if enc_params:
@@ -462,7 +459,7 @@ def _prepare_request(
462459
source_address = (source_address, 0)
463460

464461
conn: HTTPConnection | UnixHTTPConnection | HTTPSConnection
465-
if is_unix:
462+
if unix_socket is not None:
466463
conn = UnixHTTPConnection(unix_socket, timeout=timeout)
467464
elif is_https:
468465
if ssl_context is None:

0 commit comments

Comments
 (0)