Skip to content

Commit

Permalink
Fix for #65, thanks to the @jmcbailey patch at gabrielfalcao/HTTPrett…
Browse files Browse the repository at this point in the history
  • Loading branch information
mindflayer committed Aug 2, 2018
1 parent 6b40c5c commit ac0727e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions mocket/mocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,13 @@
JSONDecodeError,
)

try:
from requests.packages.urllib3.contrib.pyopenssl import inject_into_urllib3, extract_from_urllib3
pyopenssl_override = True
except ImportError:
pyopenssl_override = False


__all__ = (
'true_socket',
'true_create_connection',
Expand Down Expand Up @@ -398,6 +405,9 @@ def enable(namespace=None, truesocket_recording_dir=None):
'\x7f\x00\x00\x01',
'utf-8'
)
if pyopenssl_override:
# Take out the pyopenssl version - use the default implementation
extract_from_urllib3()

@staticmethod
def disable():
Expand All @@ -413,6 +423,9 @@ def disable():
ssl.SSLContext = ssl.__dict__['SSLContext'] = true_ssl_context
socket.inet_pton = socket.__dict__['inet_pton'] = true_inet_pton
Mocket.reset()
if pyopenssl_override:
# Put the pyopenssl version back in place
inject_into_urllib3()

@classmethod
def get_namespace(cls):
Expand Down

0 comments on commit ac0727e

Please sign in to comment.