mirror of
https://github.com/Mikaela/Limnoria.git
synced 2024-11-27 13:19:24 +01:00
Add SSL support for Socket driver
This commit is contained in:
parent
c5974046c6
commit
96ea659030
@ -37,6 +37,10 @@ from __future__ import division
|
|||||||
import time
|
import time
|
||||||
import select
|
import select
|
||||||
import socket
|
import socket
|
||||||
|
try:
|
||||||
|
import ssl
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
import supybot.log as log
|
import supybot.log as log
|
||||||
import supybot.conf as conf
|
import supybot.conf as conf
|
||||||
@ -61,10 +65,11 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
|||||||
self.writeCheckTime = None
|
self.writeCheckTime = None
|
||||||
self.nextReconnectTime = None
|
self.nextReconnectTime = None
|
||||||
self.resetDelay()
|
self.resetDelay()
|
||||||
# Only connect to non-SSL servers
|
if self.networkGroup.get('ssl').value and not globals().has_key('ssl'):
|
||||||
if self.networkGroup.get('ssl').value:
|
|
||||||
drivers.log.error('The Socket driver can not connect to SSL '
|
drivers.log.error('The Socket driver can not connect to SSL '
|
||||||
'servers. Try the Twisted driver instead.')
|
'servers for your Python version. Try the '
|
||||||
|
'Twisted driver instead, or install a Python'
|
||||||
|
'version that supports SSL (2.6 and greater).')
|
||||||
else:
|
else:
|
||||||
self.connect()
|
self.connect()
|
||||||
|
|
||||||
@ -139,6 +144,12 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
|||||||
self.irc.feedMsg(msg)
|
self.irc.feedMsg(msg)
|
||||||
except socket.timeout:
|
except socket.timeout:
|
||||||
pass
|
pass
|
||||||
|
except ssl.SSLError as e:
|
||||||
|
if e.args[0] == 'The read operation timed out':
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
self._handleSocketError(e)
|
||||||
|
return
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
self._handleSocketError(e)
|
self._handleSocketError(e)
|
||||||
return
|
return
|
||||||
@ -175,6 +186,9 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
|
|||||||
try:
|
try:
|
||||||
self.conn.connect(server)
|
self.conn.connect(server)
|
||||||
self.conn.settimeout(conf.supybot.drivers.poll())
|
self.conn.settimeout(conf.supybot.drivers.poll())
|
||||||
|
if getattr(conf.supybot.networks, self.irc.network).ssl():
|
||||||
|
assert globals().has_key('ssl')
|
||||||
|
self.conn = ssl.wrap_socket(self.conn)
|
||||||
self.connected = True
|
self.connected = True
|
||||||
self.resetDelay()
|
self.resetDelay()
|
||||||
except socket.error, e:
|
except socket.error, e:
|
||||||
|
Loading…
Reference in New Issue
Block a user