Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/AnonR/anonr.TX.../opt/imh-pyth.../lib/python3....
File: zipimport.py
"""zipimport provides support for importing Python modules from Zip archives.
[0] Fix | Delete
[1] Fix | Delete
This module exports three objects:
[2] Fix | Delete
- zipimporter: a class; its constructor takes a path to a Zip archive.
[3] Fix | Delete
- ZipImportError: exception raised by zipimporter objects. It's a
[4] Fix | Delete
subclass of ImportError, so it can be caught as ImportError, too.
[5] Fix | Delete
- _zip_directory_cache: a dict, mapping archive paths to zip directory
[6] Fix | Delete
info dicts, as used in zipimporter._files.
[7] Fix | Delete
[8] Fix | Delete
It is usually not needed to use the zipimport module explicitly; it is
[9] Fix | Delete
used by the builtin import mechanism for sys.path items that are paths
[10] Fix | Delete
to Zip archives.
[11] Fix | Delete
"""
[12] Fix | Delete
[13] Fix | Delete
#from importlib import _bootstrap_external
[14] Fix | Delete
#from importlib import _bootstrap # for _verbose_message
[15] Fix | Delete
import _frozen_importlib_external as _bootstrap_external
[16] Fix | Delete
from _frozen_importlib_external import _unpack_uint16, _unpack_uint32
[17] Fix | Delete
import _frozen_importlib as _bootstrap # for _verbose_message
[18] Fix | Delete
import _imp # for check_hash_based_pycs
[19] Fix | Delete
import _io # for open
[20] Fix | Delete
import marshal # for loads
[21] Fix | Delete
import sys # for modules
[22] Fix | Delete
import time # for mktime
[23] Fix | Delete
[24] Fix | Delete
__all__ = ['ZipImportError', 'zipimporter']
[25] Fix | Delete
[26] Fix | Delete
[27] Fix | Delete
path_sep = _bootstrap_external.path_sep
[28] Fix | Delete
alt_path_sep = _bootstrap_external.path_separators[1:]
[29] Fix | Delete
[30] Fix | Delete
[31] Fix | Delete
class ZipImportError(ImportError):
[32] Fix | Delete
pass
[33] Fix | Delete
[34] Fix | Delete
# _read_directory() cache
[35] Fix | Delete
_zip_directory_cache = {}
[36] Fix | Delete
[37] Fix | Delete
_module_type = type(sys)
[38] Fix | Delete
[39] Fix | Delete
END_CENTRAL_DIR_SIZE = 22
[40] Fix | Delete
STRING_END_ARCHIVE = b'PK\x05\x06'
[41] Fix | Delete
MAX_COMMENT_LEN = (1 << 16) - 1
[42] Fix | Delete
[43] Fix | Delete
class zipimporter:
[44] Fix | Delete
"""zipimporter(archivepath) -> zipimporter object
[45] Fix | Delete
[46] Fix | Delete
Create a new zipimporter instance. 'archivepath' must be a path to
[47] Fix | Delete
a zipfile, or to a specific path inside a zipfile. For example, it can be
[48] Fix | Delete
'/tmp/myimport.zip', or '/tmp/myimport.zip/mydirectory', if mydirectory is a
[49] Fix | Delete
valid directory inside the archive.
[50] Fix | Delete
[51] Fix | Delete
'ZipImportError is raised if 'archivepath' doesn't point to a valid Zip
[52] Fix | Delete
archive.
[53] Fix | Delete
[54] Fix | Delete
The 'archive' attribute of zipimporter objects contains the name of the
[55] Fix | Delete
zipfile targeted.
[56] Fix | Delete
"""
[57] Fix | Delete
[58] Fix | Delete
# Split the "subdirectory" from the Zip archive path, lookup a matching
[59] Fix | Delete
# entry in sys.path_importer_cache, fetch the file directory from there
[60] Fix | Delete
# if found, or else read it from the archive.
[61] Fix | Delete
def __init__(self, path):
[62] Fix | Delete
if not isinstance(path, str):
[63] Fix | Delete
import os
[64] Fix | Delete
path = os.fsdecode(path)
[65] Fix | Delete
if not path:
[66] Fix | Delete
raise ZipImportError('archive path is empty', path=path)
[67] Fix | Delete
if alt_path_sep:
[68] Fix | Delete
path = path.replace(alt_path_sep, path_sep)
[69] Fix | Delete
[70] Fix | Delete
prefix = []
[71] Fix | Delete
while True:
[72] Fix | Delete
try:
[73] Fix | Delete
st = _bootstrap_external._path_stat(path)
[74] Fix | Delete
except (OSError, ValueError):
[75] Fix | Delete
# On Windows a ValueError is raised for too long paths.
[76] Fix | Delete
# Back up one path element.
[77] Fix | Delete
dirname, basename = _bootstrap_external._path_split(path)
[78] Fix | Delete
if dirname == path:
[79] Fix | Delete
raise ZipImportError('not a Zip file', path=path)
[80] Fix | Delete
path = dirname
[81] Fix | Delete
prefix.append(basename)
[82] Fix | Delete
else:
[83] Fix | Delete
# it exists
[84] Fix | Delete
if (st.st_mode & 0o170000) != 0o100000: # stat.S_ISREG
[85] Fix | Delete
# it's a not file
[86] Fix | Delete
raise ZipImportError('not a Zip file', path=path)
[87] Fix | Delete
break
[88] Fix | Delete
[89] Fix | Delete
try:
[90] Fix | Delete
files = _zip_directory_cache[path]
[91] Fix | Delete
except KeyError:
[92] Fix | Delete
files = _read_directory(path)
[93] Fix | Delete
_zip_directory_cache[path] = files
[94] Fix | Delete
self._files = files
[95] Fix | Delete
self.archive = path
[96] Fix | Delete
# a prefix directory following the ZIP file path.
[97] Fix | Delete
self.prefix = _bootstrap_external._path_join(*prefix[::-1])
[98] Fix | Delete
if self.prefix:
[99] Fix | Delete
self.prefix += path_sep
[100] Fix | Delete
[101] Fix | Delete
[102] Fix | Delete
# Check whether we can satisfy the import of the module named by
[103] Fix | Delete
# 'fullname', or whether it could be a portion of a namespace
[104] Fix | Delete
# package. Return self if we can load it, a string containing the
[105] Fix | Delete
# full path if it's a possible namespace portion, None if we
[106] Fix | Delete
# can't load it.
[107] Fix | Delete
def find_loader(self, fullname, path=None):
[108] Fix | Delete
"""find_loader(fullname, path=None) -> self, str or None.
[109] Fix | Delete
[110] Fix | Delete
Search for a module specified by 'fullname'. 'fullname' must be the
[111] Fix | Delete
fully qualified (dotted) module name. It returns the zipimporter
[112] Fix | Delete
instance itself if the module was found, a string containing the
[113] Fix | Delete
full path name if it's possibly a portion of a namespace package,
[114] Fix | Delete
or None otherwise. The optional 'path' argument is ignored -- it's
[115] Fix | Delete
there for compatibility with the importer protocol.
[116] Fix | Delete
"""
[117] Fix | Delete
mi = _get_module_info(self, fullname)
[118] Fix | Delete
if mi is not None:
[119] Fix | Delete
# This is a module or package.
[120] Fix | Delete
return self, []
[121] Fix | Delete
[122] Fix | Delete
# Not a module or regular package. See if this is a directory, and
[123] Fix | Delete
# therefore possibly a portion of a namespace package.
[124] Fix | Delete
[125] Fix | Delete
# We're only interested in the last path component of fullname
[126] Fix | Delete
# earlier components are recorded in self.prefix.
[127] Fix | Delete
modpath = _get_module_path(self, fullname)
[128] Fix | Delete
if _is_dir(self, modpath):
[129] Fix | Delete
# This is possibly a portion of a namespace
[130] Fix | Delete
# package. Return the string representing its path,
[131] Fix | Delete
# without a trailing separator.
[132] Fix | Delete
return None, [f'{self.archive}{path_sep}{modpath}']
[133] Fix | Delete
[134] Fix | Delete
return None, []
[135] Fix | Delete
[136] Fix | Delete
[137] Fix | Delete
# Check whether we can satisfy the import of the module named by
[138] Fix | Delete
# 'fullname'. Return self if we can, None if we can't.
[139] Fix | Delete
def find_module(self, fullname, path=None):
[140] Fix | Delete
"""find_module(fullname, path=None) -> self or None.
[141] Fix | Delete
[142] Fix | Delete
Search for a module specified by 'fullname'. 'fullname' must be the
[143] Fix | Delete
fully qualified (dotted) module name. It returns the zipimporter
[144] Fix | Delete
instance itself if the module was found, or None if it wasn't.
[145] Fix | Delete
The optional 'path' argument is ignored -- it's there for compatibility
[146] Fix | Delete
with the importer protocol.
[147] Fix | Delete
"""
[148] Fix | Delete
return self.find_loader(fullname, path)[0]
[149] Fix | Delete
[150] Fix | Delete
[151] Fix | Delete
def get_code(self, fullname):
[152] Fix | Delete
"""get_code(fullname) -> code object.
[153] Fix | Delete
[154] Fix | Delete
Return the code object for the specified module. Raise ZipImportError
[155] Fix | Delete
if the module couldn't be found.
[156] Fix | Delete
"""
[157] Fix | Delete
code, ispackage, modpath = _get_module_code(self, fullname)
[158] Fix | Delete
return code
[159] Fix | Delete
[160] Fix | Delete
[161] Fix | Delete
def get_data(self, pathname):
[162] Fix | Delete
"""get_data(pathname) -> string with file data.
[163] Fix | Delete
[164] Fix | Delete
Return the data associated with 'pathname'. Raise OSError if
[165] Fix | Delete
the file wasn't found.
[166] Fix | Delete
"""
[167] Fix | Delete
if alt_path_sep:
[168] Fix | Delete
pathname = pathname.replace(alt_path_sep, path_sep)
[169] Fix | Delete
[170] Fix | Delete
key = pathname
[171] Fix | Delete
if pathname.startswith(self.archive + path_sep):
[172] Fix | Delete
key = pathname[len(self.archive + path_sep):]
[173] Fix | Delete
[174] Fix | Delete
try:
[175] Fix | Delete
toc_entry = self._files[key]
[176] Fix | Delete
except KeyError:
[177] Fix | Delete
raise OSError(0, '', key)
[178] Fix | Delete
return _get_data(self.archive, toc_entry)
[179] Fix | Delete
[180] Fix | Delete
[181] Fix | Delete
# Return a string matching __file__ for the named module
[182] Fix | Delete
def get_filename(self, fullname):
[183] Fix | Delete
"""get_filename(fullname) -> filename string.
[184] Fix | Delete
[185] Fix | Delete
Return the filename for the specified module.
[186] Fix | Delete
"""
[187] Fix | Delete
# Deciding the filename requires working out where the code
[188] Fix | Delete
# would come from if the module was actually loaded
[189] Fix | Delete
code, ispackage, modpath = _get_module_code(self, fullname)
[190] Fix | Delete
return modpath
[191] Fix | Delete
[192] Fix | Delete
[193] Fix | Delete
def get_source(self, fullname):
[194] Fix | Delete
"""get_source(fullname) -> source string.
[195] Fix | Delete
[196] Fix | Delete
Return the source code for the specified module. Raise ZipImportError
[197] Fix | Delete
if the module couldn't be found, return None if the archive does
[198] Fix | Delete
contain the module, but has no source for it.
[199] Fix | Delete
"""
[200] Fix | Delete
mi = _get_module_info(self, fullname)
[201] Fix | Delete
if mi is None:
[202] Fix | Delete
raise ZipImportError(f"can't find module {fullname!r}", name=fullname)
[203] Fix | Delete
[204] Fix | Delete
path = _get_module_path(self, fullname)
[205] Fix | Delete
if mi:
[206] Fix | Delete
fullpath = _bootstrap_external._path_join(path, '__init__.py')
[207] Fix | Delete
else:
[208] Fix | Delete
fullpath = f'{path}.py'
[209] Fix | Delete
[210] Fix | Delete
try:
[211] Fix | Delete
toc_entry = self._files[fullpath]
[212] Fix | Delete
except KeyError:
[213] Fix | Delete
# we have the module, but no source
[214] Fix | Delete
return None
[215] Fix | Delete
return _get_data(self.archive, toc_entry).decode()
[216] Fix | Delete
[217] Fix | Delete
[218] Fix | Delete
# Return a bool signifying whether the module is a package or not.
[219] Fix | Delete
def is_package(self, fullname):
[220] Fix | Delete
"""is_package(fullname) -> bool.
[221] Fix | Delete
[222] Fix | Delete
Return True if the module specified by fullname is a package.
[223] Fix | Delete
Raise ZipImportError if the module couldn't be found.
[224] Fix | Delete
"""
[225] Fix | Delete
mi = _get_module_info(self, fullname)
[226] Fix | Delete
if mi is None:
[227] Fix | Delete
raise ZipImportError(f"can't find module {fullname!r}", name=fullname)
[228] Fix | Delete
return mi
[229] Fix | Delete
[230] Fix | Delete
[231] Fix | Delete
# Load and return the module named by 'fullname'.
[232] Fix | Delete
def load_module(self, fullname):
[233] Fix | Delete
"""load_module(fullname) -> module.
[234] Fix | Delete
[235] Fix | Delete
Load the module specified by 'fullname'. 'fullname' must be the
[236] Fix | Delete
fully qualified (dotted) module name. It returns the imported
[237] Fix | Delete
module, or raises ZipImportError if it wasn't found.
[238] Fix | Delete
"""
[239] Fix | Delete
code, ispackage, modpath = _get_module_code(self, fullname)
[240] Fix | Delete
mod = sys.modules.get(fullname)
[241] Fix | Delete
if mod is None or not isinstance(mod, _module_type):
[242] Fix | Delete
mod = _module_type(fullname)
[243] Fix | Delete
sys.modules[fullname] = mod
[244] Fix | Delete
mod.__loader__ = self
[245] Fix | Delete
[246] Fix | Delete
try:
[247] Fix | Delete
if ispackage:
[248] Fix | Delete
# add __path__ to the module *before* the code gets
[249] Fix | Delete
# executed
[250] Fix | Delete
path = _get_module_path(self, fullname)
[251] Fix | Delete
fullpath = _bootstrap_external._path_join(self.archive, path)
[252] Fix | Delete
mod.__path__ = [fullpath]
[253] Fix | Delete
[254] Fix | Delete
if not hasattr(mod, '__builtins__'):
[255] Fix | Delete
mod.__builtins__ = __builtins__
[256] Fix | Delete
_bootstrap_external._fix_up_module(mod.__dict__, fullname, modpath)
[257] Fix | Delete
exec(code, mod.__dict__)
[258] Fix | Delete
except:
[259] Fix | Delete
del sys.modules[fullname]
[260] Fix | Delete
raise
[261] Fix | Delete
[262] Fix | Delete
try:
[263] Fix | Delete
mod = sys.modules[fullname]
[264] Fix | Delete
except KeyError:
[265] Fix | Delete
raise ImportError(f'Loaded module {fullname!r} not found in sys.modules')
[266] Fix | Delete
_bootstrap._verbose_message('import {} # loaded from Zip {}', fullname, modpath)
[267] Fix | Delete
return mod
[268] Fix | Delete
[269] Fix | Delete
[270] Fix | Delete
def get_resource_reader(self, fullname):
[271] Fix | Delete
"""Return the ResourceReader for a package in a zip file.
[272] Fix | Delete
[273] Fix | Delete
If 'fullname' is a package within the zip file, return the
[274] Fix | Delete
'ResourceReader' object for the package. Otherwise return None.
[275] Fix | Delete
"""
[276] Fix | Delete
try:
[277] Fix | Delete
if not self.is_package(fullname):
[278] Fix | Delete
return None
[279] Fix | Delete
except ZipImportError:
[280] Fix | Delete
return None
[281] Fix | Delete
if not _ZipImportResourceReader._registered:
[282] Fix | Delete
from importlib.abc import ResourceReader
[283] Fix | Delete
ResourceReader.register(_ZipImportResourceReader)
[284] Fix | Delete
_ZipImportResourceReader._registered = True
[285] Fix | Delete
return _ZipImportResourceReader(self, fullname)
[286] Fix | Delete
[287] Fix | Delete
[288] Fix | Delete
def __repr__(self):
[289] Fix | Delete
return f'<zipimporter object "{self.archive}{path_sep}{self.prefix}">'
[290] Fix | Delete
[291] Fix | Delete
[292] Fix | Delete
# _zip_searchorder defines how we search for a module in the Zip
[293] Fix | Delete
# archive: we first search for a package __init__, then for
[294] Fix | Delete
# non-package .pyc, and .py entries. The .pyc entries
[295] Fix | Delete
# are swapped by initzipimport() if we run in optimized mode. Also,
[296] Fix | Delete
# '/' is replaced by path_sep there.
[297] Fix | Delete
_zip_searchorder = (
[298] Fix | Delete
(path_sep + '__init__.pyc', True, True),
[299] Fix | Delete
(path_sep + '__init__.py', False, True),
[300] Fix | Delete
('.pyc', True, False),
[301] Fix | Delete
('.py', False, False),
[302] Fix | Delete
)
[303] Fix | Delete
[304] Fix | Delete
# Given a module name, return the potential file path in the
[305] Fix | Delete
# archive (without extension).
[306] Fix | Delete
def _get_module_path(self, fullname):
[307] Fix | Delete
return self.prefix + fullname.rpartition('.')[2]
[308] Fix | Delete
[309] Fix | Delete
# Does this path represent a directory?
[310] Fix | Delete
def _is_dir(self, path):
[311] Fix | Delete
# See if this is a "directory". If so, it's eligible to be part
[312] Fix | Delete
# of a namespace package. We test by seeing if the name, with an
[313] Fix | Delete
# appended path separator, exists.
[314] Fix | Delete
dirpath = path + path_sep
[315] Fix | Delete
# If dirpath is present in self._files, we have a directory.
[316] Fix | Delete
return dirpath in self._files
[317] Fix | Delete
[318] Fix | Delete
# Return some information about a module.
[319] Fix | Delete
def _get_module_info(self, fullname):
[320] Fix | Delete
path = _get_module_path(self, fullname)
[321] Fix | Delete
for suffix, isbytecode, ispackage in _zip_searchorder:
[322] Fix | Delete
fullpath = path + suffix
[323] Fix | Delete
if fullpath in self._files:
[324] Fix | Delete
return ispackage
[325] Fix | Delete
return None
[326] Fix | Delete
[327] Fix | Delete
[328] Fix | Delete
# implementation
[329] Fix | Delete
[330] Fix | Delete
# _read_directory(archive) -> files dict (new reference)
[331] Fix | Delete
#
[332] Fix | Delete
# Given a path to a Zip archive, build a dict, mapping file names
[333] Fix | Delete
# (local to the archive, using SEP as a separator) to toc entries.
[334] Fix | Delete
#
[335] Fix | Delete
# A toc_entry is a tuple:
[336] Fix | Delete
#
[337] Fix | Delete
# (__file__, # value to use for __file__, available for all files,
[338] Fix | Delete
# # encoded to the filesystem encoding
[339] Fix | Delete
# compress, # compression kind; 0 for uncompressed
[340] Fix | Delete
# data_size, # size of compressed data on disk
[341] Fix | Delete
# file_size, # size of decompressed data
[342] Fix | Delete
# file_offset, # offset of file header from start of archive
[343] Fix | Delete
# time, # mod time of file (in dos format)
[344] Fix | Delete
# date, # mod data of file (in dos format)
[345] Fix | Delete
# crc, # crc checksum of the data
[346] Fix | Delete
# )
[347] Fix | Delete
#
[348] Fix | Delete
# Directories can be recognized by the trailing path_sep in the name,
[349] Fix | Delete
# data_size and file_offset are 0.
[350] Fix | Delete
def _read_directory(archive):
[351] Fix | Delete
try:
[352] Fix | Delete
fp = _io.open_code(archive)
[353] Fix | Delete
except OSError:
[354] Fix | Delete
raise ZipImportError(f"can't open Zip file: {archive!r}", path=archive)
[355] Fix | Delete
[356] Fix | Delete
with fp:
[357] Fix | Delete
try:
[358] Fix | Delete
fp.seek(-END_CENTRAL_DIR_SIZE, 2)
[359] Fix | Delete
header_position = fp.tell()
[360] Fix | Delete
buffer = fp.read(END_CENTRAL_DIR_SIZE)
[361] Fix | Delete
except OSError:
[362] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
[363] Fix | Delete
if len(buffer) != END_CENTRAL_DIR_SIZE:
[364] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
[365] Fix | Delete
if buffer[:4] != STRING_END_ARCHIVE:
[366] Fix | Delete
# Bad: End of Central Dir signature
[367] Fix | Delete
# Check if there's a comment.
[368] Fix | Delete
try:
[369] Fix | Delete
fp.seek(0, 2)
[370] Fix | Delete
file_size = fp.tell()
[371] Fix | Delete
except OSError:
[372] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}",
[373] Fix | Delete
path=archive)
[374] Fix | Delete
max_comment_start = max(file_size - MAX_COMMENT_LEN -
[375] Fix | Delete
END_CENTRAL_DIR_SIZE, 0)
[376] Fix | Delete
try:
[377] Fix | Delete
fp.seek(max_comment_start)
[378] Fix | Delete
data = fp.read()
[379] Fix | Delete
except OSError:
[380] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}",
[381] Fix | Delete
path=archive)
[382] Fix | Delete
pos = data.rfind(STRING_END_ARCHIVE)
[383] Fix | Delete
if pos < 0:
[384] Fix | Delete
raise ZipImportError(f'not a Zip file: {archive!r}',
[385] Fix | Delete
path=archive)
[386] Fix | Delete
buffer = data[pos:pos+END_CENTRAL_DIR_SIZE]
[387] Fix | Delete
if len(buffer) != END_CENTRAL_DIR_SIZE:
[388] Fix | Delete
raise ZipImportError(f"corrupt Zip file: {archive!r}",
[389] Fix | Delete
path=archive)
[390] Fix | Delete
header_position = file_size - len(data) + pos
[391] Fix | Delete
[392] Fix | Delete
header_size = _unpack_uint32(buffer[12:16])
[393] Fix | Delete
header_offset = _unpack_uint32(buffer[16:20])
[394] Fix | Delete
if header_position < header_size:
[395] Fix | Delete
raise ZipImportError(f'bad central directory size: {archive!r}', path=archive)
[396] Fix | Delete
if header_position < header_offset:
[397] Fix | Delete
raise ZipImportError(f'bad central directory offset: {archive!r}', path=archive)
[398] Fix | Delete
header_position -= header_size
[399] Fix | Delete
arc_offset = header_position - header_offset
[400] Fix | Delete
if arc_offset < 0:
[401] Fix | Delete
raise ZipImportError(f'bad central directory size or offset: {archive!r}', path=archive)
[402] Fix | Delete
[403] Fix | Delete
files = {}
[404] Fix | Delete
# Start of Central Directory
[405] Fix | Delete
count = 0
[406] Fix | Delete
try:
[407] Fix | Delete
fp.seek(header_position)
[408] Fix | Delete
except OSError:
[409] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
[410] Fix | Delete
while True:
[411] Fix | Delete
buffer = fp.read(46)
[412] Fix | Delete
if len(buffer) < 4:
[413] Fix | Delete
raise EOFError('EOF read where not expected')
[414] Fix | Delete
# Start of file header
[415] Fix | Delete
if buffer[:4] != b'PK\x01\x02':
[416] Fix | Delete
break # Bad: Central Dir File Header
[417] Fix | Delete
if len(buffer) != 46:
[418] Fix | Delete
raise EOFError('EOF read where not expected')
[419] Fix | Delete
flags = _unpack_uint16(buffer[8:10])
[420] Fix | Delete
compress = _unpack_uint16(buffer[10:12])
[421] Fix | Delete
time = _unpack_uint16(buffer[12:14])
[422] Fix | Delete
date = _unpack_uint16(buffer[14:16])
[423] Fix | Delete
crc = _unpack_uint32(buffer[16:20])
[424] Fix | Delete
data_size = _unpack_uint32(buffer[20:24])
[425] Fix | Delete
file_size = _unpack_uint32(buffer[24:28])
[426] Fix | Delete
name_size = _unpack_uint16(buffer[28:30])
[427] Fix | Delete
extra_size = _unpack_uint16(buffer[30:32])
[428] Fix | Delete
comment_size = _unpack_uint16(buffer[32:34])
[429] Fix | Delete
file_offset = _unpack_uint32(buffer[42:46])
[430] Fix | Delete
header_size = name_size + extra_size + comment_size
[431] Fix | Delete
if file_offset > header_offset:
[432] Fix | Delete
raise ZipImportError(f'bad local header offset: {archive!r}', path=archive)
[433] Fix | Delete
file_offset += arc_offset
[434] Fix | Delete
[435] Fix | Delete
try:
[436] Fix | Delete
name = fp.read(name_size)
[437] Fix | Delete
except OSError:
[438] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
[439] Fix | Delete
if len(name) != name_size:
[440] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
[441] Fix | Delete
# On Windows, calling fseek to skip over the fields we don't use is
[442] Fix | Delete
# slower than reading the data because fseek flushes stdio's
[443] Fix | Delete
# internal buffers. See issue #8745.
[444] Fix | Delete
try:
[445] Fix | Delete
if len(fp.read(header_size - name_size)) != header_size - name_size:
[446] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
[447] Fix | Delete
except OSError:
[448] Fix | Delete
raise ZipImportError(f"can't read Zip file: {archive!r}", path=archive)
[449] Fix | Delete
[450] Fix | Delete
if flags & 0x800:
[451] Fix | Delete
# UTF-8 file names extension
[452] Fix | Delete
name = name.decode()
[453] Fix | Delete
else:
[454] Fix | Delete
# Historical ZIP filename encoding
[455] Fix | Delete
try:
[456] Fix | Delete
name = name.decode('ascii')
[457] Fix | Delete
except UnicodeDecodeError:
[458] Fix | Delete
name = name.decode('latin1').translate(cp437_table)
[459] Fix | Delete
[460] Fix | Delete
name = name.replace('/', path_sep)
[461] Fix | Delete
path = _bootstrap_external._path_join(archive, name)
[462] Fix | Delete
t = (path, compress, data_size, file_size, file_offset, time, date, crc)
[463] Fix | Delete
files[name] = t
[464] Fix | Delete
count += 1
[465] Fix | Delete
_bootstrap._verbose_message('zipimport: found {} names in {!r}', count, archive)
[466] Fix | Delete
return files
[467] Fix | Delete
[468] Fix | Delete
# During bootstrap, we may need to load the encodings
[469] Fix | Delete
# package from a ZIP file. But the cp437 encoding is implemented
[470] Fix | Delete
# in Python in the encodings package.
[471] Fix | Delete
#
[472] Fix | Delete
# Break out of this dependency by using the translation table for
[473] Fix | Delete
# the cp437 encoding.
[474] Fix | Delete
cp437_table = (
[475] Fix | Delete
# ASCII part, 8 rows x 16 chars
[476] Fix | Delete
'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
[477] Fix | Delete
'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
[478] Fix | Delete
' !"#$%&\'()*+,-./'
[479] Fix | Delete
'0123456789:;<=>?'
[480] Fix | Delete
'@ABCDEFGHIJKLMNO'
[481] Fix | Delete
'PQRSTUVWXYZ[\\]^_'
[482] Fix | Delete
'`abcdefghijklmno'
[483] Fix | Delete
'pqrstuvwxyz{|}~\x7f'
[484] Fix | Delete
# non-ASCII part, 16 rows x 8 chars
[485] Fix | Delete
'\xc7\xfc\xe9\xe2\xe4\xe0\xe5\xe7'
[486] Fix | Delete
'\xea\xeb\xe8\xef\xee\xec\xc4\xc5'
[487] Fix | Delete
'\xc9\xe6\xc6\xf4\xf6\xf2\xfb\xf9'
[488] Fix | Delete
'\xff\xd6\xdc\xa2\xa3\xa5\u20a7\u0192'
[489] Fix | Delete
'\xe1\xed\xf3\xfa\xf1\xd1\xaa\xba'
[490] Fix | Delete
'\xbf\u2310\xac\xbd\xbc\xa1\xab\xbb'
[491] Fix | Delete
'\u2591\u2592\u2593\u2502\u2524\u2561\u2562\u2556'
[492] Fix | Delete
'\u2555\u2563\u2551\u2557\u255d\u255c\u255b\u2510'
[493] Fix | Delete
'\u2514\u2534\u252c\u251c\u2500\u253c\u255e\u255f'
[494] Fix | Delete
'\u255a\u2554\u2569\u2566\u2560\u2550\u256c\u2567'
[495] Fix | Delete
'\u2568\u2564\u2565\u2559\u2558\u2552\u2553\u256b'
[496] Fix | Delete
'\u256a\u2518\u250c\u2588\u2584\u258c\u2590\u2580'
[497] Fix | Delete
'\u03b1\xdf\u0393\u03c0\u03a3\u03c3\xb5\u03c4'
[498] Fix | Delete
'\u03a6\u0398\u03a9\u03b4\u221e\u03c6\u03b5\u2229'
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function