File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -211,14 +211,15 @@ def __str__(self) -> str:
211211
212212
213213def _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
224225def urlparse (url : str = "" , ** kwargs : str | None ) -> ParseResult :
You can’t perform that action at this time.
0 commit comments