diff options
| author | Gabriel Falcão <gabriel@nacaolivre.org> | 2020-03-09 23:53:30 +0100 |
|---|---|---|
| committer | Gabriel Falcão <gabriel@nacaolivre.org> | 2020-03-09 23:53:30 +0100 |
| commit | c85942185ab1fe96a78f4bf79fe3e2cca3a5878b (patch) | |
| tree | c3d9b6eba3e6d79358a56e99b0de3b24572a99f3 | |
| parent | 41fc94787f7d741faab5dd92f451fe240900dff8 (diff) | |
| parent | 37d3aa2848f888ba134e74badecce5ef62f5ad82 (diff) | |
| download | httpretty-fix_ndg_break.tar.gz | |
Merge remote-tracking branch 'ndg/fix_ndg_break' into fix_ndg_breakfix_ndg_break
| -rw-r--r-- | httpretty/__init__.py | 3 | ||||
| -rw-r--r-- | httpretty/core.py | 18 |
2 files changed, 20 insertions, 1 deletions
diff --git a/httpretty/__init__.py b/httpretty/__init__.py index 20cfec8..e3b3f20 100644 --- a/httpretty/__init__.py +++ b/httpretty/__init__.py @@ -25,7 +25,10 @@ # OTHER DEALINGS IN THE SOFTWARE. # flake8: noqa + from . import core + +from .core import httpretty, httprettified, EmptyRequestHeaders from .errors import HTTPrettyError, UnmockedError from .version import version diff --git a/httpretty/core.py b/httpretty/core.py index bc1c16c..2af4884 100644 --- a/httpretty/core.py +++ b/httpretty/core.py @@ -112,6 +112,13 @@ try: # pragma: no cover except ImportError: # pragma: no cover ssl = None +# used to handle error caused by ndg-httpsclient +try: + from requests.packages.urllib3.contrib.pyopenssl import inject_into_urllib3, extract_from_urllib3 + pyopenssl_override = True +except: + pyopenssl_override = False + try: import requests.packages.urllib3.connection as requests_urllib3_connection @@ -1341,7 +1348,7 @@ class httpretty(HttpBaseClass): :param match_querystring: bool - whether to take the querystring into account when matching an URL :param headers: headers to be added to the response - .. warning:: When using a port in the request, add a trailing slash if no path is provided otherwise Httpretty will not catch the request. Ex: ``httpretty.register_uri(httpretty.GET, 'http://fakeuri.com:8080/', body='{"hello":"world"}')`` + .. warning:: When using a port in the request, add a trailing slash if no path is provided otherwise Httpretty will not catch the request. Ex: ``httpretty.register_uri(httpretty.GET, 'http://fakeuri.com:8080/', body='{"hello":"world"}')`` """ uri_is_string = isinstance(uri, basestring) @@ -1463,12 +1470,17 @@ class httpretty(HttpBaseClass): ssl.sslwrap_simple = old_sslwrap_simple ssl.__dict__['sslwrap_simple'] = old_sslwrap_simple + if requests_urllib3_connection is not None: requests_urllib3_connection.ssl_wrap_socket = \ old_requests_ssl_wrap_socket requests_urllib3_connection.__dict__['ssl_wrap_socket'] = \ old_requests_ssl_wrap_socket + if pyopenssl_override: + # Put the pyopenssl version back in place + inject_into_urllib3() + @classmethod def is_enabled(cls): """Check if HTTPretty is enabled @@ -1565,6 +1577,10 @@ class httpretty(HttpBaseClass): requests_urllib3_connection.ssl_wrap_socket = new_wrap requests_urllib3_connection.__dict__['ssl_wrap_socket'] = new_wrap + if pyopenssl_override: + # Take out the pyopenssl version - use the default implementation + extract_from_urllib3() + class httprettized(object): """`context-manager <https://docs.python.org/3/reference/datamodel.html#context-managers>`_ for enabling HTTPretty. |
