A high-throughput and memory-efficient inference and serving engine for LLMs
Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git
Synced Nov 9, 19:30 UTC
[Misc] Replace urllib's `urlparse` with urllib3's `parse_url` (#32746)
Signed-off-by: Isotr0py <mozf@mail2.sysu.edu.cn>
Isotr0py committed
Jan 22, 2026 at 16:37 UTC
8ebf271bb6d1e7e9b1a55be73d755ef1a57dbbe5
4 files changed
+23
-16
vllm/connections.py
+2
-2
@@ -3,10 +3,10 @@
3
4
from collections.abc import Mapping, MutableMapping
5
from pathlib import Path
6
-from urllib.parse import urlparse
6
7
import aiohttp
8
import requests
9
+from urllib3.util import parse_url
10
11
from vllm.version import __version__ as VLLM_VERSION
12
@@ -37,7 +37,7 @@ class HTTPConnection:
37
return self._async_client
38
39
def _validate_http_url(self, url: str):
40
- parsed_url = urlparse(url)
40
+ parsed_url = parse_url(url)
41
42
if parsed_url.scheme not in ("http", "https"):
43
raise ValueError(
vllm/envs.py
+2
-2
@@ -439,9 +439,9 @@ def get_vllm_port() -> int | None:
439
try:
440
return int(port)
441
except ValueError as err:
442
- from urllib.parse import urlparse
442
+ from urllib3.util import parse_url
443
444
- parsed = urlparse(port)
444
+ parsed = parse_url(port)
445
if parsed.scheme:
446
raise ValueError(
447
f"VLLM_PORT '{port}' appears to be a URI. "
vllm/multimodal/utils.py
+15
-10
@@ -9,13 +9,13 @@ from concurrent.futures import ThreadPoolExecutor
9
from itertools import groupby
10
from pathlib import Path
11
from typing import TYPE_CHECKING, Any, TypeVar
12
-from urllib.parse import ParseResult, urlparse
12
from urllib.request import url2pathname
13
14
import numpy as np
15
import numpy.typing as npt
16
import torch
17
from PIL import Image, UnidentifiedImageError
18
+from urllib3.util import Url, parse_url
19
20
import vllm.envs as envs
21
from vllm.connections import HTTPConnection, global_http_connection
@@ -105,11 +105,14 @@ class MediaConnector:
105
106
def _load_data_url(
107
self,
108
- url_spec: ParseResult,
108
+ url_spec: Url,
109
media_io: MediaIO[_M],
110
) -> _M: # type: ignore[type-var]
111
- data_spec, data = url_spec.path.split(",", 1)
111
+ url_spec_path = url_spec.path or ""
112
+ data_spec, data = url_spec_path.split(",", 1)
113
media_type, data_type = data_spec.split(";", 1)
114
+ # media_type starts with a leading "/" (e.g., "/video/jpeg")
115
+ media_type = media_type.lstrip("/")
116
117
if data_type != "base64":
118
msg = "Only base64 data URLs are supported for now."
@@ -119,7 +122,7 @@ class MediaConnector:
122
123
def _load_file_url(
124
self,
122
- url_spec: ParseResult,
125
+ url_spec: Url,
126
media_io: MediaIO[_M],
127
) -> _M: # type: ignore[type-var]
128
allowed_local_media_path = self.allowed_local_media_path
@@ -128,7 +131,9 @@ class MediaConnector:
131
"Cannot load local files without `--allowed-local-media-path`."
132
)
133
131
- filepath = Path(url2pathname(url_spec.netloc + url_spec.path))
134
+ url_spec_path = url_spec.path or ""
135
+ url_spec_netloc = url_spec.netloc or ""
136
+ filepath = Path(url2pathname(url_spec_netloc + url_spec_path))
137
if allowed_local_media_path not in filepath.resolve().parents:
138
raise ValueError(
139
f"The file path {filepath} must be a subpath "
@@ -137,7 +142,7 @@ class MediaConnector:
142
143
return media_io.load_file(filepath)
144
140
- def _assert_url_in_allowed_media_domains(self, url_spec: ParseResult) -> None:
145
+ def _assert_url_in_allowed_media_domains(self, url_spec: Url) -> None:
146
if (
147
self.allowed_media_domains
148
and url_spec.hostname not in self.allowed_media_domains
@@ -155,9 +160,9 @@ class MediaConnector:
160
*,
161
fetch_timeout: int | None = None,
162
) -> _M: # type: ignore[type-var]
158
- url_spec = urlparse(url)
163
+ url_spec = parse_url(url)
164
160
- if url_spec.scheme.startswith("http"):
165
+ if url_spec.scheme and url_spec.scheme.startswith("http"):
166
self._assert_url_in_allowed_media_domains(url_spec)
167
168
connection = self.connection
@@ -185,10 +190,10 @@ class MediaConnector:
190
*,
191
fetch_timeout: int | None = None,
192
) -> _M:
188
- url_spec = urlparse(url)
193
+ url_spec = parse_url(url)
194
loop = asyncio.get_running_loop()
195
191
- if url_spec.scheme.startswith("http"):
196
+ if url_spec.scheme and url_spec.scheme.startswith("http"):
197
self._assert_url_in_allowed_media_domains(url_spec)
198
199
connection = self.connection
vllm/utils/network_utils.py
+4
-2
@@ -11,12 +11,12 @@ from collections.abc import (
11
Sequence,
12
)
13
from typing import Any
14
-from urllib.parse import urlparse
14
from uuid import uuid4
15
16
import psutil
17
import zmq
18
import zmq.asyncio
19
+from urllib3.util import parse_url
20
21
import vllm.envs as envs
22
from vllm.logger import init_logger
@@ -217,13 +217,15 @@ def find_process_using_port(port: int) -> psutil.Process | None:
217
218
def split_zmq_path(path: str) -> tuple[str, str, str]:
219
"""Split a zmq path into its parts."""
220
- parsed = urlparse(path)
220
+ parsed = parse_url(path)
221
if not parsed.scheme:
222
raise ValueError(f"Invalid zmq path: {path}")
223
224
scheme = parsed.scheme
225
host = parsed.hostname or ""
226
port = str(parsed.port or "")
227
+ if host.startswith("[") and host.endswith("]"):
228
+ host = host[1:-1] # Remove brackets for IPv6 address
229
230
if scheme == "tcp" and not all((host, port)):
231
# The host and port fields are required for tcp