zipremove 0.4.0__tar.gz → 0.4.1__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zipremove
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Extend `zipfile` with `remove`-related functionalities
5
5
  Home-page: https://github.com/danny0838/zipremove
6
6
  Author: Danny Lin
@@ -1,6 +1,6 @@
1
1
  [metadata]
2
2
  name = zipremove
3
- version = 0.4.0
3
+ version = 0.4.1
4
4
  author = Danny Lin
5
5
  author_email = danny0838@gmail.com
6
6
  url = https://github.com/danny0838/zipremove
@@ -262,14 +262,11 @@ class _ZipRepacker:
262
262
  used_entry_size,
263
263
  )
264
264
 
265
- if used_entry_size < entry_size:
266
- stale_entry_size = self._validate_local_file_entry_sequence(
267
- fp,
268
- old_header_offset + used_entry_size,
269
- old_header_offset + entry_size,
270
- )
271
- else:
272
- stale_entry_size = 0
265
+ stale_entry_size = self._validate_local_file_entry_sequence(
266
+ fp,
267
+ old_header_offset + used_entry_size,
268
+ old_header_offset + entry_size,
269
+ )
273
270
 
274
271
  if stale_entry_size > 0:
275
272
  self._copy_bytes(
@@ -380,8 +377,8 @@ class _ZipRepacker:
380
377
  if pos > end_offset:
381
378
  return None
382
379
 
380
+ # parse zip64
383
381
  try:
384
- # parse zip64
385
382
  try:
386
383
  zinfo._decodeExtra(crc32(filename))
387
384
  except TypeError:
@@ -617,15 +614,16 @@ class ZipFile(ZipFile):
617
614
 
618
615
  with self._lock:
619
616
  # get the zinfo
620
- # raise KeyError if arcname does not exist
621
617
  if isinstance(zinfo_or_arcname, ZipInfo):
622
618
  zinfo = zinfo_or_arcname
623
- if zinfo not in self.filelist:
624
- raise KeyError('There is no item %r in the archive' % zinfo)
625
619
  else:
620
+ # raise KeyError if arcname does not exist
626
621
  zinfo = self.getinfo(zinfo_or_arcname)
627
622
 
628
- self.filelist.remove(zinfo)
623
+ try:
624
+ self.filelist.remove(zinfo)
625
+ except ValueError:
626
+ raise KeyError('There is no item %r in the archive' % zinfo) from None
629
627
 
630
628
  try:
631
629
  del self.NameToInfo[zinfo.filename]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: zipremove
3
- Version: 0.4.0
3
+ Version: 0.4.1
4
4
  Summary: Extend `zipfile` with `remove`-related functionalities
5
5
  Home-page: https://github.com/danny0838/zipremove
6
6
  Author: Danny Lin
@@ -1,3 +1,4 @@
1
+ import contextlib
1
2
  import io
2
3
  import itertools
3
4
  import os
@@ -6,7 +7,6 @@ import sys
6
7
  import unittest
7
8
  import unittest.mock as mock
8
9
  import warnings
9
- from contextlib import nullcontext
10
10
 
11
11
  import zipremove as zipfile
12
12
 
@@ -616,27 +616,20 @@ class AbstractRepackTests(RepackHelperMixin):
616
616
  self._prepare_zip_from_test_files(TESTFN, self.test_files)
617
617
 
618
618
  with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
619
- zi = zh.remove(zh.infolist()[0])
620
- with mock.patch.object(zipfile._ZipRepacker, 'repack') as m_rp:
619
+ with mock.patch.object(zipfile._ZipRepacker, 'repack') as m_rp, \
620
+ mock.patch.object(zipfile, '_ZipRepacker', wraps=zipfile._ZipRepacker) as m_zr:
621
621
  zh.repack()
622
+ m_zr.assert_called_once_with()
622
623
  m_rp.assert_called_once_with(zh, None)
623
624
 
624
625
  with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
625
626
  zi = zh.remove(zh.infolist()[0])
626
- with mock.patch.object(zipfile._ZipRepacker, 'repack') as m_rp:
627
- zh.repack([zi])
627
+ with mock.patch.object(zipfile._ZipRepacker, 'repack') as m_rp, \
628
+ mock.patch.object(zipfile, '_ZipRepacker', wraps=zipfile._ZipRepacker) as m_zr:
629
+ zh.repack([zi], strict_descriptor=True, chunk_size=1024)
630
+ m_zr.assert_called_once_with(strict_descriptor=True, chunk_size=1024)
628
631
  m_rp.assert_called_once_with(zh, [zi])
629
632
 
630
- with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
631
- with mock.patch.object(zipfile, '_ZipRepacker') as m_rp:
632
- zh.repack()
633
- m_rp.assert_called_once_with()
634
-
635
- with zipfile.ZipFile(TESTFN, 'a', self.compression) as zh:
636
- with mock.patch.object(zipfile, '_ZipRepacker') as m_rp:
637
- zh.repack(strict_descriptor=True, chunk_size=1024)
638
- m_rp.assert_called_once_with(strict_descriptor=True, chunk_size=1024)
639
-
640
633
  def test_repack_bytes_before_first_file(self):
641
634
  """Should preserve random bytes before the first recorded local file entry."""
642
635
  for ii in ([], [0], [0, 1], [0, 1, 2]):
@@ -1392,7 +1385,7 @@ class ZipRepackerTests(unittest.TestCase):
1392
1385
  fz = io.BytesIO()
1393
1386
  f = Unseekable(fz) if dd else fz
1394
1387
  cm = (mock.patch.object(struct, 'pack', side_effect=struct_pack_no_dd_sig)
1395
- if not dd_sig else nullcontext())
1388
+ if not dd_sig else contextlib.nullcontext())
1396
1389
  with zipfile.ZipFile(f, 'w', compression=compression) as zh:
1397
1390
  with cm:
1398
1391
  with zh.open(arcname, 'w', force_zip64=force_zip64) as fh:
@@ -18,16 +18,19 @@ except ImportError:
18
18
  # polyfill for Python < 3.12
19
19
  from test.test_zipfile import Unseekable, requires_zlib
20
20
 
21
- ENABLED_RESOURCES = set(os.environ.get("TEST_RESOURCES", "").split(","))
22
-
23
- def requires(resource_name):
21
+ def requires_resource(res):
22
+ if not hasattr(requires_resource, '_resources'):
23
+ requires_resource._resources = set(os.environ.get("TEST_RESOURCES", "").split(","))
24
24
  return unittest.skipUnless(
25
- resource_name in ENABLED_RESOURCES,
26
- f"requires resource: {resource_name!r} (set envvar TEST_RESOURCES)"
25
+ res in requires_resource._resources,
26
+ f"requires resource {res!r} in envvar TEST_RESOURCES"
27
27
  )
28
28
 
29
+ @requires_resource('extralargefile')
30
+ def setUpModule():
31
+ pass
32
+
29
33
 
30
- @requires('extralargefile')
31
34
  class TestRepack(unittest.TestCase):
32
35
  def setUp(self):
33
36
  # Create test data.
File without changes
File without changes
File without changes
File without changes