Skip to content
This repository was archived by the owner on Apr 14, 2022. It is now read-only.

Rename inject_into_urllib3/extract_from_urllib3 #171

Merged
merged 2 commits into from
Nov 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions src/urllib3/contrib/pyopenssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
pip install pyopenssl cryptography idna

To activate certificate checking, call
:func:`~urllib3.contrib.pyopenssl.inject_into_urllib3` from your Python code
:func:`~urllib3.contrib.pyopenssl.inject_into_hip` from your Python code
before you begin making HTTP requests. This can be done in a ``sitecustomize``
module, or at any other time before your application begins using ``urllib3``,
like this::

try:
import urllib3.contrib.pyopenssl
urllib3.contrib.pyopenssl.inject_into_urllib3()
urllib3.contrib.pyopenssl.inject_into_hip()
except ImportError:
pass

Expand Down Expand Up @@ -73,7 +73,7 @@ class UnsupportedExtension(Exception):
from .. import util


__all__ = ["inject_into_urllib3", "extract_from_urllib3"]
__all__ = ["inject_into_hip", "extract_from_hip"]

# SNI always works.
HAS_SNI = True
Expand Down Expand Up @@ -114,7 +114,7 @@ class UnsupportedExtension(Exception):
log = logging.getLogger(__name__)


def inject_into_urllib3():
def inject_into_hip():
"Monkey-patch urllib3 with PyOpenSSL-backed SSL-support."

_validate_dependencies_met()
Expand All @@ -131,8 +131,8 @@ def inject_into_urllib3():
util.ssl_.SSLWantWriteError = OpenSSL.SSL.WantWriteError


def extract_from_urllib3():
"Undo monkey-patching by :func:`inject_into_urllib3`."
def extract_from_hip():
"Undo monkey-patching by :func:`inject_into_hip`."

util.SSLContext = orig_util_SSLContext
util.ssl_.SSLContext = orig_util_SSLContext
Expand Down
10 changes: 5 additions & 5 deletions src/urllib3/contrib/securetransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
To use this module, simply import and inject it::

import urllib3.contrib.securetransport
urllib3.contrib.securetransport.inject_into_urllib3()
urllib3.contrib.securetransport.inject_into_hip()

Happy TLSing!

Expand Down Expand Up @@ -76,7 +76,7 @@
_fileobject = None
from ..packages.backports.makefile import backport_makefile

__all__ = ["inject_into_urllib3", "extract_from_urllib3"]
__all__ = ["inject_into_hip", "extract_from_hip"]

# SNI always works
HAS_SNI = True
Expand Down Expand Up @@ -177,7 +177,7 @@
)


def inject_into_urllib3():
def inject_into_hip():
"""
Monkey-patch urllib3 with SecureTransport-backed SSL-support.
"""
Expand All @@ -189,9 +189,9 @@ def inject_into_urllib3():
util.ssl_.IS_SECURETRANSPORT = True


def extract_from_urllib3():
def extract_from_hip():
"""
Undo monkey-patching by :func:`inject_into_urllib3`.
Undo monkey-patching by :func:`inject_into_hip`.
"""
util.SSLContext = orig_util_SSLContext
util.ssl_.SSLContext = orig_util_SSLContext
Expand Down
11 changes: 5 additions & 6 deletions test/contrib/test_pyopenssl.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
import pytest

pytestmark = pytest.mark.skip(
"inject_into_urllib3/extract_from_urllib3 appear to break the standard "
"library SSL tests"
"inject_into_hip/extract_from_hip appear to break the standard library SSL tests"
)

try:
Expand All @@ -19,18 +18,18 @@

def setup_module():
try:
from urllib3.contrib.pyopenssl import inject_into_urllib3
from urllib3.contrib.pyopenssl import inject_into_hip

inject_into_urllib3()
inject_into_hip()
except ImportError as e:
pytest.skip("Could not import PyOpenSSL: %r" % e)


def teardown_module():
try:
from urllib3.contrib.pyopenssl import extract_from_urllib3
from urllib3.contrib.pyopenssl import extract_from_hip

extract_from_urllib3()
extract_from_hip()
except ImportError:
pass

Expand Down
24 changes: 12 additions & 12 deletions test/contrib/test_pyopenssl_dependencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,32 +4,32 @@
from mock import patch, Mock

try:
from urllib3.contrib.pyopenssl import inject_into_urllib3, extract_from_urllib3
from urllib3.contrib.pyopenssl import inject_into_hip, extract_from_hip
except ImportError:
pass


def setup_module():
try:
from urllib3.contrib.pyopenssl import inject_into_urllib3
from urllib3.contrib.pyopenssl import inject_into_hip

inject_into_urllib3()
inject_into_hip()
except ImportError as e:
pytest.skip("Could not import PyOpenSSL: %r" % e)


def teardown_module():
try:
from urllib3.contrib.pyopenssl import extract_from_urllib3
from urllib3.contrib.pyopenssl import extract_from_hip

extract_from_urllib3()
extract_from_hip()
except ImportError:
pass


class TestPyOpenSSLInjection(object):
"""
Tests for error handling in pyopenssl's 'inject_into urllib3'
Tests for error handling in pyopenssl's 'inject_into_hip'
"""

def test_inject_validate_fail_cryptography(self):
Expand All @@ -40,12 +40,12 @@ def test_inject_validate_fail_cryptography(self):
with patch("cryptography.x509.extensions.Extensions") as mock:
del mock.get_extension_for_class
with pytest.raises(ImportError):
inject_into_urllib3()
inject_into_hip()
finally:
# `inject_into_urllib3` is not supposed to succeed.
# `inject_into_hip` is not supposed to succeed.
# If it does, this test should fail, but we need to
# clean up so that subsequent tests are unaffected.
extract_from_urllib3()
extract_from_hip()

def test_inject_validate_fail_pyopenssl(self):
"""
Expand All @@ -56,9 +56,9 @@ def test_inject_validate_fail_pyopenssl(self):
del return_val._x509
with patch("OpenSSL.crypto.X509", return_value=return_val):
with pytest.raises(ImportError):
inject_into_urllib3()
inject_into_hip()
finally:
# `inject_into_urllib3` is not supposed to succeed.
# `inject_into_hip` is not supposed to succeed.
# If it does, this test should fail, but we need to
# clean up so that subsequent tests are unaffected.
extract_from_urllib3()
extract_from_hip()
8 changes: 4 additions & 4 deletions test/contrib/test_securetransport.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@

def setup_module():
try:
from urllib3.contrib.securetransport import inject_into_urllib3
from urllib3.contrib.securetransport import inject_into_hip

inject_into_urllib3()
inject_into_hip()
except ImportError as e:
pytest.skip("Could not import SecureTransport: %r" % e)


def teardown_module():
try:
from urllib3.contrib.securetransport import extract_from_urllib3
from urllib3.contrib.securetransport import extract_from_hip

extract_from_urllib3()
extract_from_hip()
except ImportError:
pass

Expand Down