Skip to content

Commit 0dd9b44

Browse files
committed
Removed features slated for Python 3.15 only.
1 parent bf614c9 commit 0dd9b44

File tree

3 files changed

+28
-50
lines changed

3 files changed

+28
-50
lines changed

Lib/zipfile/_path/__init__.py

Lines changed: 27 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
for more detail.
88
"""
99

10-
import functools
10+
import contextlib
1111
import io
1212
import itertools
1313
import pathlib
@@ -17,10 +17,9 @@
1717
import sys
1818
import zipfile
1919

20-
from ._functools import save_method_args
2120
from .glob import Translator
2221

23-
__all__ = ['Path']
22+
__all__ = ["Path"]
2423

2524

2625
def _parents(path):
@@ -86,12 +85,13 @@ class InitializedState:
8685
Mix-in to save the initialization state for pickling.
8786
"""
8887

89-
@save_method_args
9088
def __init__(self, *args, **kwargs):
89+
self.__args = args
90+
self.__kwargs = kwargs
9191
super().__init__(*args, **kwargs)
9292

9393
def __getstate__(self):
94-
return self._saved___init__.args, self._saved___init__.kwargs
94+
return self.__args, self.__kwargs
9595

9696
def __setstate__(self, state):
9797
args, kwargs = state
@@ -128,7 +128,7 @@ def resolve_dir(self, name):
128128
as a directory (with the trailing slash).
129129
"""
130130
names = self._name_set()
131-
dirname = name + '/'
131+
dirname = name + "/"
132132
dir_match = name not in names and dirname in names
133133
return dirname if dir_match else name
134134

@@ -139,7 +139,7 @@ def getinfo(self, name):
139139
try:
140140
return super().getinfo(name)
141141
except KeyError:
142-
if not name.endswith('/') or name not in self._name_set():
142+
if not name.endswith("/") or name not in self._name_set():
143143
raise
144144
return zipfile.ZipInfo(filename=name)
145145

@@ -156,7 +156,7 @@ def make(cls, source):
156156
return cls(source)
157157

158158
# Only allow for FastLookup when supplied zipfile is read-only
159-
if 'r' not in source.mode:
159+
if "r" not in source.mode:
160160
cls = CompleteDirs
161161

162162
source.__class__ = cls
@@ -182,21 +182,22 @@ class FastLookup(CompleteDirs):
182182
def namelist(self):
183183
return self._namelist
184184

185-
@functools.cached_property
186-
def _namelist(self):
187-
return super().namelist()
185+
def namelist(self):
186+
with contextlib.suppress(AttributeError):
187+
return self.__names
188+
self.__names = super().namelist()
189+
return self.__names
188190

189191
def _name_set(self):
190-
return self._name_set_prop
191-
192-
@functools.cached_property
193-
def _name_set_prop(self):
194-
return super()._name_set()
192+
with contextlib.suppress(AttributeError):
193+
return self.__lookup
194+
self.__lookup = super()._name_set()
195+
return self.__lookup
195196

196197

197198
def _extract_text_encoding(encoding=None, *args, **kwargs):
198199
# compute stack level so that the caller of the caller sees any warning.
199-
is_pypy = sys.implementation.name == 'pypy'
200+
is_pypy = sys.implementation.name == "pypy"
200201
# PyPy no longer special cased after 7.3.19 (or maybe 7.3.18)
201202
# See jaraco/zipp#143
202203
is_old_pypi = is_pypy and sys.pypy_version_info < (7, 3, 19)
@@ -334,7 +335,7 @@ def __eq__(self, other):
334335
def __hash__(self):
335336
return hash((self.root, self.at))
336337

337-
def open(self, mode='r', *args, pwd=None, **kwargs):
338+
def open(self, mode="r", *args, pwd=None, **kwargs):
338339
"""
339340
Open this entry as text or binary following the semantics
340341
of ``pathlib.Path.open()`` by passing arguments through
@@ -343,10 +344,10 @@ def open(self, mode='r', *args, pwd=None, **kwargs):
343344
if self.is_dir():
344345
raise IsADirectoryError(self)
345346
zip_mode = mode[0]
346-
if zip_mode == 'r' and not self.exists():
347+
if zip_mode == "r" and not self.exists():
347348
raise FileNotFoundError(self)
348349
stream = self.root.open(self.at, zip_mode, pwd=pwd)
349-
if 'b' in mode:
350+
if "b" in mode:
350351
if args or kwargs:
351352
raise ValueError("encoding args invalid for binary operation")
352353
return stream
@@ -379,11 +380,11 @@ def filename(self):
379380

380381
def read_text(self, *args, **kwargs):
381382
encoding, args, kwargs = _extract_text_encoding(*args, **kwargs)
382-
with self.open('r', encoding, *args, **kwargs) as strm:
383+
with self.open("r", encoding, *args, **kwargs) as strm:
383384
return strm.read()
384385

385386
def read_bytes(self):
386-
with self.open('rb') as strm:
387+
with self.open("rb") as strm:
387388
return strm.read()
388389

389390
def _is_child(self, path):
@@ -423,12 +424,12 @@ def glob(self, pattern):
423424
raise ValueError(f"Unacceptable pattern: {pattern!r}")
424425

425426
prefix = re.escape(self.at)
426-
tr = Translator(seps='/')
427+
tr = Translator(seps="/")
427428
matches = re.compile(prefix + tr.translate(pattern)).fullmatch
428429
return map(self._next, filter(matches, self.root.namelist()))
429430

430431
def rglob(self, pattern):
431-
return self.glob(f'**/{pattern}')
432+
return self.glob(f"**/{pattern}")
432433

433434
def relative_to(self, other, *extra):
434435
return posixpath.relpath(str(self), str(other.joinpath(*extra)))
@@ -449,7 +450,7 @@ def joinpath(self, *other):
449450
def parent(self):
450451
if not self.at:
451452
return self.filename.parent
452-
parent_at = posixpath.dirname(self.at.rstrip('/'))
453+
parent_at = posixpath.dirname(self.at.rstrip("/"))
453454
if parent_at:
454-
parent_at += '/'
455+
parent_at += "/"
455456
return self._next(parent_at)

Lib/zipfile/_path/_functools.py

Lines changed: 0 additions & 20 deletions
This file was deleted.
Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
Synchronized zipfile.Path with zipp 3.23, including improved performance of
2-
:meth:`zipfile.Path.open` for non-reading modes, rely on
3-
:func:`functools.cached_property` to cache values on the instance. Rely on
4-
``save_method_args`` to save the initialization method arguments. Fixed
1+
Backported bugfixes in zipfile.Path from zipp 3.23. Fixed
52
``.name``, ``.stem`` and other basename-based properties on Windows when
63
working with a zipfile on disk.

0 commit comments

Comments
 (0)