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

Function _get_data

tools/python-3.11.9-amd64/Lib/zipimport.py:587–627  ·  view source on GitHub ↗
(archive, toc_entry)

Source from the content-addressed store, hash-verified

585
586# Given a path to a Zip file and a toc_entry, return the (uncompressed) data.
587def _get_data(archive, toc_entry):
588 datapath, compress, data_size, file_size, file_offset, time, date, crc = toc_entry
589 if data_size < 0:
590 raise ZipImportError('negative data size')
591
592 with _io.open_code(archive) as fp:
593 # Check to make sure the local file header is correct
594 try:
595 fp.seek(file_offset)
596 except OSError:
597 raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
598 buffer = fp.read(30)
599 if len(buffer) != 30:
600 raise EOFError('EOF read where not expected')
601
602 if buffer[:4] != b'PK\x03\x04':
603 # Bad: Local File Header
604 raise ZipImportError(f'bad local file header: {archive!r}', path=archive)
605
606 name_size = _unpack_uint16(buffer[26:28])
607 extra_size = _unpack_uint16(buffer[28:30])
608 header_size = 30 + name_size + extra_size
609 file_offset += header_size # Start of file data
610 try:
611 fp.seek(file_offset)
612 except OSError:
613 raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
614 raw_data = fp.read(data_size)
615 if len(raw_data) != data_size:
616 raise OSError("zipimport: can't read data")
617
618 if compress == 0:
619 # data is not compressed
620 return raw_data
621
622 # Decompress with zlib
623 try:
624 decompress = _get_decompress_func()
625 except Exception:
626 raise ZipImportError("can't decompress data; zlib not available")
627 return decompress(raw_data, -15)
628
629
630# Lenient date/time comparison function. The precision of the mtime

Callers 4

get_dataMethod · 0.85
get_sourceMethod · 0.85
_get_pyc_sourceFunction · 0.85
_get_module_codeFunction · 0.85

Calls 7

ZipImportErrorClass · 0.85
_unpack_uint16Function · 0.85
_get_decompress_funcFunction · 0.85
open_codeMethod · 0.80
decompressFunction · 0.70
seekMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected