Commit 07035b7e authored by Jason Madden's avatar Jason Madden

Down to one failing test.

parent bd96d8e1
......@@ -110,31 +110,21 @@ class socket(_socketcommon.SocketMixin):
# don't subclass it. This lets code that needs the raw _sock (not tied to the hub)
# get it. This shows up in tests like test__example_udp_server.
if sys.version_info[:2] < (3, 7):
def __init__(self, family=AF_INET, type=SOCK_STREAM, proto=0, fileno=None):
super().__init__()
self._closed = False
self._sock = self._gevent_sock_class(family, type, proto, fileno)
self.timeout = None
self.__init_common()
else:
# In 3.7, socket changed to auto-detecting family, type, and proto
# when given a fileno.
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
super().__init__()
self._closed = False
if fileno is None:
if family == -1:
family = AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
self._sock = self._gevent_sock_class(family, type, proto, fileno)
self.timeout = None
self.__init_common()
def __init_common(self):
# In 3.7, socket changed to auto-detecting family, type, and proto
# when given a fileno.
def __init__(self, family=-1, type=-1, proto=-1, fileno=None):
super().__init__()
self._closed = False
if fileno is None:
if family == -1:
family = AddressFamily.AF_INET
if type == -1:
type = SOCK_STREAM
if proto == -1:
proto = 0
self._sock = self._gevent_sock_class(family, type, proto, fileno)
self.timeout = None
self._io_refs = 0
_socket.socket.setblocking(self._sock, False)
fileno = _socket.socket.fileno(self._sock)
......
......@@ -51,9 +51,6 @@ __imports__ = [
'setdefaulttimeout',
# Windows:
'errorTab',
]
__py3_imports__ = [
# Python 3
'AddressFamily',
'SocketKind',
......@@ -64,15 +61,15 @@ __py3_imports__ = [
'if_nameindex',
'if_nametoindex',
'sethostname',
'create_server',
'has_dualstack_ipv6',
]
__imports__.extend(__py3_imports__)
import time
from gevent._hub_local import get_hub_noargs as get_hub
from gevent._compat import string_types, integer_types, PY3
from gevent._compat import PY38
from gevent._compat import string_types, integer_types
from gevent._compat import PY39
from gevent._compat import WIN as is_windows
from gevent._compat import OSX as is_macos
......@@ -83,11 +80,6 @@ from gevent._hub_primitives import wait_on_socket as _wait_on_socket
from gevent.timeout import Timeout
if PY38:
__imports__.extend([
'create_server',
'has_dualstack_ipv6',
])
if PY39:
__imports__.extend([
......@@ -210,8 +202,7 @@ def gethostbyname_ex(hostname):
"""
return get_hub().resolver.gethostbyname_ex(hostname)
def getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
def getaddrinfo(host, port, family=0, type=0, proto=0, flags=0):
"""
Resolve host and port into list of address info entries.
......@@ -228,40 +219,24 @@ def getaddrinfo(host, port, family=0, socktype=0, proto=0, flags=0):
.. seealso:: :doc:`/dns`
"""
return get_hub().resolver.getaddrinfo(host, port, family, socktype, proto, flags)
if PY3:
# The name of the socktype param changed to type in Python 3.
# See https://github.com/gevent/gevent/issues/960
# Using inspect here to directly detect the condition is painful because we have to
# wrap it with a try/except TypeError because not all Python 2
# versions can get the args of a builtin; we also have to use a with to suppress
# the deprecation warning.
d = getaddrinfo.__doc__
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: # pragma: no cover
return value
# 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
def _intenum_converter(value, enum_klass):
try:
return enum_klass(value)
except ValueError: # pragma: no cover
return value
def gethostbyaddr(ip_address):
......@@ -546,8 +521,8 @@ class SocketMixin(object):
self.hub.cancel_wait(self._write_event, cancel_wait_ex)
self._sock.shutdown(how)
family = property(lambda self: self._sock.family)
type = property(lambda self: self._sock.type)
family = property(lambda self: _intenum_converter(self._sock.family, AddressFamily))
type = property(lambda self: _intenum_converter(self._sock.type, SocketKind))
proto = property(lambda self: self._sock.proto)
def fileno(self):
......
......@@ -123,7 +123,7 @@ def notify_and_call_entry_points(event):
# Prior to 3.9, there is no ``.module`` attribute, so if we
# needed that we'd have to look at the complete ``.value``
# attribute.
ep_dict = entry_points()
ep_dict = metadata.entry_points()
__traceback_info__ = ep_dict
# On Python 3.8, we can get duplicate EntryPoint objects; it is unclear
# why. Drop them into a set to make sure we only get one.
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment