Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/requests/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

# Detect which major version of urllib3 is being used.
try:
is_urllib3_1 = int(urllib3_version.split(".")[0]) == 1
is_urllib3_1 = int(urllib3_version.partition(".")[0]) == 1
except (TypeError, AttributeError):
# If we can't discern a version, prefer old functionality.
is_urllib3_1 = True
Expand Down
20 changes: 8 additions & 12 deletions src/requests/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def extract_zipped_paths(path: str) -> str:
return path

# we have a valid zip archive and a valid member of that archive
suffix = os.path.splitext(member.split("/")[-1])[-1]
suffix = os.path.splitext(member.rpartition("/")[2])[-1]
fd, extracted_path = tempfile.mkstemp(suffix=suffix)
try:
os.write(fd, zip_file.read(member))
Expand Down Expand Up @@ -464,7 +464,7 @@ def parse_dict_header(value: str) -> dict[str, str | None]:
if "=" not in item:
result[item] = None
continue
name, value = item.split("=", 1)
name, _, value = item.partition("=")
if value[:1] == value[-1:] == '"':
value = unquote_header_value(value[1:-1])
result[name] = value
Expand Down Expand Up @@ -768,15 +768,15 @@ def is_valid_cidr(string_network: str) -> bool:
"""
if string_network.count("/") == 1:
try:
mask = int(string_network.split("/")[1])
mask = int(string_network.partition("/")[2])
except ValueError:
return False

if mask < 1 or mask > 32:
return False

try:
socket.inet_aton(string_network.split("/")[0])
socket.inet_aton(string_network.partition("/")[0])
except OSError:
return False
else:
Expand Down Expand Up @@ -979,17 +979,13 @@ def parse_header_links(value: str) -> list[dict[str, str]]:
return links

for val in re.split(", *<", value):
try:
url, params = val.split(";", 1)
except ValueError:
url, params = val, ""
url, _, params = val.partition(";")

link: dict[str, str] = {"url": url.strip("<> '\"")}

for param in params.split(";"):
try:
key, value = param.split("=")
except ValueError:
key, sep, value = param.partition("=")
if not sep:
break

link[key.strip(replace_chars)] = value.strip(replace_chars)
Expand Down Expand Up @@ -1131,7 +1127,7 @@ def urldefragauth(url: str) -> str:
if not netloc:
netloc, path = path, netloc

netloc = netloc.rsplit("@", 1)[-1]
netloc = netloc.rpartition("@")[2]

return urlunparse((scheme, netloc, path, params, query, ""))

Expand Down
Loading