mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-41490: `path
and
contents
` to aggressively close handles (#22915)
* bpo-41490: ``path`` method to aggressively close handles * Add blurb * In ZipReader.contents, eagerly evaluate the contents to release references to the zipfile. * Instead use _ensure_sequence to ensure any iterable from a reader is eagerly converted to a list if it's not already a sequence.
This commit is contained in:
parent
c32f2976b8
commit
df8d4c83a6
7 changed files with 114 additions and 16 deletions
|
@ -22,8 +22,8 @@ class FileReader(abc.TraversableResources):
|
|||
class ZipReader(abc.TraversableResources):
|
||||
def __init__(self, loader, module):
|
||||
_, _, name = module.rpartition('.')
|
||||
prefix = loader.prefix.replace('\\', '/') + name + '/'
|
||||
self.path = zipfile.Path(loader.archive, prefix)
|
||||
self.prefix = loader.prefix.replace('\\', '/') + name + '/'
|
||||
self.archive = loader.archive
|
||||
|
||||
def open_resource(self, resource):
|
||||
try:
|
||||
|
@ -38,4 +38,4 @@ class ZipReader(abc.TraversableResources):
|
|||
return target.is_file() and target.exists()
|
||||
|
||||
def files(self):
|
||||
return self.path
|
||||
return zipfile.Path(self.archive, self.prefix)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue