Skip to content

Commit

Permalink
Cleanup constant naming in _url.py (#1354)
Browse files Browse the repository at this point in the history
  • Loading branch information
bdraco authored Oct 21, 2024
1 parent 8f98545 commit 088dafb
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions yarl/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,18 @@

# Leading and trailing C0 control and space to be stripped per WHATWG spec.
# == "".join([chr(i) for i in range(0, 0x20 + 1)])
_WHATWG_C0_CONTROL_OR_SPACE = (
WHATWG_C0_CONTROL_OR_SPACE = (
"\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10"
"\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f "
)

# Unsafe bytes to be removed per WHATWG spec
_UNSAFE_URL_BYTES_TO_REMOVE = ["\t", "\r", "\n"]
UNSAFE_URL_BYTES_TO_REMOVE = ["\t", "\r", "\n"]

# reg-name: unreserved / pct-encoded / sub-delims
# this pattern matches anything that is *not* in those classes. and is only used
# on lower-cased ASCII values.
_not_reg_name = re.compile(
NOT_REG_NAME = re.compile(
r"""
# any character not in the unreserved or sub-delims sets, plus %
# (validated with the additional check for pct-encoded sequences below)
Expand Down Expand Up @@ -160,8 +160,8 @@ def _split_url(url: str) -> SplitResult:
# Adapted from urllib.parse.urlsplit
# Only lstrip url as some applications rely on preserving trailing space.
# (https://url.spec.whatwg.org/#concept-basic-url-parser would strip both)
url = url.lstrip(_WHATWG_C0_CONTROL_OR_SPACE)
for b in _UNSAFE_URL_BYTES_TO_REMOVE:
url = url.lstrip(WHATWG_C0_CONTROL_OR_SPACE)
for b in UNSAFE_URL_BYTES_TO_REMOVE:
if b in url:
url = url.replace(b, "")

Expand Down Expand Up @@ -1764,7 +1764,7 @@ def _ip_compressed_version(raw_ip: str) -> tuple[str, int]:
@lru_cache(_MAXCACHE)
def _host_validate(host: str) -> None:
"""Validate an ascii host name."""
invalid = _not_reg_name.search(host)
invalid = NOT_REG_NAME.search(host)
if invalid is None:
return
value, pos, extra = invalid.group(), invalid.start(), ""
Expand Down

0 comments on commit 088dafb

Please sign in to comment.