Skip to content

Commit

Permalink
Support old Python 2.7 releases (#341)
Browse files Browse the repository at this point in the history
  • Loading branch information
hroncok authored and gabrielfalcao committed Aug 9, 2018
1 parent b0cb78c commit 7bd9afe
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions httpretty/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@
try: # pragma: no cover
import ssl
old_ssl_wrap_socket = ssl.wrap_socket
old_sslcontext_wrap_socket = ssl.SSLContext.wrap_socket
try:
old_sslcontext_wrap_socket = ssl.SSLContext.wrap_socket
except AttributeError:
pass
if not PY3:
old_sslwrap_simple = ssl.sslwrap_simple
old_sslsocket = ssl.SSLSocket
Expand Down Expand Up @@ -1397,7 +1400,10 @@ def disable(cls):
if ssl:
ssl.wrap_socket = old_ssl_wrap_socket
ssl.SSLSocket = old_sslsocket
ssl.SSLContext.wrap_socket = old_sslcontext_wrap_socket
try:
ssl.SSLContext.wrap_socket = old_sslcontext_wrap_socket
except AttributeError:
pass
ssl.__dict__['wrap_socket'] = old_ssl_wrap_socket
ssl.__dict__['SSLSocket'] = old_sslsocket

Expand Down Expand Up @@ -1488,7 +1494,10 @@ def enable(cls):
new_wrap = partial(fake_wrap_socket, old_ssl_wrap_socket)
ssl.wrap_socket = new_wrap
ssl.SSLSocket = FakeSSLSocket
ssl.SSLContext.wrap_socket = partial(fake_wrap_socket, old_sslcontext_wrap_socket)
try:
ssl.SSLContext.wrap_socket = partial(fake_wrap_socket, old_sslcontext_wrap_socket)
except AttributeError:
pass

ssl.__dict__['wrap_socket'] = new_wrap
ssl.__dict__['SSLSocket'] = FakeSSLSocket
Expand Down

0 comments on commit 7bd9afe

Please sign in to comment.