Handle versions of python that don't have ssl.PROTOCOL_TLS

This commit is contained in:
jesopo 2017-11-01 14:04:49 +00:00
parent d6134d71a3
commit 4779c885c8

View file

@ -1,6 +1,10 @@
import collections, socket, ssl, sys, time
import IRCChannel, IRCLineHandler, IRCUser
OUR_TLS_PROTOCOL = ssl.PROTOCOL_SSLv23
if hasattr(ssl, "PROTOCOL_TLS"):
OUR_TLS_PROTOCOL = ssl.PROTOCOL_TLS
class Server(object):
def __init__(self, id, hostname, port, password, ipv4, tls,
nickname, username, realname, bot):
@ -38,7 +42,7 @@ class Server(object):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEPORT, 1)
self.socket.settimeout(5.0)
if self.tls:
context = ssl.SSLContext(ssl.PROTOCOL_TLS)
context = ssl.SSLContext(OUR_TLS_PROTOCOL)
context.options |= ssl.OP_NO_SSLv2
context.options |= ssl.OP_NO_SSLv3
self.socket = context.wrap_socket(self.socket)