From d0837ba1cf8324d678b54567a7570421b7ede18c Mon Sep 17 00:00:00 2001 From: Sergey Shepelev Date: Tue, 24 May 2016 12:59:47 +0500 Subject: [PATCH] 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 --- eventlet/greenio/base.py | 8 ++++---- tests/socket_test.py | 6 ++++++ 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/eventlet/greenio/base.py b/eventlet/greenio/base.py index 60a8f29..5ed2593 100644 --- a/eventlet/greenio/base.py +++ b/eventlet/greenio/base.py @@ -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: diff --git a/tests/socket_test.py b/tests/socket_test.py index 5dea1b9..6bd32a8 100644 --- a/tests/socket_test.py +++ b/tests/socket_test.py @@ -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)