socket: family kwarg name compatibility

GreenSocket was (family_or_realsock=AF_INET, ...) which breaks code like socket(family=...)
https://github.com/eventlet/eventlet/issues/319
This commit is contained in:
Sergey Shepelev
2016-05-24 12:59:47 +05:00
parent 8f30065548
commit d0837ba1cf
2 changed files with 10 additions and 4 deletions

View File

@@ -125,14 +125,14 @@ class GreenSocket(object):
# This placeholder is to prevent __getattr__ from creating an infinite call loop
fd = None
def __init__(self, family_or_realsock=socket.AF_INET, *args, **kwargs):
def __init__(self, family=socket.AF_INET, *args, **kwargs):
should_set_nonblocking = kwargs.pop('set_nonblocking', True)
if isinstance(family_or_realsock, six.integer_types):
fd = _original_socket(family_or_realsock, *args, **kwargs)
if isinstance(family, six.integer_types):
fd = _original_socket(family, *args, **kwargs)
# Notify the hub that this is a newly-opened socket.
notify_opened(fd.fileno())
else:
fd = family_or_realsock
fd = family
# import timeout from other socket, if it was there
try:

View File

@@ -43,3 +43,9 @@ def test_dns_methods_are_green():
assert socket.gethostbyname_ex is greendns.gethostbyname_ex
assert socket.getaddrinfo is greendns.getaddrinfo
assert socket.getnameinfo is greendns.getnameinfo
def test_socket_api_family():
# It was named family_or_realsock
# https://github.com/eventlet/eventlet/issues/319
socket.socket(family=socket.AF_INET)