Skip to content

Commit ea3259f

Browse files
committed
Optimize code
1 parent de4f15b commit ea3259f

File tree

2 files changed

+7
-10
lines changed

2 files changed

+7
-10
lines changed

Lib/test/test_zipfile/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1374,7 +1374,7 @@ def struct_pack_no_dd_sig(fmt, *values):
13741374
with warnings.catch_warnings():
13751375
warnings.simplefilter("ignore")
13761376
if values[0] == zipfile._DD_SIGNATURE:
1377-
return _struct_pack(fmt[0:1] + fmt[2:], *values[1:])
1377+
return _struct_pack(fmt[:1] + fmt[2:], *values[1:])
13781378
return _struct_pack(fmt, *values)
13791379

13801380
class RepackHelperMixin:

Lib/zipfile/__init__.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1494,10 +1494,10 @@ def repack(self, zfile, removed=None):
14941494
# calculate the starting entry offset (bytes to skip)
14951495
if removed is None:
14961496
try:
1497-
data_offset = filelist[0].header_offset
1497+
offset = filelist[0].header_offset
14981498
except IndexError:
1499-
data_offset = zfile.start_dir
1500-
entry_offset = self._calc_initial_entry_offset(fp, data_offset)
1499+
offset = zfile.start_dir
1500+
entry_offset = self._calc_initial_entry_offset(fp, offset)
15011501
else:
15021502
entry_offset = 0
15031503

@@ -1644,7 +1644,7 @@ def _validate_local_file_entry(self, fp, offset, end_offset):
16441644
except BadZipFile:
16451645
return None
16461646

1647-
data_descriptor_size = 0
1647+
dd_size = 0
16481648

16491649
if zinfo.flag_bits & _MASK_USE_DATA_DESCRIPTOR:
16501650
# According to the spec, these fields should be zero when data
@@ -1668,16 +1668,13 @@ def _validate_local_file_entry(self, fp, offset, end_offset):
16681668
if dd is None:
16691669
return None
16701670

1671-
crc, compress_size, file_size, data_descriptor_size = dd
1672-
zinfo.CRC = crc
1673-
zinfo.compress_size = compress_size
1674-
zinfo.file_size = file_size
1671+
zinfo.CRC, zinfo.compress_size, zinfo.file_size, dd_size = dd
16751672

16761673
return (
16771674
sizeFileHeader +
16781675
fheader[_FH_FILENAME_LENGTH] + fheader[_FH_EXTRA_FIELD_LENGTH] +
16791676
zinfo.compress_size +
1680-
data_descriptor_size
1677+
dd_size
16811678
)
16821679

16831680
def _read_local_file_header(self, fp):

0 commit comments

Comments
 (0)