Lines Matching +full:format +full:- +full:extra +full:- +full:args
4 XXX references to utf-8 need further investigation.
53 error = BadZipfile = BadZipFile # Pre-3.2 compatibility names
56 ZIP64_LIMIT = (1 << 31) - 1
57 ZIP_FILECOUNT_LIMIT = (1 << 16) - 1
58 ZIP_MAX_COMMENT = (1 << 16) - 1
76 # in the PKWARE description of the ZIP file format:
81 # (section V.I in the format document)
100 # of entries in the structure (section V.F in the format document)
132 # _MASK_USE_DATA_DESCRIPTOR: If set, crc-32, compressed size and uncompressed
153 # (section V.A in the format document)
177 # (section V.G in the format document)
197 def _strip_extra(extra, xids): argument
198 # Remove Extra Fields with specified IDs.
203 while i + 4 <= len(extra):
204 xid, xlen = unpack(extra[i : i + 4])
208 buffer.append(extra[start : i])
213 return extra
214 if start != len(extra):
215 buffer.append(extra[start:])
229 The filename argument may be a file or file-like object too.
244 Read the ZIP64 end-of-archive records and use that to update endrec
247 fpin.seek(offset - sizeEndCentDir64Locator, 2)
250 # end-of-archive record, so just return the end record we were given.
264 fpin.seek(offset - sizeEndCentDir64Locator - sizeEndCentDir64, 2)
299 fpin.seek(-sizeEndCentDir, 2)
305 data[-2:] == b"\000\000"):
312 endrec.append(filesize - sizeEndCentDir)
315 return _EndRecData64(fpin, -sizeEndCentDir, endrec)
322 maxCommentStart = max(filesize - (1 << 16) - sizeEndCentDir, 0)
339 return _EndRecData64(fpin, maxCommentStart + start - filesize,
356 'extra',
383 # ZIP format specification.
397 self.extra = b"" # ZIP extra data
401 # Assume everything else is unix-y
415 # CRC CRC-32 of the uncompressed file
440 """Return the per-file header as a bytes object.
447 dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2]
457 extra = self.extra
466 extra = extra + struct.pack(fmt,
467 1, struct.calcsize(fmt)-4, file_size, compress_size)
484 len(filename), len(extra))
485 return header + filename + extra
491 return self.filename.encode('utf-8'), self.flag_bits | _MASK_UTF_FILENAME
494 # Try to decode the extra field.
495 extra = self.extra
497 while len(extra) >= 4:
498 tp, ln = unpack('<HH', extra[:4])
499 if ln+4 > len(extra):
500 raise BadZipFile("Corrupt extra field %04x (size=%d)" % (tp, ln))
502 data = extra[4:ln+4]
517 raise BadZipFile(f"Corrupt zip64 extra field. "
520 extra = extra[ln+4:]
554 zinfo.external_attr |= 0x10 # MS-DOS directory flag
562 return self.filename[-1] == '/'
565 # ZIP encryption uses the CRC32 one-byte primitive for scrambling some
578 # ZIP supports a password-based form of encryption. Even though known
717 return zlib.compressobj(compresslevel, zlib.DEFLATED, -15)
718 return zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15)
735 return zlib.decompressobj(-15)
770 def read(self, n=-1):
809 """File-like object for reading an archive member.
814 MAX_N = 1 << 31 - 1
881 self._compress_left -= 12
898 def readline(self, limit=-1):
905 # Shortcut common case - newline found in buffer.
916 if n > len(self._readbuffer) - self._offset:
922 self._offset -= len(chunk)
932 def read(self, n=-1):
952 n = end - len(self._readbuffer)
964 n -= len(data)
975 raise BadZipFile("Bad CRC-32 for file %r" % self.name)
997 n = end - len(self._readbuffer)
1025 data += self._read2(n - len(data))
1044 self._left -= len(data)
1058 self._compress_left -= len(data)
1100 read_offset = new_pos - curr_pos
1124 read_offset -= read_len
1133 filepos = self._orig_file_size - self._left - len(self._readbuffer) + self._offset
1227 file: Either the path to the file, or a file-like object.
1274 # Check if we were passed a file-like object
1316 # Some file-like objects can provide tell() but not seek()
1379 concat = endrec[_ECD_LOCATION] - size_cd - offset_cd
1382 concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator)
1407 # UTF-8 file names extension
1408 filename = filename.decode('utf-8')
1414 x.extra = fp.read(centdir[_CD_EXTRA_FIELD_LENGTH])
1460 print("%-46s %19s %12s" % ("File Name", "Modified ", "Size"),
1463 date = "%d-%02d-%02d %02d:%02d:%02d" % zinfo.date_time[:6]
1464 print("%-46s %s %12d" % (zinfo.filename, date, zinfo.file_size),
1475 while f.read(chunk_size): # Check CRC-32
1522 """Return file-like object for 'name'.
1533 2 GiB, pass force_zip64 to use the ZIP64 format, which can handle large
1591 # UTF-8 filename
1592 fname_str = fname.decode("utf-8")
1640 # Compressed data includes an end-of-stream (EOS) marker
1646 zinfo.external_attr = 0o600 << 16 # permissions: ?rw-------
1812 it is encoded as UTF-8 first.
1816 data = data.encode("utf-8")
1822 if zinfo.filename[-1] == '/':
1823 zinfo.external_attr = 0o40775 << 16 # drwxrwxr-x
1824 zinfo.external_attr |= 0x10 # MS-DOS directory flag
1826 zinfo.external_attr = 0o600 << 16 # ?rw-------
1873 # Compressed data includes an end-of-stream (EOS) marker
1913 dosdate = (dt[0] - 1980) << 9 | dt[1] << 5 | dt[2]
1915 extra = []
1918 extra.append(zinfo.file_size)
1919 extra.append(zinfo.compress_size)
1927 extra.append(zinfo.header_offset)
1932 extra_data = zinfo.extra
1934 if extra:
1935 # Append a ZIP64 field to the extra's
1938 '<HH' + 'Q'*len(extra),
1939 1, 8*len(extra), *extra) + extra_data
1965 # Write end-of-zip-archive record
1967 centDirSize = pos2 - self.start_dir
1977 # Need to write the ZIP64 end-of-archive records
2006 self._fileRefCnt -= 1
2015 allowZip64=True, optimize=-1):
2051 fname, arcname = self._get_codename(initname[0:-3], basename)
2071 fname, arcname = self._get_codename(path[0:-3],
2088 fname, arcname = self._get_codename(path[0:-3],
2094 if pathname[-3:] != ".py":
2097 fname, arcname = self._get_codename(pathname[0:-3], basename)
2109 def _compile(file, optimize=-1):
2125 if self._optimize == -1:
2173 msg = "invalid value for 'optimize': {!r}".format(self._optimize)
2290 # Only allow for FastLookup when supplied zipfile is read-only
2317 def _extract_text_encoding(encoding=None, *args, **kwargs): argument
2319 return io.text_encoding(encoding, 3), args, kwargs
2324 A pathlib-compatible interface for zip files.
2415 def open(self, mode='r', *args, pwd=None, **kwargs): argument
2428 if args or kwargs:
2429 raise ValueError("encoding args invalid for binary operation")
2432 encoding, args, kwargs = _extract_text_encoding(*args, **kwargs)
2433 return io.TextIOWrapper(stream, encoding, *args, **kwargs)
2455 def read_text(self, *args, **kwargs): argument
2456 encoding, args, kwargs = _extract_text_encoding(*args, **kwargs)
2457 with self.open('r', encoding, *args, **kwargs) as strm:
2489 return self.__repr.format(self=self)
2507 def main(args=None): argument
2510 description = 'A simple command-line interface for zipfile module.'
2513 group.add_argument('-l', '--list', metavar='<zipfile>',
2515 group.add_argument('-e', '--extract', nargs=2,
2518 group.add_argument('-c', '--create', nargs='+',
2521 group.add_argument('-t', '--test', metavar='<zipfile>',
2523 parser.add_argument('--metadata-encoding', metavar='<encoding>',
2524 help='Specify encoding of member names for -l, -e and -t')
2525 args = parser.parse_args(args)
2527 encoding = args.metadata_encoding
2529 if args.test is not None:
2530 src = args.test
2534 print("The following enclosed file is corrupted: {!r}".format(badfile))
2537 elif args.list is not None:
2538 src = args.list
2542 elif args.extract is not None:
2543 src, curdir = args.extract
2547 elif args.create is not None:
2549 print("Non-conforming encodings not supported with -c.",
2553 zip_name = args.create.pop(0)
2554 files = args.create