Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try using super() to prevent recursion #750

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
76 changes: 41 additions & 35 deletions eventlet/green/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,25 @@

@contextmanager
def _original_ssl_context(*args, **kwargs):
tmp_sslcontext = _original_wrap_socket.__globals__.get('SSLContext', None)
tmp_sslsocket = _original_sslsocket._create.__globals__.get('SSLSocket', None)
_original_sslsocket._create.__globals__['SSLSocket'] = _original_sslsocket
_original_wrap_socket.__globals__['SSLContext'] = _original_sslcontext
tmp_sslcontext = _original_wrap_socket.__globals__.get("SSLContext", None)
tmp_sslsocket = _original_sslsocket.sslsocket_class._create.__globals__.get(
"SSLSocket", None
)
_original_sslsocket.sslsocket_class._create.__globals__[
"SSLSocket"
] = _original_sslsocket
_original_wrap_socket.__globals__["SSLContext"] = _original_sslcontext
try:
yield
finally:
_original_wrap_socket.__globals__['SSLContext'] = tmp_sslcontext
_original_sslsocket._create.__globals__['SSLSocket'] = tmp_sslsocket
_original_wrap_socket.__globals__["SSLContext"] = tmp_sslcontext
_original_sslsocket.sslsocket_class._create.__globals__[
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please don't shrink it

there's max-line-width = 123 in tox.ini

if you want to introduce black formatter it's very much welcome in separate patch, with 123 width

"SSLSocket"
] = tmp_sslsocket


class GreenSSLSocket(_original_sslsocket):
""" This is a green version of the SSLSocket class from the ssl module added
"""This is a green version of the SSLSocket class from the ssl module added
in 2.6. For documentation on it, please see the Python standard
documentation.

Expand Down Expand Up @@ -447,37 +453,37 @@ def wrap_socket(self, sock, *a, **kw):

# https://github.com/eventlet/eventlet/issues/371
# Thanks to Gevent developers for sharing patch to this problem.
if hasattr(_original_sslcontext.options, 'setter'):
# In 3.6, these became properties. They want to access the
# property __set__ method in the superclass, and they do so by using
# super(SSLContext, SSLContext). But we rebind SSLContext when we monkey
# patch, which causes infinite recursion.
# https://github.com/python/cpython/commit/328067c468f82e4ec1b5c510a4e84509e010f296
@_original_sslcontext.options.setter
def options(self, value):
super(_original_sslcontext, _original_sslcontext).options.__set__(self, value)

@_original_sslcontext.verify_flags.setter
def verify_flags(self, value):
super(_original_sslcontext, _original_sslcontext).verify_flags.__set__(self, value)

@_original_sslcontext.verify_mode.setter
def verify_mode(self, value):
super(_original_sslcontext, _original_sslcontext).verify_mode.__set__(self, value)

if hasattr(_original_sslcontext, "maximum_version"):
@_original_sslcontext.maximum_version.setter
def maximum_version(self, value):
super(_original_sslcontext, _original_sslcontext).maximum_version.__set__(self, value)

if hasattr(_original_sslcontext, "minimum_version"):
@_original_sslcontext.minimum_version.setter
def minimum_version(self, value):
super(_original_sslcontext, _original_sslcontext).minimum_version.__set__(self, value)
# if hasattr(_original_sslcontext.options, 'setter'):
# # In 3.6, these became properties. They want to access the
# # property __set__ method in the superclass, and they do so by using
# # super(SSLContext, SSLContext). But we rebind SSLContext when we monkey
# # patch, which causes infinite recursion.
# # https://github.com/python/cpython/commit/328067c468f82e4ec1b5c510a4e84509e010f296
# @_original_sslcontext.options.setter
# def options(self, value):
# super(_original_sslcontext, _original_sslcontext).options.__set__(self, value)

# @_original_sslcontext.verify_flags.setter
# def verify_flags(self, value):
# super(_original_sslcontext, _original_sslcontext).verify_flags.__set__(self, value)

# @_original_sslcontext.verify_mode.setter
# def verify_mode(self, value):
# super(_original_sslcontext, _original_sslcontext).verify_mode.__set__(self, value)

# if hasattr(_original_sslcontext, "maximum_version"):
# @_original_sslcontext.maximum_version.setter
# def maximum_version(self, value):
# super(_original_sslcontext, _original_sslcontext).maximum_version.__set__(self, value)

# if hasattr(_original_sslcontext, "minimum_version"):
# @_original_sslcontext.minimum_version.setter
# def minimum_version(self, value):
# super(_original_sslcontext, _original_sslcontext).minimum_version.__set__(self, value)

SSLContext = GreenSSLContext

if hasattr(__ssl, 'create_default_context'):
if hasattr(__ssl, "create_default_context"):
_original_create_default_context = __ssl.create_default_context

def green_create_default_context(*a, **kw):
Expand Down