Commit 86531f8f authored by Jason Madden's avatar Jason Madden

Use the new ssl module on any python version that natively supports it. Fixes #702.

parent eba87aa7
...@@ -7,7 +7,11 @@ ...@@ -7,7 +7,11 @@
1.1rc3 (Unreleased) 1.1rc3 (Unreleased)
=================== ===================
- TBD - Support the new PEP 466 :mod:`ssl` interfaces on any Python 2
version that supplies them, not just on the versions it officially
shipped with. Some Linux distributions, including RedHat/CentOS and
Amazon have backported the changes to older versions. Reported in
:issue:`702`.
1.1rc2 (Dec 11, 2015) 1.1rc2 (Dec 11, 2015)
===================== =====================
......
...@@ -494,16 +494,15 @@ elif 'fromfd' in __implements__: ...@@ -494,16 +494,15 @@ elif 'fromfd' in __implements__:
__implements__.remove('fromfd') __implements__.remove('fromfd')
if hasattr(__socket__, 'ssl'): if hasattr(__socket__, 'ssl'):
from gevent.hub import PYGTE279
def ssl(sock, keyfile=None, certfile=None): def ssl(sock, keyfile=None, certfile=None):
# deprecated in 2.7.9 but still present # deprecated in 2.7.9 but still present;
if PYGTE279: # sometimes backported by distros. See ssl.py
from . import _sslgte279 from gevent import ssl as _sslmod
return _sslgte279.wrap_socket(sock, keyfile, certfile) # wrap_socket is 2.7.9/backport, sslwrap_simple is older. They take
else: # the same arguments.
from . import _ssl2 wrap = getattr(_sslmod, 'wrap_socket', None) or getattr(_sslmod, 'sslwrap_simple')
return _ssl2.sslwrap_simple(sock, keyfile, certfile) return wrap(sock, keyfile, certfile)
__implements__.append('ssl') __implements__.append('ssl')
__all__ = __implements__ + __extensions__ + __imports__ __all__ = __implements__ + __extensions__ + __imports__
...@@ -22,14 +22,7 @@ __all__ = ['getcurrent', ...@@ -22,14 +22,7 @@ __all__ = ['getcurrent',
'Hub', 'Hub',
'Waiter'] 'Waiter']
# Sniff Python > 2.7.9 for new SSL interfaces PY2 = sys.version_info[0] == 2
# If True, Python is greater than or equal to 2.7.9 (but not Python 3).
PYGTE279 = (
sys.version_info[0] == 2
and sys.version_info[1] >= 7
and sys.version_info[2] >= 9
)
PY3 = sys.version_info[0] >= 3 PY3 = sys.version_info[0] >= 3
PYPY = hasattr(sys, 'pypy_version_info') PYPY = hasattr(sys, 'pypy_version_info')
......
""" """
Secure Sockets Layer (SSL/TLS) module. Secure Sockets Layer (SSL/TLS) module.
""" """
from gevent.hub import PY3 from gevent.hub import PY2
from gevent.hub import PYGTE279
if PYGTE279: if PY2:
from gevent import _sslgte279 as _source if hasattr(__import__('ssl'), 'SSLContext'):
elif PY3: # It's not sufficient to check for >= 2.7.9; some distributions
from gevent import _ssl3 as _source # have backported most of PEP 466. Try to accommodate them. See Issue #702.
# We're just about to import ssl anyway so it's fine to import it here, just
# don't pollute the namespace
from gevent import _sslgte279 as _source
else:
from gevent import _ssl2 as _source
else: else:
from gevent import _ssl2 as _source # Py3
from gevent import _ssl3 as _source
for key in _source.__dict__: for key in _source.__dict__:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment