@@ -212,45 +212,6 @@ def make_zipfile(zip_filename, *base_dirs, timestamp=None,
212212 name of the output zip file.
213213 """
214214
215- # Borrowed from python 3.8 zipfile.py library
216- # due to the need of strict_timestamps functionality.
217- def from_file (cls , filename , arcname = None , * , strict_timestamps = True ):
218- """Construct an appropriate ZipInfo for a file on the filesystem.
219-
220- filename should be the path to a file or directory on the filesystem.
221-
222- arcname is the name which it will have within the archive (by default,
223- this will be the same as filename, but without a drive letter and with
224- leading path separators removed).
225- """
226- if isinstance (filename , os .PathLike ):
227- filename = os .fspath (filename )
228- st = os .stat (filename )
229- isdir = stat .S_ISDIR (st .st_mode )
230- mtime = time .localtime (st .st_mtime )
231- date_time = mtime [0 :6 ]
232- if not strict_timestamps and date_time [0 ] < 1980 :
233- date_time = (1980 , 1 , 1 , 0 , 0 , 0 )
234- elif not strict_timestamps and date_time [0 ] > 2107 :
235- date_time = (2107 , 12 , 31 , 23 , 59 , 59 )
236- # Create ZipInfo instance to store file information
237- if arcname is None :
238- arcname = filename
239- arcname = os .path .normpath (os .path .splitdrive (arcname )[1 ])
240- while arcname [0 ] in (os .sep , os .altsep ):
241- arcname = arcname [1 :]
242- if isdir :
243- arcname += '/'
244- zinfo = cls (arcname , date_time )
245- zinfo .external_attr = (st .st_mode & 0xFFFF ) << 16 # Unix attributes
246- if isdir :
247- zinfo .file_size = 0
248- zinfo .external_attr |= 0x10 # MS-DOS directory flag
249- else :
250- zinfo .file_size = st .st_size
251-
252- return zinfo
253-
254215 # An extended version of a write method
255216 # from the original zipfile.py library module
256217 def write (self , filename , arcname = None ,
@@ -474,6 +435,46 @@ def write_file_obj(self, file_path, data, prefix=None, timestamp=None):
474435 if self ._isopen ():
475436 raise NotImplementedError
476437
438+ # Borrowed from python 3.8 zipfile.py library
439+ # due to the need of strict_timestamps functionality.
440+ @staticmethod
441+ def _zinfo_from_file (filename , arcname = None , * , strict_timestamps = True ):
442+ """Construct an appropriate ZipInfo for a file on the filesystem.
443+
444+ filename should be the path to a file or directory on the filesystem.
445+
446+ arcname is the name which it will have within the archive (by default,
447+ this will be the same as filename, but without a drive letter and with
448+ leading path separators removed).
449+ """
450+ if isinstance (filename , os .PathLike ):
451+ filename = os .fspath (filename )
452+ st = os .stat (filename )
453+ isdir = stat .S_ISDIR (st .st_mode )
454+ mtime = time .localtime (st .st_mtime )
455+ date_time = mtime [0 :6 ]
456+ if not strict_timestamps and date_time [0 ] < 1980 :
457+ date_time = (1980 , 1 , 1 , 0 , 0 , 0 )
458+ elif not strict_timestamps and date_time [0 ] > 2107 :
459+ date_time = (2107 , 12 , 31 , 23 , 59 , 59 )
460+ # Create ZipInfo instance to store file information
461+ if arcname is None :
462+ arcname = filename
463+ arcname = os .path .normpath (os .path .splitdrive (arcname )[1 ])
464+ while arcname [0 ] in (os .sep , os .altsep ):
465+ arcname = arcname [1 :]
466+ if isdir :
467+ arcname += '/'
468+ zinfo = zipfile .ZipInfo (arcname , date_time )
469+ zinfo .external_attr = (st .st_mode & 0xFFFF ) << 16 # Unix attributes
470+ if isdir :
471+ zinfo .file_size = 0
472+ zinfo .external_attr |= 0x10 # MS-DOS directory flag
473+ else :
474+ zinfo .file_size = st .st_size
475+
476+ return zinfo
477+
477478
478479################################################################################
479480# Docker building
0 commit comments