Add SSL support

This commit is contained in:
Brendan Molloy
2010-09-12 21:33:15 +10:00
parent b45c1e94f7
commit 4969c0d603
3 changed files with 18 additions and 6 deletions

9
irc.py
View File

@@ -64,15 +64,18 @@ class Bot(asynchat.async_chat):
self.__write(args, text)
except Exception, e: pass
def run(self, host, port=6667):
self.initiate_connect(host, port)
def run(self, host, port=6667, ssl=False):
self.initiate_connect(host, port, ssl)
def initiate_connect(self, host, port):
def initiate_connect(self, host, port, ssl):
if self.verbose:
message = 'Connecting to %s:%s...' % (host, port)
print >> sys.stderr, message,
self.create_socket(socket.AF_INET, socket.SOCK_STREAM)
self.connect((host, port))
if ssl:
import ssl
self.socket = ssl.wrap_socket(self.socket)
try: asyncore.loop()
except KeyboardInterrupt:
sys.exit()