Skip to content

Commit

Permalink
Fix for #65 (#73)
Browse files Browse the repository at this point in the history
* Fix for #65, thanks to the @jmcbailey patch at gabrielfalcao/HTTPretty#242.
* Improving the check, removing dependency of `requests` which is only acting as wrapper.
  • Loading branch information
mindflayer committed Aug 2, 2018
1 parent 6b40c5c commit 1973945
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ python:
- "3.4"
- "3.5"
- "3.6"
# - "3.7-dev"
# - "3.7-dev" # need to investigate the failure
- "pypy"
- "pypy3"
# - "pypy3"
install:
- make develop
script:
Expand Down
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 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
3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
python-magic
six
decorator
hexdump
hexdump
urllib3

0 comments on commit 1973945

Please sign in to comment.