Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
93d628b3
Commit
93d628b3
authored
Nov 04, 2012
by
Jesus Cea
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Closes #16183: ZipExtFile object close without file handle closed (backporting of Issue #9846)
parent
146a5fea
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
13 additions
and
2 deletions
+13
-2
Lib/zipfile.py
Lib/zipfile.py
+13
-2
No files found.
Lib/zipfile.py
View file @
93d628b3
...
@@ -475,9 +475,11 @@ class ZipExtFile(io.BufferedIOBase):
...
@@ -475,9 +475,11 @@ class ZipExtFile(io.BufferedIOBase):
# Search for universal newlines or line chunks.
# Search for universal newlines or line chunks.
PATTERN
=
re
.
compile
(
r'^(?P<chunk>[^\r\n]+)|(?P<newline>\n|\r\n?)'
)
PATTERN
=
re
.
compile
(
r'^(?P<chunk>[^\r\n]+)|(?P<newline>\n|\r\n?)'
)
def
__init__
(
self
,
fileobj
,
mode
,
zipinfo
,
decrypter
=
None
):
def
__init__
(
self
,
fileobj
,
mode
,
zipinfo
,
decrypter
=
None
,
close_fileobj
=
False
):
self
.
_fileobj
=
fileobj
self
.
_fileobj
=
fileobj
self
.
_decrypter
=
decrypter
self
.
_decrypter
=
decrypter
self
.
_close_fileobj
=
close_fileobj
self
.
_compress_type
=
zipinfo
.
compress_type
self
.
_compress_type
=
zipinfo
.
compress_type
self
.
_compress_size
=
zipinfo
.
compress_size
self
.
_compress_size
=
zipinfo
.
compress_size
...
@@ -649,6 +651,12 @@ class ZipExtFile(io.BufferedIOBase):
...
@@ -649,6 +651,12 @@ class ZipExtFile(io.BufferedIOBase):
self
.
_offset
+=
len
(
data
)
self
.
_offset
+=
len
(
data
)
return
data
return
data
def
close
(
self
):
try
:
if
self
.
_close_fileobj
:
self
.
_fileobj
.
close
()
finally
:
super
(
ZipExtFile
,
self
).
close
()
class
ZipFile
(
object
):
class
ZipFile
(
object
):
...
@@ -896,8 +904,10 @@ class ZipFile(object):
...
@@ -896,8 +904,10 @@ class ZipFile(object):
# given a file object in the constructor
# given a file object in the constructor
if
self
.
_filePassed
:
if
self
.
_filePassed
:
zef_file
=
self
.
fp
zef_file
=
self
.
fp
should_close
=
False
else
:
else
:
zef_file
=
open
(
self
.
filename
,
'rb'
)
zef_file
=
open
(
self
.
filename
,
'rb'
)
should_close
=
True
# Make sure we have an info object
# Make sure we have an info object
if
isinstance
(
name
,
ZipInfo
):
if
isinstance
(
name
,
ZipInfo
):
...
@@ -951,7 +961,8 @@ class ZipFile(object):
...
@@ -951,7 +961,8 @@ class ZipFile(object):
if
ord
(
h
[
11
])
!=
check_byte
:
if
ord
(
h
[
11
])
!=
check_byte
:
raise
RuntimeError
(
"Bad password for file"
,
name
)
raise
RuntimeError
(
"Bad password for file"
,
name
)
return
ZipExtFile
(
zef_file
,
mode
,
zinfo
,
zd
)
return
ZipExtFile
(
zef_file
,
mode
,
zinfo
,
zd
,
close_fileobj
=
should_close
)
def
extract
(
self
,
member
,
path
=
None
,
pwd
=
None
):
def
extract
(
self
,
member
,
path
=
None
,
pwd
=
None
):
"""Extract a member from the archive to the current working directory,
"""Extract a member from the archive to the current working directory,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment