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
95351056
Commit
95351056
authored
Jun 17, 2011
by
R David Murray
Browse files
Options
Browse Files
Download
Plain Diff
merge #11700: proxy object close methods can now be called multiple times
parents
85198753
c88bce15
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
25 additions
and
5 deletions
+25
-5
Lib/mailbox.py
Lib/mailbox.py
+10
-4
Lib/test/test_mailbox.py
Lib/test/test_mailbox.py
+12
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/mailbox.py
View file @
95351056
...
...
@@ -1923,9 +1923,10 @@ class _ProxyFile:
def
close
(
self
):
"""Close the file."""
if
hasattr
(
self
.
_file
,
'close'
):
self
.
_file
.
close
()
del
self
.
_file
if
hasattr
(
self
,
'_file'
):
if
hasattr
(
self
.
_file
,
'close'
):
self
.
_file
.
close
()
del
self
.
_file
def
_read
(
self
,
size
,
read_method
):
"""Read size bytes using read_method."""
...
...
@@ -1957,6 +1958,10 @@ class _ProxyFile:
@
property
def
closed
(
self
):
if
not
hasattr
(
self
,
'_file'
):
return
True
if
not
hasattr
(
self
.
_file
,
'closed'
):
return
False
return
self
.
_file
.
closed
...
...
@@ -1995,7 +2000,8 @@ class _PartialFile(_ProxyFile):
def
close
(
self
):
# do *not* close the underlying file object for partial files,
# since it's global to the mailbox object
del
self
.
_file
if
hasattr
(
self
,
'_file'
):
del
self
.
_file
def
_lock_file
(
f
,
dotlock
=
True
):
...
...
Lib/test/test_mailbox.py
View file @
95351056
...
...
@@ -297,6 +297,13 @@ class TestMailbox(TestBase):
self
.
assertEqual
(
data1
.
decode
(
'ascii'
).
replace
(
os
.
linesep
,
'
\
n
'
),
_sample_message
)
def
test_get_file_can_be_closed_twice
(
self
):
# Issue 11700
key
=
self
.
_box
.
add
(
_sample_message
)
f
=
self
.
_box
.
get_file
(
key
)
f
.
close
()
f
.
close
()
def
test_iterkeys
(
self
):
# Get keys using iterkeys()
self
.
_check_iteration
(
self
.
_box
.
keys
,
do_keys
=
True
,
do_values
=
False
)
...
...
@@ -1862,8 +1869,12 @@ class TestProxyFileBase(TestBase):
def _test_close(self, proxy):
# Close a file
self.assertFalse(proxy.closed)
proxy.close()
self.assertTrue(proxy.closed)
# Issue 11700 subsequent closes should be a no-op.
proxy.close()
self.assert
Raises(AttributeError, lambda: proxy.close()
)
self.assert
True(proxy.closed
)
class TestProxyFile(TestProxyFileBase):
...
...
Misc/NEWS
View file @
95351056
...
...
@@ -193,6 +193,9 @@ Core and Builtins
Library
-------
- Issue #11700: mailbox proxy object close methods can now be called multiple
times without error.
- Issue #11767: Correct file descriptor leak in mailbox'
s
__getitem__
method
.
-
Issue
#
12133
:
AbstractHTTPHandler
.
do_open
()
of
urllib
.
request
closes
the
HTTP
...
...
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