Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gevent
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
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
gevent
Commits
f9ad8e95
Commit
f9ad8e95
authored
Apr 29, 2020
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement canonical names for c-ares
parent
f20e334a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
58 additions
and
12 deletions
+58
-12
src/gevent/resolver/ares.py
src/gevent/resolver/ares.py
+7
-2
src/gevent/resolver/cares.pyx
src/gevent/resolver/cares.pyx
+17
-1
src/gevent/tests/test__socket_dns.py
src/gevent/tests/test__socket_dns.py
+34
-9
No files found.
src/gevent/resolver/ares.py
View file @
f9ad8e95
...
...
@@ -90,6 +90,9 @@ class Resolver(AbstractResolver):
``getaddrinfo``; unknown flags are ignored. System-specific flags
such as ``AI_V4MAPPED_CFG`` are not supported.
- ``getaddrinfo`` may return canonical names even without the ``AI_CANONNAME``
being set.
.. caution::
This module is considered extremely experimental on PyPy, and
...
...
@@ -102,6 +105,10 @@ class Resolver(AbstractResolver):
resolved <https://github.com/c-ares/c-ares/issues/196>`_ or even
sent to the DNS server.
.. versionchanged:: NEXT
``getaddrinfo`` is now implemented using the native c-ares function
from c-ares 1.16 or newer.
.. _c-ares: http://c-ares.haxx.se
"""
...
...
@@ -186,8 +193,6 @@ class Resolver(AbstractResolver):
"""
Returns a list ``(family, socktype, proto, canonname, sockaddr)``
TODO: Implement canonical names.
:raises gaierror: If no results are found.
"""
# pylint:disable=too-many-locals,too-many-branches
...
...
src/gevent/resolver/cares.pyx
View file @
f9ad8e95
...
...
@@ -535,8 +535,11 @@ cdef class channel:
int
timeouts
,
cares
.
ares_addrinfo
*
result
):
cdef
cares
.
ares_addrinfo_node
*
nodes
cdef
cares
.
ares_addrinfo_cname
*
cnames
cdef
sockaddr_in
*
sadr4
cdef
sockaddr_in6
*
sadr6
cdef
object
canonname
=
''
cdef
channel
channel
cdef
object
callback
# INET6_ADDRSTRLEN is 46, but we can't use that named constant
...
...
@@ -559,6 +562,19 @@ cdef class channel:
if
status
!=
cares
.
ARES_SUCCESS
:
callback
(
Result
(
None
,
gaierror
(
status
,
strerror
(
status
))))
return
if
result
.
cnames
:
# These tend to come in pairs:
#
# alias: www.gevent.org name: python-gevent.readthedocs.org
# alias: python-gevent.readthedocs.org name: readthedocs.io
#
# The standard library returns the last name so we do too.
cnames
=
result
.
cnames
while
cnames
:
canonname
=
_as_str
(
cnames
.
name
)
cnames
=
cnames
.
next
nodes
=
result
.
nodes
while
nodes
:
if
nodes
.
ai_family
==
AF_INET
:
...
...
@@ -584,7 +600,7 @@ cdef class channel:
nodes
.
ai_family
,
nodes
.
ai_socktype
,
nodes
.
ai_protocol
,
''
,
canonname
,
sockaddr
,
))
nodes
=
nodes
.
ai_next
...
...
src/gevent/tests/test__socket_dns.py
View file @
f9ad8e95
...
...
@@ -330,16 +330,25 @@ class TestCase(greentest.TestCase):
# On some systems, the hostname can get caps
return
(
result
[
0
].
lower
(),
[],
ips
)
def
_normalize_result_getaddrinfo
(
self
,
result
):
if
not
RESOLVER_NOT_SYSTEM
:
IGNORE_CANONICAL_NAME
=
RESOLVER_ARES
# It tends to return them even when not asked for
if
not
RESOLVER_NOT_SYSTEM
:
def
_normalize_result_getaddrinfo
(
self
,
result
):
return
result
else
:
def
_normalize_result_getaddrinfo
(
self
,
result
):
# On Python 3, the builtin resolver can return SOCK_RAW results, but
# c-ares doesn't do that. So we remove those if we find them.
if
hasattr
(
socket
,
'SOCK_RAW'
)
and
isinstance
(
result
,
list
):
result
=
[
x
for
x
in
result
if
x
[
1
]
!=
socket
.
SOCK_RAW
]
if
self
.
IGNORE_CANONICAL_NAME
:
result
=
[
(
family
,
kind
,
proto
,
''
,
addr
)
for
family
,
kind
,
proto
,
_
,
addr
in
result
]
if
isinstance
(
result
,
list
):
result
.
sort
()
return
result
# On Python 3, the builtin resolver can return SOCK_RAW results, but
# c-ares doesn't do that. So we remove those if we find them.
if
hasattr
(
socket
,
'SOCK_RAW'
)
and
isinstance
(
result
,
list
):
result
=
[
x
for
x
in
result
if
x
[
1
]
!=
socket
.
SOCK_RAW
]
if
isinstance
(
result
,
list
):
result
.
sort
()
return
result
def
_normalize_result_getnameinfo
(
self
,
result
):
return
result
...
...
@@ -583,6 +592,22 @@ class TestGeventOrg(TestCase):
result
=
(
'readthedocs.io'
,
)
+
result
[
1
:]
return
result
def
test_AI_CANONNAME
(
self
):
self
.
IGNORE_CANONICAL_NAME
=
False
result
=
self
.
_test
(
'getaddrinfo'
,
# host
TestGeventOrg
.
HOSTNAME
,
# port
None
,
# family
socket
.
AF_INET
,
# type
0
,
# proto
0
,
# flags
socket
.
AI_CANONNAME
)
self
.
assertEqual
(
result
[
0
][
3
],
'readthedocs.io'
)
add
(
TestGeventOrg
,
TestGeventOrg
.
HOSTNAME
)
...
...
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