MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / _extract_member

Method _extract_member

tools/python-3.11.9-amd64/Lib/zipfile.py:1718–1758  ·  view source on GitHub ↗

Extract the ZipInfo object 'member' to a physical file on the path targetpath.

(self, member, targetpath, pwd)

Source from the content-addressed store, hash-verified

1716 return arcname
1717
1718 def _extract_member(self, member, targetpath, pwd):
1719 """Extract the ZipInfo object 'member' to a physical
1720 file on the path targetpath.
1721 """
1722 if not isinstance(member, ZipInfo):
1723 member = self.getinfo(member)
1724
1725 # build the destination pathname, replacing
1726 # forward slashes to platform specific separators.
1727 arcname = member.filename.replace('/', os.path.sep)
1728
1729 if os.path.altsep:
1730 arcname = arcname.replace(os.path.altsep, os.path.sep)
1731 # interpret absolute pathname as relative, remove drive letter or
1732 # UNC path, redundant separators, "." and ".." components.
1733 arcname = os.path.splitdrive(arcname)[1]
1734 invalid_path_parts = ('', os.path.curdir, os.path.pardir)
1735 arcname = os.path.sep.join(x for x in arcname.split(os.path.sep)
1736 if x not in invalid_path_parts)
1737 if os.path.sep == '\\':
1738 # filter illegal characters on Windows
1739 arcname = self._sanitize_windows_name(arcname, os.path.sep)
1740
1741 targetpath = os.path.join(targetpath, arcname)
1742 targetpath = os.path.normpath(targetpath)
1743
1744 # Create all upper directories if necessary.
1745 upperdirs = os.path.dirname(targetpath)
1746 if upperdirs and not os.path.exists(upperdirs):
1747 os.makedirs(upperdirs)
1748
1749 if member.is_dir():
1750 if not os.path.isdir(targetpath):
1751 os.mkdir(targetpath)
1752 return targetpath
1753
1754 with self.open(member, pwd=pwd) as source, \
1755 open(targetpath, "wb") as target:
1756 shutil.copyfileobj(source, target)
1757
1758 return targetpath
1759
1760 def _writecheck(self, zinfo):
1761 """Check for errors before writing a file to the archive."""

Callers 2

extractMethod · 0.95
extractallMethod · 0.95

Calls 11

getinfoMethod · 0.95
openMethod · 0.95
openFunction · 0.70
replaceMethod · 0.45
joinMethod · 0.45
splitMethod · 0.45
existsMethod · 0.45
is_dirMethod · 0.45
isdirMethod · 0.45
mkdirMethod · 0.45

Tested by

no test coverage detected