Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inject pyopenssl into urllib3 only when necessary #292

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
29 changes: 27 additions & 2 deletions src/etcd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,34 @@ def handle(cls, payload):

# Attempt to enable urllib3's SNI support, if possible
# Blatantly copied from requests.
def _check_cryptography(cryptography_version):
import warnings

# cryptography < 1.3.4
try:
cryptography_version = list(map(int, cryptography_version.split(".")))
except ValueError:
return

if cryptography_version < [1, 3, 4]:
warning = "Old version of cryptography ({}) may cause slowdown.".format(
cryptography_version
)
warnings.warn(warning, RequestsDependencyWarning)

try:
from urllib3.contrib import pyopenssl
try:
import ssl
except ImportError:
ssl = None

if not getattr(ssl, "HAS_SNI", False):
from urllib3.contrib import pyopenssl

pyopenssl.inject_into_urllib3()

from cryptography import __version__ as cryptography_version

pyopenssl.inject_into_urllib3()
_check_cryptography(cryptography_version)
except ImportError:
pass