[Python-Dev] [Python-checkins] r86699 - python/branches/py3k/Lib/zipfile.py (original) (raw)
Łukasz Langa lukasz at langa.pl
Tue Nov 23 01:25:01 CET 2010
- Previous message: [Python-Dev] [Python-checkins] r86699 - python/branches/py3k/Lib/zipfile.py
- Next message: [Python-Dev] [Python-checkins] r86699 - python/branches/py3k/Lib/zipfile.py
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Wiadomość napisana przez Benjamin Peterson w dniu 2010-11-23, o godz. 00:47:
No test?
The tests were there already, raising ResourceWarnings. After this change, they stopped doing that. You may say: now they pass for the first time :)
Best regards, Łukasz
2010/11/22 lukasz.langa <python-checkins at python.org>:
Author: lukasz.langa Date: Tue Nov 23 00:31:26 2010 New Revision: 86699
Log: Issue #9846: ZipExtFile provides no mechanism for closing the underlying file object
Modified: python/branches/py3k/Lib/zipfile.py Modified: python/branches/py3k/Lib/zipfile.py ============================================================================== --- python/branches/py3k/Lib/zipfile.py (original) +++ python/branches/py3k/Lib/zipfile.py Tue Nov 23 00:31:26 2010 @@ -473,9 +473,11 @@ # Search for universal newlines or line chunks. PATTERN = re.compile(br'^(?P[^\r\n]+)|(?P\n|\r\n?)') - def init(self, fileobj, mode, zipinfo, decrypter=None): + def init(self, fileobj, mode, zipinfo, decrypter=None, + closefileobj=False): self.fileobj = fileobj self.decrypter = decrypter + self.closefileobj = closefileobj self.compresstype = zipinfo.compresstype self.compresssize = zipinfo.compresssize @@ -647,6 +649,12 @@ self.offset += len(data) return data + def close(self): + try: + if self.closefileobj: + self.fileobj.close() + finally: + super().close() class ZipFile: @@ -889,8 +897,10 @@ # given a file object in the constructor if self.filePassed: zeffile = self.fp + shouldclose = False else: zeffile = io.open(self.filename, 'rb') + shouldclose = True # Make sure we have an info object if isinstance(name, ZipInfo): @@ -944,7 +954,7 @@ if h[11] != checkbyte: raise RuntimeError("Bad password for file", name) - return ZipExtFile(zeffile, mode, zinfo, zd) + return ZipExtFile(zeffile, mode, zinfo, zd, closefileobj=shouldclose) def extract(self, member, path=None, pwd=None): """Extract a member from the archive to the current working directory,
Python-checkins mailing list Python-checkins at python.org http://mail.python.org/mailman/listinfo/python-checkins
-- Regards, Benjamin
Python-checkins mailing list Python-checkins at python.org http://mail.python.org/mailman/listinfo/python-checkins
-- Pozdrawiam serdecznie, Łukasz Langa tel. +48 791 080 144 WWW http://lukasz.langa.pl/
-------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mail.python.org/pipermail/python-dev/attachments/20101123/5cb7412d/attachment.html>
- Previous message: [Python-Dev] [Python-checkins] r86699 - python/branches/py3k/Lib/zipfile.py
- Next message: [Python-Dev] [Python-checkins] r86699 - python/branches/py3k/Lib/zipfile.py
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]