mirror of
https://github.com/python/cpython.git
synced 2025-09-01 22:47:59 +00:00
Make sure path names inserted into ZIP files are normalized to use "/" as
the directory separator, as required by the format specification. This closes SF bug #440693.
This commit is contained in:
parent
d4f7f609bf
commit
a58947f600
1 changed files with 12 additions and 1 deletions
|
@ -89,7 +89,7 @@ class ZipInfo:
|
||||||
"""Class with attributes describing each file in the ZIP archive."""
|
"""Class with attributes describing each file in the ZIP archive."""
|
||||||
|
|
||||||
def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
|
def __init__(self, filename="NoName", date_time=(1980,1,1,0,0,0)):
|
||||||
self.filename = filename # Name of the file in the archive
|
self.filename = _normpath(filename) # Name of the file in the archive
|
||||||
self.date_time = date_time # year, month, day, hour, min, sec
|
self.date_time = date_time # year, month, day, hour, min, sec
|
||||||
# Standard values:
|
# Standard values:
|
||||||
self.compress_type = ZIP_STORED # Type of compression for the file
|
self.compress_type = ZIP_STORED # Type of compression for the file
|
||||||
|
@ -130,6 +130,17 @@ class ZipInfo:
|
||||||
return header + self.filename + self.extra
|
return header + self.filename + self.extra
|
||||||
|
|
||||||
|
|
||||||
|
# This is used to ensure paths in generated ZIP files always use
|
||||||
|
# forward slashes as the directory separator, as required by the
|
||||||
|
# ZIP format specification.
|
||||||
|
if os.sep != "/":
|
||||||
|
def _normpath(path):
|
||||||
|
return path.replace(os.sep, "/")
|
||||||
|
else:
|
||||||
|
def _normpath(path):
|
||||||
|
return path
|
||||||
|
|
||||||
|
|
||||||
class ZipFile:
|
class ZipFile:
|
||||||
""" Class with methods to open, read, write, close, list zip files.
|
""" Class with methods to open, read, write, close, list zip files.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue