Skip to content

Commit

Permalink
green.ssl don't monkey-patch at import time
Browse files Browse the repository at this point in the history
  • Loading branch information
davidszotten committed Dec 18, 2015
1 parent 3ae710e commit e2e9be0
Showing 1 changed file with 21 additions and 9 deletions.
30 changes: 21 additions & 9 deletions eventlet/green/ssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
has_ciphers = False
timeout_exc = orig_socket.timeout

__patched__ = ['SSLSocket', 'wrap_socket', 'sslwrap_simple']
__patched__ = [
'SSLSocket', 'wrap_socket', 'sslwrap_simple', 'create_default_context',
'_create_default_https_context']

_original_sslsocket = __ssl.SSLSocket
_original_sslcontext = __ssl.SSLContext
_original_create_default_context = __ssl.create_default_context


class GreenSSLSocket(_original_sslsocket):
Expand Down Expand Up @@ -357,11 +361,19 @@ def sslwrap_simple(sock, keyfile=None, certfile=None):


if hasattr(__ssl, 'SSLContext'):
@functools.wraps(__ssl.SSLContext.wrap_socket)
def _green_sslcontext_wrap_socket(self, sock, *a, **kw):
return GreenSSLSocket(sock, *a, _context=self, **kw)

# FIXME:
# * GreenSSLContext akin to GreenSSLSocket
# * make ssl.create_default_context() use modified SSLContext from globals as usual
__ssl.SSLContext.wrap_socket = _green_sslcontext_wrap_socket
class GreenSSLContext(_original_sslcontext):
__slots__ = ()
def wrap_socket(self, sock, *a, **kw):
return GreenSSLSocket(sock, *a, _context=self, **kw)

def green_create_default_context(*a, **kw):
# We can't just monkey-patch on the green version of `wrap_socket` on
# to SSLContext instances, but SSLContext.create_default_context does a
# bunch of work. Rather than re-implementing it all, just switch out
# the __class__ to get our `wrap_socket` implementation
context = _original_create_default_context(*a, **kw)
context.__class__ = GreenSSLContext
return context

create_default_context = green_create_default_context
_create_default_https_context = green_create_default_context

0 comments on commit e2e9be0

Please sign in to comment.