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
4c16b8ad
Commit
4c16b8ad
authored
Nov 21, 2016
by
Yury Selivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #28652: Partially rollback previous changes
Allow AF_UNIX in create_server & create_connection
parent
9180d527
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
14 additions
and
18 deletions
+14
-18
Lib/asyncio/base_events.py
Lib/asyncio/base_events.py
+10
-12
Lib/test/test_asyncio/test_base_events.py
Lib/test/test_asyncio/test_base_events.py
+4
-6
No files found.
Lib/asyncio/base_events.py
View file @
4c16b8ad
...
@@ -98,14 +98,6 @@ def _is_dgram_socket(sock):
...
@@ -98,14 +98,6 @@ def _is_dgram_socket(sock):
return
(
sock
.
type
&
socket
.
SOCK_DGRAM
)
==
socket
.
SOCK_DGRAM
return
(
sock
.
type
&
socket
.
SOCK_DGRAM
)
==
socket
.
SOCK_DGRAM
def
_is_ip_socket
(
sock
):
if
sock
.
family
==
socket
.
AF_INET
:
return
True
if
hasattr
(
socket
,
'AF_INET6'
)
and
sock
.
family
==
socket
.
AF_INET6
:
return
True
return
False
def
_ipaddr_info
(
host
,
port
,
family
,
type
,
proto
):
def
_ipaddr_info
(
host
,
port
,
family
,
type
,
proto
):
# Try to skip getaddrinfo if "host" is already an IP. Users might have
# Try to skip getaddrinfo if "host" is already an IP. Users might have
# handled name resolution in their own code and pass in resolved IPs.
# handled name resolution in their own code and pass in resolved IPs.
...
@@ -795,9 +787,15 @@ class BaseEventLoop(events.AbstractEventLoop):
...
@@ -795,9 +787,15 @@ class BaseEventLoop(events.AbstractEventLoop):
if
sock
is
None
:
if
sock
is
None
:
raise
ValueError
(
raise
ValueError
(
'host and port was not specified and no sock specified'
)
'host and port was not specified and no sock specified'
)
if
not
_is_stream_socket
(
sock
)
or
not
_is_ip_socket
(
sock
):
if
not
_is_stream_socket
(
sock
):
# We allow AF_INET, AF_INET6, AF_UNIX as long as they
# are SOCK_STREAM.
# We support passing AF_UNIX sockets even though we have
# a dedicated API for that: create_unix_connection.
# Disallowing AF_UNIX in this method, breaks backwards
# compatibility.
raise
ValueError
(
raise
ValueError
(
'A
TCP
Stream Socket was expected, got {!r}'
.
format
(
sock
))
'A Stream Socket was expected, got {!r}'
.
format
(
sock
))
transport
,
protocol
=
yield
from
self
.
_create_connection_transport
(
transport
,
protocol
=
yield
from
self
.
_create_connection_transport
(
sock
,
protocol_factory
,
ssl
,
server_hostname
)
sock
,
protocol_factory
,
ssl
,
server_hostname
)
...
@@ -1054,9 +1052,9 @@ class BaseEventLoop(events.AbstractEventLoop):
...
@@ -1054,9 +1052,9 @@ class BaseEventLoop(events.AbstractEventLoop):
else
:
else
:
if
sock
is
None
:
if
sock
is
None
:
raise
ValueError
(
'Neither host/port nor sock were specified'
)
raise
ValueError
(
'Neither host/port nor sock were specified'
)
if
not
_is_stream_socket
(
sock
)
or
not
_is_ip_socket
(
sock
)
:
if
not
_is_stream_socket
(
sock
):
raise
ValueError
(
raise
ValueError
(
'A
TCP
Stream Socket was expected, got {!r}'
.
format
(
sock
))
'A Stream Socket was expected, got {!r}'
.
format
(
sock
))
sockets
=
[
sock
]
sockets
=
[
sock
]
server
=
Server
(
self
,
sockets
)
server
=
Server
(
self
,
sockets
)
...
...
Lib/test/test_asyncio/test_base_events.py
View file @
4c16b8ad
...
@@ -1047,22 +1047,20 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
...
@@ -1047,22 +1047,20 @@ class BaseEventLoopWithSelectorTests(test_utils.TestCase):
MyProto
,
'example.com'
,
80
,
sock
=
object
())
MyProto
,
'example.com'
,
80
,
sock
=
object
())
self
.
assertRaises
(
ValueError
,
self
.
loop
.
run_until_complete
,
coro
)
self
.
assertRaises
(
ValueError
,
self
.
loop
.
run_until_complete
,
coro
)
@
unittest
.
skipUnless
(
hasattr
(
socket
,
'AF_UNIX'
),
'no Unix sockets'
)
def
test_create_connection_wrong_sock
(
self
):
def
test_create_connection_wrong_sock
(
self
):
sock
=
socket
.
socket
(
socket
.
AF_
UNIX
)
sock
=
socket
.
socket
(
socket
.
AF_
INET
,
socket
.
SOCK_DGRAM
)
with
sock
:
with
sock
:
coro
=
self
.
loop
.
create_connection
(
MyProto
,
sock
=
sock
)
coro
=
self
.
loop
.
create_connection
(
MyProto
,
sock
=
sock
)
with
self
.
assertRaisesRegex
(
ValueError
,
with
self
.
assertRaisesRegex
(
ValueError
,
'A
TCP
Stream Socket was expected'
):
'A Stream Socket was expected'
):
self
.
loop
.
run_until_complete
(
coro
)
self
.
loop
.
run_until_complete
(
coro
)
@
unittest
.
skipUnless
(
hasattr
(
socket
,
'AF_UNIX'
),
'no Unix sockets'
)
def
test_create_server_wrong_sock
(
self
):
def
test_create_server_wrong_sock
(
self
):
sock
=
socket
.
socket
(
socket
.
AF_
UNIX
)
sock
=
socket
.
socket
(
socket
.
AF_
INET
,
socket
.
SOCK_DGRAM
)
with
sock
:
with
sock
:
coro
=
self
.
loop
.
create_server
(
MyProto
,
sock
=
sock
)
coro
=
self
.
loop
.
create_server
(
MyProto
,
sock
=
sock
)
with
self
.
assertRaisesRegex
(
ValueError
,
with
self
.
assertRaisesRegex
(
ValueError
,
'A
TCP
Stream Socket was expected'
):
'A Stream Socket was expected'
):
self
.
loop
.
run_until_complete
(
coro
)
self
.
loop
.
run_until_complete
(
coro
)
@
unittest
.
skipUnless
(
hasattr
(
socket
,
'SOCK_NONBLOCK'
),
@
unittest
.
skipUnless
(
hasattr
(
socket
,
'SOCK_NONBLOCK'
),
...
...
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