MCPcopy Index your code
hub / github.com/RustPython/RustPython / _get_data

Function _get_data

Lib/zipimport.py:631–671  ·  view source on GitHub ↗
(archive, toc_entry)

Source from the content-addressed store, hash-verified

629
630# Given a path to a Zip file and a toc_entry, return the (uncompressed) data.
631def _get_data(archive, toc_entry):
632 datapath, compress, data_size, file_size, file_offset, time, date, crc = toc_entry
633 if data_size < 0:
634 raise ZipImportError('negative data size')
635
636 with _io.open_code(archive) as fp:
637 # Check to make sure the local file header is correct
638 try:
639 fp.seek(file_offset)
640 except OSError:
641 raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
642 buffer = fp.read(30)
643 if len(buffer) != 30:
644 raise EOFError('EOF read where not expected')
645
646 if buffer[:4] != b'PK\x03\x04':
647 # Bad: Local File Header
648 raise ZipImportError(f'bad local file header: {archive!r}', path=archive)
649
650 name_size = _unpack_uint16(buffer[26:28])
651 extra_size = _unpack_uint16(buffer[28:30])
652 header_size = 30 + name_size + extra_size
653 file_offset += header_size # Start of file data
654 try:
655 fp.seek(file_offset)
656 except OSError:
657 raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
658 raw_data = fp.read(data_size)
659 if len(raw_data) != data_size:
660 raise OSError("zipimport: can't read data")
661
662 if compress == 0:
663 # data is not compressed
664 return raw_data
665
666 # Decompress with zlib
667 try:
668 decompress = _get_decompress_func()
669 except Exception:
670 raise ZipImportError("can't decompress data; zlib not available")
671 return decompress(raw_data, -15)
672
673
674# 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

_unpack_uint16Function · 0.90
decompressFunction · 0.90
ZipImportErrorClass · 0.85
lenFunction · 0.85
_get_decompress_funcFunction · 0.85
seekMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected