From 96ea659030432e1860f01aafc9dbafc7cd2bba1c Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Thu, 9 Dec 2010 19:33:35 +0100 Subject: [PATCH 1/6] Add SSL support for Socket driver --- src/drivers/Socket.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/drivers/Socket.py b/src/drivers/Socket.py index 6db605a59..4cc2d6194 100644 --- a/src/drivers/Socket.py +++ b/src/drivers/Socket.py @@ -37,6 +37,10 @@ from __future__ import division import time import select import socket +try: + import ssl +except: + pass import supybot.log as log import supybot.conf as conf @@ -61,10 +65,11 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): 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() @@ -139,6 +144,12 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): 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 @@ -175,6 +186,9 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): 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: From a58e2705161cd35d50ce10817d33db25e4c720a7 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 12 Dec 2010 14:17:09 +0100 Subject: [PATCH 2/6] Fix issue with Pypy --- src/__init__.py | 2 +- src/drivers/Socket.py | 2 +- src/dynamicScope.py | 2 +- src/utils/__init__.py | 10 +++++----- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/__init__.py b/src/__init__.py index 3871a8940..4a1fdab74 100644 --- a/src/__init__.py +++ b/src/__init__.py @@ -34,7 +34,7 @@ import dynamicScope import supybot.utils as utils -__builtins__['format'] = utils.str.format +(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['format'] = utils.str.format class Author(object): def __init__(self, name=None, nick=None, email=None, **kwargs): diff --git a/src/drivers/Socket.py b/src/drivers/Socket.py index 4cc2d6194..d992792e0 100644 --- a/src/drivers/Socket.py +++ b/src/drivers/Socket.py @@ -144,7 +144,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): self.irc.feedMsg(msg) except socket.timeout: pass - except ssl.SSLError as e: + except ssl.SSLError, e: if e.args[0] == 'The read operation timed out': pass else: diff --git a/src/dynamicScope.py b/src/dynamicScope.py index 6b4675cad..e1fd97fd2 100644 --- a/src/dynamicScope.py +++ b/src/dynamicScope.py @@ -47,6 +47,6 @@ class DynamicScope(object): def __setattr__(self, name, value): self._getLocals(name)[name] = value -__builtins__['dynamic'] = DynamicScope() +(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['dynamic'] = DynamicScope() # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 7de7a425d..c32e23ef9 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -54,14 +54,14 @@ def force(x): return x() else: return x -__builtins__['force'] = force +(__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['force'] = force if sys.version_info < (2, 4, 0): def reversed(L): """Iterates through a sequence in reverse.""" for i in xrange(len(L) - 1, -1, -1): yield L[i] - __builtins__['reversed'] = reversed + (__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['reversed'] = reversed def sorted(iterable, cmp=None, key=None, reversed=False): L = list(iterable) @@ -74,7 +74,7 @@ if sys.version_info < (2, 4, 0): L.reverse() return L - __builtins__['sorted'] = sorted + (__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['sorted'] = sorted import operator def itemgetter(i): @@ -86,8 +86,8 @@ if sys.version_info < (2, 4, 0): operator.attrgetter = attrgetter import sets - __builtins__['set'] = sets.Set - __builtins__['frozenset'] = sets.ImmutableSet + (__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['set'] = sets.Set + (__builtins__ if isinstance(__builtins__, dict) else __builtins__.__dict__)['frozenset'] = sets.ImmutableSet import socket # Some socket modules don't have sslerror, so we'll just make it an error. From 49dfa69b91c37a11f588af6130c0a313283d712e Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 12 Dec 2010 14:33:36 +0100 Subject: [PATCH 3/6] Fix actually compatibility with non-ssl envirronments --- src/drivers/Socket.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/drivers/Socket.py b/src/drivers/Socket.py index d992792e0..d1ca4ee8a 100644 --- a/src/drivers/Socket.py +++ b/src/drivers/Socket.py @@ -39,8 +39,10 @@ import select import socket try: import ssl + SSLError = ssl.SSLError except: - pass + class SSLError(Exception): + pass import supybot.log as log import supybot.conf as conf @@ -144,7 +146,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): self.irc.feedMsg(msg) except socket.timeout: pass - except ssl.SSLError, e: + except SSLError, e: if e.args[0] == 'The read operation timed out': pass else: From b3ffbdf951caf8c5760b6b66817ad94b064a9483 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 12 Dec 2010 15:00:50 +0100 Subject: [PATCH 4/6] Fix localization issue --- locale/fr.po | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/locale/fr.po b/locale/fr.po index 519c6cde7..1bc929a46 100644 --- a/locale/fr.po +++ b/locale/fr.po @@ -39,7 +39,7 @@ msgstr "\"|\" avec rien ne le suivant. Je ne peux évidtemment pas faire un pipe #: callbacks.py:515 msgid "%s is not a valid %s." -msgstr "%s n'est pas un %s valide." +msgstr "%s n'est pas du type '%s'." #: callbacks.py:517 msgid "That's not a valid %s." From a739511b7329c290bc5164e71593ae5435d14dab Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 12 Dec 2010 15:03:13 +0100 Subject: [PATCH 5/6] Internationalize two strings in Config --- plugins/Config/messages.pot | 10 +++++++++- plugins/Config/plugin.py | 4 ++-- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/plugins/Config/messages.pot b/plugins/Config/messages.pot index bc578f015..91f5aa6d6 100644 --- a/plugins/Config/messages.pot +++ b/plugins/Config/messages.pot @@ -5,7 +5,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" -"POT-Creation-Date: 2010-10-16 12:34+CEST\n" +"POT-Creation-Date: 2010-12-12 15:02+CET\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -15,6 +15,14 @@ msgstr "" "Generated-By: pygettext.py 1.5\n" +#: plugin.py:103 +msgid "configuration variable" +msgstr "" + +#: plugin.py:109 +msgid "settable configuration variable" +msgstr "" + #: plugin.py:136 #, docstring msgid "" diff --git a/plugins/Config/plugin.py b/plugins/Config/plugin.py index 8f669dc76..d248f4bcd 100644 --- a/plugins/Config/plugin.py +++ b/plugins/Config/plugin.py @@ -100,13 +100,13 @@ def getConfigVar(irc, msg, args, state): state.args.append(group) del args[0] except registry.InvalidRegistryName, e: - state.errorInvalid('configuration variable', str(e)) + state.errorInvalid(_('configuration variable'), str(e)) addConverter('configVar', getConfigVar) def getSettableConfigVar(irc, msg, args, state): getConfigVar(irc, msg, args, state) if not hasattr(state.args[-1], 'set'): - state.errorInvalid('settable configuration variable', + state.errorInvalid(_('settable configuration variable'), state.args[-1]._name) addConverter('settableConfigVar', getSettableConfigVar) From 01018b902e5508d6f43daf5990235994bb55894c Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 12 Dec 2010 15:05:00 +0100 Subject: [PATCH 6/6] Localize the two new strings of Config in French --- plugins/Config/locale/fr.po | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/plugins/Config/locale/fr.po b/plugins/Config/locale/fr.po index 2627b7553..9eb4cb258 100644 --- a/plugins/Config/locale/fr.po +++ b/plugins/Config/locale/fr.po @@ -1,7 +1,7 @@ msgid "" msgstr "" "Project-Id-Version: Supybot-fr\n" -"POT-Creation-Date: 2010-10-16 12:34+CEST\n" +"POT-Creation-Date: 2010-12-12 15:02+CET\n" "PO-Revision-Date: \n" "Last-Translator: Valentin Lorentz \n" "Language-Team: Supybot-fr \n" @@ -13,6 +13,14 @@ msgstr "" "X-Poedit-Country: France\n" "X-Poedit-SourceCharset: ASCII\n" +#: plugin.py:103 +msgid "configuration variable" +msgstr "variable de configuration" + +#: plugin.py:109 +msgid "settable configuration variable" +msgstr "variable de configuration modifiable" + #: plugin.py:136 msgid "" "\n"