Skip to content

Commit

Permalink
Add SSL support for Socket driver
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Dec 9, 2010
1 parent c597404 commit 96ea659
Showing 1 changed file with 17 additions and 3 deletions.
20 changes: 17 additions & 3 deletions src/drivers/Socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
import time
import select
import socket
try:
import ssl
except:
pass

import supybot.log as log
import supybot.conf as conf
Expand All @@ -61,10 +65,11 @@ def __init__(self, irc):
self.writeCheckTime = None
self.nextReconnectTime = None
self.resetDelay()
# Only connect to non-SSL servers
if self.networkGroup.get('ssl').value:
if self.networkGroup.get('ssl').value and not globals().has_key('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:
self.connect()

Expand Down Expand Up @@ -139,6 +144,12 @@ def run(self):
self.irc.feedMsg(msg)
except socket.timeout:
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:
self._handleSocketError(e)
return
Expand Down Expand Up @@ -175,6 +186,9 @@ def reconnect(self, reset=True):
try:
self.conn.connect(server)
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.resetDelay()
except socket.error, e:
Expand Down

0 comments on commit 96ea659

Please sign in to comment.