extract_zipped_paths() — requests Function Reference
Architecture documentation for the extract_zipped_paths() function in utils.py from the requests codebase.
Entity Profile
Dependency Diagram
graph TD 43bfb55b_6419_5997_8140_872a62e09796["extract_zipped_paths()"] 2c39b9da_e317_5e6c_bbac_8362bac2110c["utils.py"] 43bfb55b_6419_5997_8140_872a62e09796 -->|defined in| 2c39b9da_e317_5e6c_bbac_8362bac2110c f3317fc3_a2fa_ce2a_bb1a_4f53b0443c40["cert_verify()"] f3317fc3_a2fa_ce2a_bb1a_4f53b0443c40 -->|calls| 43bfb55b_6419_5997_8140_872a62e09796 81958e94_0b68_fef6_ea31_76646323e79a["atomic_open()"] 43bfb55b_6419_5997_8140_872a62e09796 -->|calls| 81958e94_0b68_fef6_ea31_76646323e79a style 43bfb55b_6419_5997_8140_872a62e09796 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/requests/utils.py lines 256–290
def extract_zipped_paths(path):
"""Replace nonexistent paths that look like they refer to a member of a zip
archive with the location of an extracted copy of the target, or else
just return the provided path unchanged.
"""
if os.path.exists(path):
# this is already a valid path, no need to do anything further
return path
# find the first valid part of the provided path and treat that as a zip archive
# assume the rest of the path is the name of a member in the archive
archive, member = os.path.split(path)
while archive and not os.path.exists(archive):
archive, prefix = os.path.split(archive)
if not prefix:
# If we don't check for an empty prefix after the split (in other words, archive remains unchanged after the split),
# we _can_ end up in an infinite loop on a rare corner case affecting a small number of users
break
member = "/".join([prefix, member])
if not zipfile.is_zipfile(archive):
return path
zip_file = zipfile.ZipFile(archive)
if member not in zip_file.namelist():
return path
# we have a valid zip archive and a valid member of that archive
tmp = tempfile.gettempdir()
extracted_path = os.path.join(tmp, member.split("/")[-1])
if not os.path.exists(extracted_path):
# use read + write to avoid the creating nested folders, we only want the file, avoids mkdir racing condition
with atomic_open(extracted_path) as file_handler:
file_handler.write(zip_file.read(member))
return extracted_path
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does extract_zipped_paths() do?
extract_zipped_paths() is a function in the requests codebase, defined in src/requests/utils.py.
Where is extract_zipped_paths() defined?
extract_zipped_paths() is defined in src/requests/utils.py at line 256.
What does extract_zipped_paths() call?
extract_zipped_paths() calls 1 function(s): atomic_open.
What calls extract_zipped_paths()?
extract_zipped_paths() is called by 1 function(s): cert_verify.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free