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
ce12629c
Commit
ce12629c
authored
Nov 13, 2017
by
Yury Selivanov
Committed by
GitHub
Nov 13, 2017
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-28369: Enhance transport socket check in add_reader/writer (#4365)
parent
f76231f8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
90 additions
and
1 deletion
+90
-1
Lib/asyncio/selector_events.py
Lib/asyncio/selector_events.py
+9
-1
Lib/asyncio/test_utils.py
Lib/asyncio/test_utils.py
+7
-0
Lib/test/test_asyncio/test_unix_events.py
Lib/test/test_asyncio/test_unix_events.py
+70
-0
Misc/NEWS.d/next/Library/2017-11-10-16-27-26.bpo-28369.IS74nd.rst
...S.d/next/Library/2017-11-10-16-27-26.bpo-28369.IS74nd.rst
+4
-0
No files found.
Lib/asyncio/selector_events.py
View file @
ce12629c
...
...
@@ -246,8 +246,16 @@ class BaseSelectorEventLoop(base_events.BaseEventLoop):
self
.
call_exception_handler
(
context
)
def
_ensure_fd_no_transport
(
self
,
fd
):
fileno
=
fd
if
not
isinstance
(
fileno
,
int
):
try
:
fileno
=
int
(
fileno
.
fileno
())
except
(
AttributeError
,
TypeError
,
ValueError
):
# This code matches selectors._fileobj_to_fd function.
raise
ValueError
(
"Invalid file object: "
"{!r}"
.
format
(
fd
))
from
None
try
:
transport
=
self
.
_transports
[
f
d
]
transport
=
self
.
_transports
[
f
ileno
]
except
KeyError
:
pass
else
:
...
...
Lib/asyncio/test_utils.py
View file @
ce12629c
...
...
@@ -361,6 +361,13 @@ class TestLoop(base_events.BaseEventLoop):
handle
.
_args
,
args
)
def
_ensure_fd_no_transport
(
self
,
fd
):
if
not
isinstance
(
fd
,
int
):
try
:
fd
=
int
(
fd
.
fileno
())
except
(
AttributeError
,
TypeError
,
ValueError
):
# This code matches selectors._fileobj_to_fd function.
raise
ValueError
(
"Invalid file object: "
"{!r}"
.
format
(
fd
))
from
None
try
:
transport
=
self
.
_transports
[
fd
]
except
KeyError
:
...
...
Lib/test/test_asyncio/test_unix_events.py
View file @
ce12629c
...
...
@@ -1616,5 +1616,75 @@ class PolicyTests(unittest.TestCase):
new_loop
.
close
()
class
TestFunctional
(
unittest
.
TestCase
):
def
setUp
(
self
):
self
.
loop
=
asyncio
.
new_event_loop
()
asyncio
.
set_event_loop
(
self
.
loop
)
def
tearDown
(
self
):
self
.
loop
.
close
()
asyncio
.
set_event_loop
(
None
)
def
test_add_reader_invalid_argument
(
self
):
def
assert_raises
():
return
self
.
assertRaisesRegex
(
ValueError
,
r'Invalid file object'
)
cb
=
lambda
:
None
with
assert_raises
():
self
.
loop
.
add_reader
(
object
(),
cb
)
with
assert_raises
():
self
.
loop
.
add_writer
(
object
(),
cb
)
with
assert_raises
():
self
.
loop
.
remove_reader
(
object
())
with
assert_raises
():
self
.
loop
.
remove_writer
(
object
())
def
test_add_reader_or_writer_transport_fd
(
self
):
def
assert_raises
():
return
self
.
assertRaisesRegex
(
RuntimeError
,
r'File descriptor .* is used by transport'
)
async
def
runner
():
tr
,
pr
=
await
self
.
loop
.
create_connection
(
lambda
:
asyncio
.
Protocol
(),
sock
=
rsock
)
try
:
cb
=
lambda
:
None
with
assert_raises
():
self
.
loop
.
add_reader
(
rsock
,
cb
)
with
assert_raises
():
self
.
loop
.
add_reader
(
rsock
.
fileno
(),
cb
)
with
assert_raises
():
self
.
loop
.
remove_reader
(
rsock
)
with
assert_raises
():
self
.
loop
.
remove_reader
(
rsock
.
fileno
())
with
assert_raises
():
self
.
loop
.
add_writer
(
rsock
,
cb
)
with
assert_raises
():
self
.
loop
.
add_writer
(
rsock
.
fileno
(),
cb
)
with
assert_raises
():
self
.
loop
.
remove_writer
(
rsock
)
with
assert_raises
():
self
.
loop
.
remove_writer
(
rsock
.
fileno
())
finally
:
tr
.
close
()
rsock
,
wsock
=
socket
.
socketpair
()
try
:
self
.
loop
.
run_until_complete
(
runner
())
finally
:
rsock
.
close
()
wsock
.
close
()
if
__name__
==
'__main__'
:
unittest
.
main
()
Misc/NEWS.d/next/Library/2017-11-10-16-27-26.bpo-28369.IS74nd.rst
0 → 100644
View file @
ce12629c
Enhance add_reader/writer check that socket is not used by some transport.
Before, only cases when add_reader/writer were called with an int FD were
supported. Now the check is implemented correctly for all file-like
objects.
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