Extract the ZipInfo object 'member' to a physical file on the path targetpath.
(self, member, targetpath, pwd)
| 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.""" |