Skip to content

Commit b7b0224

Browse files
committed
chore: rollback to use any to check chars
1 parent 1811889 commit b7b0224

1 file changed

Lines changed: 9 additions & 8 deletions

File tree

httpx/_urlparse.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,14 +211,15 @@ def __str__(self) -> str:
211211

212212

213213
def _check_ascii_printable(url: str, key: str | None = None) -> None:
214-
for idx, char in enumerate(url):
215-
if char.isascii() and not char.isprintable():
216-
error = "Invalid non-printable ASCII character in URL"
217-
if key is None:
218-
error += f", {char!r} at position {idx}."
219-
else:
220-
error += f" {key} component, {char!r} at position {idx}."
221-
raise InvalidURL(error)
214+
if any(char.isascii() and not char.isprintable() for char in url):
215+
char = next(char for char in url if char.isascii() and not char.isprintable())
216+
idx = url.find(char)
217+
component = f" {key} component" if key else ""
218+
error = (
219+
f"Invalid non-printable ASCII character in URL{component},"
220+
f" {char!r} at position {idx}."
221+
)
222+
raise InvalidURL(error)
222223

223224

224225
def urlparse(url: str = "", **kwargs: str | None) -> ParseResult:

0 commit comments

Comments
 (0)