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
6e0ef748
Commit
6e0ef748
authored
Nov 12, 2018
by
Jason Madden
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make gevent.socket.getaddrinfo return enums on Python 3
Fixes #1310
parent
a2c56938
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
54 additions
and
16 deletions
+54
-16
CHANGES.rst
CHANGES.rst
+4
-0
src/gevent/_socketcommon.py
src/gevent/_socketcommon.py
+21
-2
src/gevent/resolver/__init__.py
src/gevent/resolver/__init__.py
+8
-8
src/gevent/tests/test__ares_host_result.py
src/gevent/tests/test__ares_host_result.py
+7
-6
src/gevent/tests/test__socket_dns.py
src/gevent/tests/test__socket_dns.py
+14
-0
No files found.
CHANGES.rst
View file @
6e0ef748
...
...
@@ -46,6 +46,10 @@
reusable. In particular, the tests are now run with ``python -m
gevent.tests``. See :issue:`1293`.
- Make a monkey-patched ``socket.getaddrinfo`` return socket module
enums instead of plain integers for the socket type and address
family on Python 3. See :issue:`1310` reported by TheYOSH.
1.3.7 (2018-10-12)
==================
...
...
src/gevent/_socketcommon.py
View file @
6e0ef748
...
...
@@ -204,11 +204,30 @@ if PY3:
# the deprecation warning.
d
=
getaddrinfo
.
__doc__
def
getaddrinfo
(
host
,
port
,
family
=
0
,
type
=
0
,
proto
=
0
,
flags
=
0
):
# pylint:disable=function-redefined
return
get_hub
().
resolver
.
getaddrinfo
(
host
,
port
,
family
,
type
,
proto
,
flags
)
def
getaddrinfo
(
host
,
port
,
family
=
0
,
type
=
0
,
proto
=
0
,
flags
=
0
):
# pylint:disable=function-redefined, undefined-variable
# Also, on Python 3, we need to translate into the special enums.
# Our lower-level resolvers, including the thread and blocking, which use _socket,
# function simply with integers.
addrlist
=
get_hub
().
resolver
.
getaddrinfo
(
host
,
port
,
family
,
type
,
proto
,
flags
)
result
=
[
(
_intenum_converter
(
af
,
AddressFamily
),
_intenum_converter
(
socktype
,
SocketKind
),
proto
,
canonname
,
sa
)
for
af
,
socktype
,
proto
,
canonname
,
sa
in
addrlist
]
return
result
getaddrinfo
.
__doc__
=
d
del
d
def
_intenum_converter
(
value
,
enum_klass
):
try
:
return
enum_klass
(
value
)
except
ValueError
:
return
value
def
gethostbyaddr
(
ip_address
):
"""
...
...
src/gevent/resolver/__init__.py
View file @
6e0ef748
...
...
@@ -4,18 +4,18 @@ from _socket import gaierror
from
_socket
import
error
from
_socket
import
getservbyname
from
_socket
import
getaddrinfo
from
_socket
import
SOCK_STREAM
from
_socket
import
SOCK_DGRAM
from
_socket
import
SOL_TCP
from
_socket
import
AI_CANONNAME
from
_socket
import
EAI_SERVICE
from
_socket
import
AF_INET
from
_socket
import
AI_PASSIVE
from
gevent._compat
import
string_types
from
gevent._compat
import
integer_types
from
gevent.socket
import
SOCK_STREAM
from
gevent.socket
import
SOCK_DGRAM
from
gevent.socket
import
SOL_TCP
from
gevent.socket
import
AI_CANONNAME
from
gevent.socket
import
EAI_SERVICE
from
gevent.socket
import
AF_INET
from
gevent.socket
import
AI_PASSIVE
# Nothing public here.
__all__
=
[]
...
...
src/gevent/tests/test__ares_host_result.py
View file @
6e0ef748
from
__future__
import
print_function
import
pickle
import
sys
import
gevent.testing
as
greentest
try
:
from
gevent.resolver.cares
import
ares_host_result
except
ImportError
as
ex
:
print
(
ex
)
sys
.
exit
(
0
)
except
ImportError
:
# pragma: no cover
ares_host_result
=
None
@
greentest
.
skipIf
(
ares_host_result
is
None
,
"Must be able to import ares"
)
class
TestPickle
(
greentest
.
TestCase
):
# Issue 104: ares.ares_host_result unpickleable
...
...
@@ -17,8 +17,9 @@ class TestPickle(greentest.TestCase):
r
=
ares_host_result
(
'family'
,
(
'arg1'
,
'arg2'
,
))
dumped
=
pickle
.
dumps
(
r
,
protocol
)
loaded
=
pickle
.
loads
(
dumped
)
assert
r
==
loaded
,
(
r
,
loaded
)
assert
r
.
family
==
loaded
.
family
,
(
r
,
loaded
)
self
.
assertEqual
(
r
,
loaded
)
self
.
assertEqual
(
r
.
family
,
loaded
.
family
)
for
i
in
range
(
0
,
pickle
.
HIGHEST_PROTOCOL
):
def
make_test
(
j
):
...
...
src/gevent/tests/test__socket_dns.py
View file @
6e0ef748
...
...
@@ -564,6 +564,20 @@ class Test_getaddrinfo(TestCase):
return
self
.
_test_getaddrinfo
(
'google.com'
,
'http'
,
socket
.
AF_INET6
)
@
greentest
.
skipIf
(
PY2
,
"Enums only on Python 3.4+"
)
def
test_enums
(
self
):
# https://github.com/gevent/gevent/issues/1310
# On Python 3, getaddrinfo does special things to make sure that
# the fancy enums are returned.
gai
=
gevent_socket
.
getaddrinfo
(
'example.com'
,
80
,
socket
.
AF_INET
,
socket
.
SOCK_STREAM
,
socket
.
IPPROTO_TCP
)
af
,
socktype
,
_proto
,
_canonname
,
_sa
=
gai
[
0
]
self
.
assertIs
(
socktype
,
socket
.
SOCK_STREAM
)
self
.
assertIs
(
af
,
socket
.
AF_INET
)
class
TestInternational
(
TestCase
):
pass
...
...
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