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

Method _RealGetContents

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

Read in the table of contents for the ZIP file.

(self)

Source from the content-addressed store, hash-verified

1369 return ''.join(result)
1370
1371 def _RealGetContents(self):
1372 """Read in the table of contents for the ZIP file."""
1373 fp = self.fp
1374 try:
1375 endrec = _EndRecData(fp)
1376 except OSError:
1377 raise BadZipFile("File is not a zip file")
1378 if not endrec:
1379 raise BadZipFile("File is not a zip file")
1380 if self.debug > 1:
1381 print(endrec)
1382 size_cd = endrec[_ECD_SIZE] # bytes in central directory
1383 offset_cd = endrec[_ECD_OFFSET] # offset of central directory
1384 self._comment = endrec[_ECD_COMMENT] # archive comment
1385
1386 # "concat" is zero, unless zip was concatenated to another file
1387 concat = endrec[_ECD_LOCATION] - size_cd - offset_cd
1388 if endrec[_ECD_SIGNATURE] == stringEndArchive64:
1389 # If Zip64 extension structures are present, account for them
1390 concat -= (sizeEndCentDir64 + sizeEndCentDir64Locator)
1391
1392 if self.debug > 2:
1393 inferred = concat + offset_cd
1394 print("given, inferred, offset", offset_cd, inferred, concat)
1395 # self.start_dir: Position of start of central directory
1396 self.start_dir = offset_cd + concat
1397 if self.start_dir < 0:
1398 raise BadZipFile("Bad offset for central directory")
1399 fp.seek(self.start_dir, 0)
1400 data = fp.read(size_cd)
1401 fp = io.BytesIO(data)
1402 total = 0
1403 while total < size_cd:
1404 centdir = fp.read(sizeCentralDir)
1405 if len(centdir) != sizeCentralDir:
1406 raise BadZipFile("Truncated central directory")
1407 centdir = struct.unpack(structCentralDir, centdir)
1408 if centdir[_CD_SIGNATURE] != stringCentralDir:
1409 raise BadZipFile("Bad magic number for central directory")
1410 if self.debug > 2:
1411 print(centdir)
1412 filename = fp.read(centdir[_CD_FILENAME_LENGTH])
1413 flags = centdir[_CD_FLAG_BITS]
1414 if flags & _MASK_UTF_FILENAME:
1415 # UTF-8 file names extension
1416 filename = filename.decode('utf-8')
1417 else:
1418 # Historical ZIP filename encoding
1419 filename = filename.decode(self.metadata_encoding or 'cp437')
1420 # Create ZipInfo instance to store file information
1421 x = ZipInfo(filename)
1422 x.extra = fp.read(centdir[_CD_EXTRA_FIELD_LENGTH])
1423 x.comment = fp.read(centdir[_CD_COMMENT_LENGTH])
1424 x.header_offset = centdir[_CD_LOCAL_HEADER_OFFSET]
1425 (x.create_version, x.create_system, x.extract_version, x.reserved,
1426 x.flag_bits, x.compress_type, t, d,
1427 x.CRC, x.compress_size, x.file_size) = centdir[1:12]
1428 if x.extract_version > MAX_EXTRACT_VERSION:

Callers 1

__init__Method · 0.95

Calls 11

seekMethod · 0.95
readMethod · 0.95
_decodeExtraMethod · 0.95
_EndRecDataFunction · 0.85
BadZipFileClass · 0.85
ZipInfoClass · 0.85
sortedFunction · 0.85
printFunction · 0.50
unpackMethod · 0.45
decodeMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected