Created
December 30, 2014 13:11
-
-
Save zz/af7d9efa539999757950 to your computer and use it in GitHub Desktop.
gevent ssl.py patch for python 2.7.9
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Re-add sslwrap to Python 2.7.9 | |
import inspect | |
__ssl__ = __import__('ssl') | |
try: | |
_ssl = __ssl__._ssl | |
except AttributeError: | |
_ssl = __ssl__._ssl2 | |
def new_sslwrap(sock, server_side=False, keyfile=None, certfile=None, cert_reqs=__ssl__.CERT_NONE, ssl_version=__ssl__.PROTOCOL_SSLv23, ca_certs=None, ciphers=None): | |
context = __ssl__.SSLContext(ssl_version) | |
context.verify_mode = cert_reqs or __ssl__.CERT_NONE | |
if ca_certs: | |
context.load_verify_locations(ca_certs) | |
if certfile: | |
context.load_cert_chain(certfile, keyfile) | |
if ciphers: | |
context.set_ciphers(ciphers) | |
caller_self = inspect.currentframe().f_back.f_locals['self'] | |
return context._wrap_socket(sock, server_side=server_side, ssl_sock=caller_self) | |
if not hasattr(_ssl, 'sslwrap'): | |
_ssl.sslwrap = new_sslwrap |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment