Fix import ssl may fail under some Python installs

It's only required for certain proxy configurations, so we
don't want it to raise ImportError while the user imports
our library.
This commit is contained in:
Lonami Exo 2019-10-31 19:20:18 +01:00
parent 6850903d17
commit 7e346180d7

View File

@ -1,9 +1,13 @@
import abc
import asyncio
import socket
import ssl as ssl_mod
import sys
try:
import ssl as ssl_mod
except ImportError:
ssl_mod = None
from ...errors import InvalidChecksumError
from ... import helpers
@ -68,6 +72,12 @@ class Connection(abc.ABC):
loop=self._loop
)
if ssl:
if ssl_mod is None:
raise RuntimeError(
'Cannot use proxy that requires SSL'
'without the SSL module being available'
)
s.settimeout(timeout)
s = ssl_mod.wrap_socket(
s,