Skip to content

Commit 1973945

Browse files
authored
Fix for #65 (#73)
* 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.
1 parent 6b40c5c commit 1973945

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@ python:
66
- "3.4"
77
- "3.5"
88
- "3.6"
9-
# - "3.7-dev"
9+
# - "3.7-dev" # need to investigate the failure
1010
- "pypy"
11-
- "pypy3"
11+
# - "pypy3"
1212
install:
1313
- make develop
1414
script:

mocket/mocket.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@
2626
JSONDecodeError,
2727
)
2828

29+
try:
30+
from urllib3.contrib.pyopenssl import inject_into_urllib3, extract_from_urllib3
31+
pyopenssl_override = True
32+
except ImportError:
33+
pyopenssl_override = False
34+
35+
2936
__all__ = (
3037
'true_socket',
3138
'true_create_connection',
@@ -398,6 +405,9 @@ def enable(namespace=None, truesocket_recording_dir=None):
398405
'\x7f\x00\x00\x01',
399406
'utf-8'
400407
)
408+
if pyopenssl_override:
409+
# Take out the pyopenssl version - use the default implementation
410+
extract_from_urllib3()
401411

402412
@staticmethod
403413
def disable():
@@ -413,6 +423,9 @@ def disable():
413423
ssl.SSLContext = ssl.__dict__['SSLContext'] = true_ssl_context
414424
socket.inet_pton = socket.__dict__['inet_pton'] = true_inet_pton
415425
Mocket.reset()
426+
if pyopenssl_override:
427+
# Put the pyopenssl version back in place
428+
inject_into_urllib3()
416429

417430
@classmethod
418431
def get_namespace(cls):

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
python-magic
22
six
33
decorator
4-
hexdump
4+
hexdump
5+
urllib3

0 commit comments

Comments
 (0)