From bb7db3ab213d7be919d19b839f834c97d345cb56 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 20 Jan 2014 15:49:15 +0100 Subject: [PATCH] Continue accelerating the 2to3 step (remove fix_except). --- plugins/Alias/plugin.py | 6 +++--- plugins/ChannelLogger/plugin.py | 2 +- plugins/ChannelStats/plugin.py | 4 ++-- plugins/Conditional/plugin.py | 2 +- plugins/Config/plugin.py | 4 ++-- plugins/Dict/plugin.py | 8 ++++---- plugins/Format/plugin.py | 2 +- plugins/Internet/plugin.py | 4 ++-- plugins/Later/plugin.py | 2 +- plugins/Math/plugin.py | 10 +++++----- plugins/MessageParser/plugin.py | 4 ++-- plugins/Misc/plugin.py | 2 +- plugins/MoobotFactoids/plugin.py | 6 +++--- plugins/News/plugin.py | 4 ++-- plugins/Owner/plugin.py | 18 +++++++++--------- plugins/RSS/plugin.py | 2 +- plugins/Scheduler/plugin.py | 10 +++++----- plugins/ShrinkUrl/plugin.py | 16 ++++++++-------- plugins/String/plugin.py | 2 +- plugins/Topic/plugin.py | 8 ++++---- plugins/Unix/plugin.py | 12 ++++++------ plugins/User/plugin.py | 4 ++-- plugins/Utilities/plugin.py | 2 +- plugins/Web/plugin.py | 2 +- plugins/__init__.py | 10 +++++----- setup.py | 2 +- src/callbacks.py | 18 +++++++++--------- src/commands.py | 16 ++++++++-------- src/dbi.py | 6 +++--- src/drivers/Socket.py | 10 +++++----- src/ircdb.py | 24 ++++++++++++------------ src/irclib.py | 2 +- src/log.py | 8 ++++---- src/plugin.py | 6 +++--- src/registry.py | 8 ++++---- src/schedule.py | 2 +- src/test.py | 2 +- src/utils/gen.py | 2 +- src/utils/str.py | 2 +- src/utils/transaction.py | 2 +- src/utils/web.py | 14 +++++++------- src/world.py | 2 +- 42 files changed, 136 insertions(+), 136 deletions(-) diff --git a/plugins/Alias/plugin.py b/plugins/Alias/plugin.py index 6d818a0ae..136259f63 100644 --- a/plugins/Alias/plugin.py +++ b/plugins/Alias/plugin.py @@ -272,7 +272,7 @@ class Alias(callbacks.Plugin): for (alias, (command, locked, _)) in self.aliases.items(): try: self.addAlias(irc, alias, command, locked) - except Exception, e: + except Exception as e: self.log.exception('Exception when trying to add alias %s. ' 'Removing from the Alias database.', alias) del self.aliases[alias] @@ -397,7 +397,7 @@ class Alias(callbacks.Plugin): self.log.info('Adding alias %q for %q (from %s)', name, alias, msg.prefix) irc.replySuccess() - except AliasError, e: + except AliasError as e: irc.error(str(e)) add = wrap(add, ['commandName', 'text']) @@ -411,7 +411,7 @@ class Alias(callbacks.Plugin): self.removeAlias(name) self.log.info('Removing alias %q (from %s)', name, msg.prefix) irc.replySuccess() - except AliasError, e: + except AliasError as e: irc.error(str(e)) remove = wrap(remove, ['commandName']) diff --git a/plugins/ChannelLogger/plugin.py b/plugins/ChannelLogger/plugin.py index 43d9a1175..5087e6389 100644 --- a/plugins/ChannelLogger/plugin.py +++ b/plugins/ChannelLogger/plugin.py @@ -98,7 +98,7 @@ class ChannelLogger(callbacks.Plugin): for log in self._logs(): try: log.flush() - except ValueError, e: + except ValueError as e: if e.args[0] != 'I/O operation on a closed file': self.log.exception('Odd exception:') diff --git a/plugins/ChannelStats/plugin.py b/plugins/ChannelStats/plugin.py index 1ea05eacd..e2b3e6fec 100644 --- a/plugins/ChannelStats/plugin.py +++ b/plugins/ChannelStats/plugin.py @@ -336,9 +336,9 @@ class ChannelStats(callbacks.Plugin): v = eval(expr, e, e) except ZeroDivisionError: v = float('inf') - except NameError, e: + except NameError as e: irc.errorInvalid(_('stat variable'), str(e).split()[1]) - except Exception, e: + except Exception as e: irc.error(utils.exnToString(e), Raise=True) if id == 0: users.append((v, irc.nick)) diff --git a/plugins/Conditional/plugin.py b/plugins/Conditional/plugin.py index e724fea79..ecba0ff01 100644 --- a/plugins/Conditional/plugin.py +++ b/plugins/Conditional/plugin.py @@ -65,7 +65,7 @@ class Conditional(callbacks.Plugin): tokens = callbacks.tokenize(command) try: self.Proxy(irc.irc, msg, tokens) - except Exception, e: + except Exception as e: self.log.exception('Uncaught exception in requested function:') @internationalizeDocstring diff --git a/plugins/Config/plugin.py b/plugins/Config/plugin.py index ce88f381a..8c4d11ab9 100644 --- a/plugins/Config/plugin.py +++ b/plugins/Config/plugin.py @@ -99,7 +99,7 @@ def getConfigVar(irc, msg, args, state): group = getWrapper(name) state.args.append(group) del args[0] - except registry.InvalidRegistryName, e: + except registry.InvalidRegistryName as e: state.errorInvalid(_('configuration variable'), str(e)) addConverter('configVar', getConfigVar) @@ -114,7 +114,7 @@ class Config(callbacks.Plugin): def callCommand(self, command, irc, msg, *args, **kwargs): try: super(Config, self).callCommand(command, irc, msg, *args, **kwargs) - except registry.InvalidRegistryValue, e: + except registry.InvalidRegistryValue as e: irc.error(str(e)) def _list(self, group): diff --git a/plugins/Dict/plugin.py b/plugins/Dict/plugin.py index 008b32f5d..3eed6de64 100644 --- a/plugins/Dict/plugin.py +++ b/plugins/Dict/plugin.py @@ -56,7 +56,7 @@ class Dict(callbacks.Plugin): dbs = list(conn.getdbdescs().keys()) dbs.sort() irc.reply(format('%L', dbs)) - except socket.error, e: + except socket.error as e: irc.error(utils.web.strError(e)) dictionaries = wrap(dictionaries) @@ -71,7 +71,7 @@ class Dict(callbacks.Plugin): conn = dictclient.Connection(server) dbs = conn.getdbdescs().keys() irc.reply(utils.iter.choice(dbs)) - except socket.error, e: + except socket.error as e: irc.error(utils.web.strError(e)) random = wrap(random) @@ -85,7 +85,7 @@ class Dict(callbacks.Plugin): try: server = conf.supybot.plugins.Dict.server() conn = dictclient.Connection(server) - except socket.error, e: + except socket.error as e: irc.error(utils.web.strError(e), Raise=True) dbs = set(conn.getdbdescs()) if words[0] in dbs: @@ -139,7 +139,7 @@ class Dict(callbacks.Plugin): try: server = conf.supybot.plugins.Dict.server() conn = dictclient.Connection(server) - except socket.error, e: + except socket.error as e: irc.error(utils.web.strError(e), Raise=True) dictionary = 'moby-thes' diff --git a/plugins/Format/plugin.py b/plugins/Format/plugin.py index f18968b28..72b5ceecf 100644 --- a/plugins/Format/plugin.py +++ b/plugins/Format/plugin.py @@ -208,7 +208,7 @@ class Format(callbacks.Plugin): try: s %= tuple(args) irc.reply(s) - except TypeError, e: + except TypeError as e: self.log.debug(utils.exnToString(e)) irc.error(_('Not enough arguments for the format string.'), Raise=True) diff --git a/plugins/Internet/plugin.py b/plugins/Internet/plugin.py index 8128b4b61..2e09a1623 100644 --- a/plugins/Internet/plugin.py +++ b/plugins/Internet/plugin.py @@ -82,7 +82,7 @@ class Internet(callbacks.Plugin): try: sock = utils.net.getSocket('%s.whois-servers.net' % usertld) sock.connect(('%s.whois-servers.net' % usertld, 43)) - except socket.error, e: + except socket.error as e: irc.error(str(e)) return sock.settimeout(5) @@ -130,7 +130,7 @@ class Internet(callbacks.Plugin): status = 'unknown' try: t = telnetlib.Telnet('whois.pir.org', 43) - except socket.error, e: + except socket.error as e: irc.error(str(e)) return t.write(b'registrar ') diff --git a/plugins/Later/plugin.py b/plugins/Later/plugin.py index 8bd00687b..6bc2cb049 100644 --- a/plugins/Later/plugin.py +++ b/plugins/Later/plugin.py @@ -69,7 +69,7 @@ class Later(callbacks.Plugin): def _openNotes(self): try: fd = open(self.filename) - except EnvironmentError, e: + except EnvironmentError as e: self.log.warning('Couldn\'t open %s: %s', self.filename, e) return reader = csv.reader(fd) diff --git a/plugins/Math/plugin.py b/plugins/Math/plugin.py index 8877e2dfc..d23566b29 100644 --- a/plugins/Math/plugin.py +++ b/plugins/Math/plugin.py @@ -219,9 +219,9 @@ class Math(callbacks.Plugin): irc.error(_('The answer exceeded %s or so.') % maxFloat) except TypeError: irc.error(_('Something in there wasn\'t a valid number.')) - except NameError, e: + except NameError as e: irc.error(_('%s is not a defined function.') % str(e).split()[1]) - except Exception, e: + except Exception as e: irc.error(str(e)) calc = wrap(calc, ['text']) @@ -253,9 +253,9 @@ class Math(callbacks.Plugin): irc.error(_('The answer exceeded %s or so.') % maxFloat) except TypeError: irc.error(_('Something in there wasn\'t a valid number.')) - except NameError, e: + except NameError as e: irc.error(_('%s is not a defined function.') % str(e).split()[1]) - except Exception, e: + except Exception as e: irc.error(utils.exnToString(e)) icalc = wrap(icalc, [('checkCapability', 'trusted'), 'text']) @@ -337,7 +337,7 @@ class Math(callbacks.Plugin): newNum = round(newNum, digits + 1 + zeros) newNum = self._floatToString(newNum) irc.reply(str(newNum)) - except convertcore.UnitDataError, ude: + except convertcore.UnitDataError as ude: irc.error(str(ude)) convert = wrap(convert, [optional('float', 1.0),'something','to','text']) diff --git a/plugins/MessageParser/plugin.py b/plugins/MessageParser/plugin.py index 66382358a..0ad7160aa 100644 --- a/plugins/MessageParser/plugin.py +++ b/plugins/MessageParser/plugin.py @@ -128,7 +128,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): tokens = callbacks.tokenize(command) try: self.Proxy(irc.irc, msg, tokens) - except Exception, e: + except Exception as e: log.exception('Uncaught exception in function called by MessageParser:') def _checkManageCapabilities(self, irc, msg, channel): @@ -213,7 +213,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler): if not locked: try: re.compile(regexp) - except Exception, e: + except Exception as e: irc.error(_('Invalid python regexp: %s') % (e,)) return if ircdb.users.hasUser(msg.prefix): diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index 781098d59..e2be33e8c 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -320,7 +320,7 @@ class Misc(callbacks.Plugin): newest = _('The newest versions available online are %s.') % \ ', '.join([_('%s (in %s)') % (y,x) for x,y in versions.items()]) - except utils.web.Error, e: + except utils.web.Error as e: self.log.info('Couldn\'t get website version: %s', e) newest = _('I couldn\'t fetch the newest version ' 'from the Limnoria repository.') diff --git a/plugins/MoobotFactoids/plugin.py b/plugins/MoobotFactoids/plugin.py index 32026c016..e1f8bb5cc 100755 --- a/plugins/MoobotFactoids/plugin.py +++ b/plugins/MoobotFactoids/plugin.py @@ -387,7 +387,7 @@ class MoobotFactoids(callbacks.Plugin): id = self._getUserId(irc, msg.prefix) try: (key, fact) = self._getKeyAndFactoid(tokens) - except ValueError, e: + except ValueError as e: irc.error(str(e), Raise=True) # Check and make sure it's not in the DB already if self.db.getFactoid(channel, key): @@ -406,7 +406,7 @@ class MoobotFactoids(callbacks.Plugin): # It's fair game if we get to here try: r = utils.str.perlReToReplacer(regexp) - except ValueError, e: + except ValueError as e: irc.errorInvalid('regexp', regexp, Raise=True) fact = fact[0] new_fact = r(fact) @@ -436,7 +436,7 @@ class MoobotFactoids(callbacks.Plugin): del tokens[0] # remove the "no," try: (key, fact) = self._getKeyAndFactoid(tokens) - except ValueError, e: + except ValueError as e: irc.error(str(e), Raise=True) _ = self._getFactoid(irc, channel, key) self._checkNotLocked(irc, channel, key) diff --git a/plugins/News/plugin.py b/plugins/News/plugin.py index 5a9d5d95d..599225fd7 100644 --- a/plugins/News/plugin.py +++ b/plugins/News/plugin.py @@ -153,7 +153,7 @@ class News(callbacks.Plugin): try: record = self.db.get(channel, id) irc.reply(str(record)) - except dbi.NoRecordError, id: + except dbi.NoRecordError as id: irc.errorInvalid(_('news item id'), id) news = wrap(news, ['channeldb', additional('positiveInt')]) @@ -199,7 +199,7 @@ class News(callbacks.Plugin): try: record = self.db.getOld(channel, id) irc.reply(str(record)) - except dbi.NoRecordError, id: + except dbi.NoRecordError as id: irc.errorInvalid(_('news item id'), id) else: try: diff --git a/plugins/Owner/plugin.py b/plugins/Owner/plugin.py index f4b285593..9983e3e95 100644 --- a/plugins/Owner/plugin.py +++ b/plugins/Owner/plugin.py @@ -142,9 +142,9 @@ class Owner(callbacks.Plugin): for network in conf.supybot.networks(): try: self._connect(network) - except socket.error, e: + except socket.error as e: self.log.error('Could not connect to %s: %s.', network, e) - except Exception, e: + except Exception as e: self.log.exception('Exception connecting to %s:', network) self.log.error('Could not connect to %s: %s.', network, e) @@ -209,21 +209,21 @@ class Owner(callbacks.Plugin): m = plugin.loadPluginModule(name, ignoreDeprecation=True) plugin.loadPluginClass(irc, m) - except callbacks.Error, e: + except callbacks.Error as e: # This is just an error message. log.warning(str(e)) - except (plugins.NoSuitableDatabase, ImportError), e: + except (plugins.NoSuitableDatabase, ImportError) as e: s = 'Failed to load %s: %s' % (name, e) if not s.endswith('.'): s += '.' log.warning(s) - except Exception, e: + except Exception as e: log.exception('Failed to load %s:', name) else: # Let's import the module so configuration is preserved. try: _ = plugin.loadPluginModule(name) - except Exception, e: + except Exception as e: log.debug('Attempted to load %s to preserve its ' 'configuration, but load failed: %s', name, e) @@ -267,7 +267,7 @@ class Owner(callbacks.Plugin): try: tokens = callbacks.tokenize(s, channel=msg.args[0]) self.Proxy(irc, msg, tokens) - except SyntaxError, e: + except SyntaxError as e: irc.queueMsg(callbacks.error(msg, str(e))) def logmark(self, irc, msg, args, text): @@ -340,7 +340,7 @@ class Owner(callbacks.Plugin): """ try: m = ircmsgs.IrcMsg(s) - except Exception, e: + except Exception as e: irc.error(utils.exnToString(e)) else: irc.queueMsg(m) @@ -435,7 +435,7 @@ class Owner(callbacks.Plugin): irc.error('%s is deprecated. Use --deprecated ' 'to force it to load.' % name.capitalize()) return - except ImportError, e: + except ImportError as e: if str(e).endswith(' ' + name): irc.error('No plugin named %s exists.' % utils.str.dqrepr(name)) else: diff --git a/plugins/RSS/plugin.py b/plugins/RSS/plugin.py index 5238ce865..7807f4b70 100644 --- a/plugins/RSS/plugin.py +++ b/plugins/RSS/plugin.py @@ -289,7 +289,7 @@ class RSS(callbacks.Plugin): raise callbacks.Error('Invalid (unparsable) RSS feed.') except socket.timeout: return error('Timeout downloading feed.') - except Exception, e: + except Exception as e: # These seem mostly harmless. We'll need reports of a # kind that isn't. self.log.debug('Allowing bozo_exception %r through.', e) diff --git a/plugins/Scheduler/plugin.py b/plugins/Scheduler/plugin.py index 226f12e45..28d34b631 100644 --- a/plugins/Scheduler/plugin.py +++ b/plugins/Scheduler/plugin.py @@ -58,12 +58,12 @@ class Scheduler(callbacks.Plugin): pkl = open(filename, 'rb') try: eventdict = pickle.load(pkl) - except Exception, e: + except Exception as e: self.log.debug('Unable to load pickled data: %s', e) return finally: pkl.close() - except IOError, e: + except IOError as e: self.log.debug('Unable to open pickle file: %s', e) return for name, event in eventdict.iteritems(): @@ -81,7 +81,7 @@ class Scheduler(callbacks.Plugin): elif event['type'] == 'repeat': # repeating event self._repeat(ircobj, event['msg'], name, event['time'], event['command'], False) - except AssertionError, e: + except AssertionError as e: if str(e) == 'An event with the same name has already been scheduled.': # we must be reloading the plugin, event is still scheduled self.log.info('Event %s already exists, adding to dict.' % (name,)) @@ -95,11 +95,11 @@ class Scheduler(callbacks.Plugin): pkl = os.fdopen(pklfd, 'wb') try: pickle.dump(self.events, pkl) - except Exception, e: + except Exception as e: self.log.warning('Unable to store pickled data: %s', e) pkl.close() shutil.move(tempfn, filename) - except (IOError, shutil.Error), e: + except (IOError, shutil.Error) as e: self.log.warning('File error: %s', e) def die(self): diff --git a/plugins/ShrinkUrl/plugin.py b/plugins/ShrinkUrl/plugin.py index 26772e5ec..f9981a2f9 100644 --- a/plugins/ShrinkUrl/plugin.py +++ b/plugins/ShrinkUrl/plugin.py @@ -98,7 +98,7 @@ class ShrinkUrl(callbacks.PluginRegexp): def callCommand(self, command, irc, msg, *args, **kwargs): try: self.__parent.callCommand(command, irc, msg, *args, **kwargs) - except utils.web.Error, e: + except utils.web.Error as e: irc.error(str(e)) def _outFilterThread(self, irc, msg): @@ -195,7 +195,7 @@ class ShrinkUrl(callbacks.PluginRegexp): m = irc.reply(lnurl) if m is not None: m.tag('shrunken') - except ShrinkError, e: + except ShrinkError as e: irc.error(str(e)) ln = thread(wrap(ln, ['url'])) @@ -222,7 +222,7 @@ class ShrinkUrl(callbacks.PluginRegexp): m = irc.reply(tinyurl) if m is not None: m.tag('shrunken') - except ShrinkError, e: + except ShrinkError as e: irc.errorPossibleBug(str(e)) tiny = thread(wrap(tiny, ['url'])) @@ -251,7 +251,7 @@ class ShrinkUrl(callbacks.PluginRegexp): m = irc.reply(xrlurl) if m is not None: m.tag('shrunken') - except ShrinkError, e: + except ShrinkError as e: irc.error(str(e)) xrl = thread(wrap(xrl, ['url'])) @@ -283,7 +283,7 @@ class ShrinkUrl(callbacks.PluginRegexp): m = irc.reply(goourl) if m is not None: m.tag('shrunken') - except ShrinkError, e: + except ShrinkError as e: irc.error(str(e)) goo = thread(wrap(goo, ['url'])) @@ -313,7 +313,7 @@ class ShrinkUrl(callbacks.PluginRegexp): m = irc.reply(ur1url) if m is not None: m.tag('shrunken') - except ShrinkError, e: + except ShrinkError as e: irc.error(str(e)) ur1 = thread(wrap(ur1, ['url'])) @@ -340,7 +340,7 @@ class ShrinkUrl(callbacks.PluginRegexp): m = irc.reply(x0url) if m is not None: m.tag('shrunken') - except ShrinkError, e: + except ShrinkError as e: irc.error(str(e)) x0 = thread(wrap(x0, ['url'])) @@ -367,7 +367,7 @@ class ShrinkUrl(callbacks.PluginRegexp): m = irc.reply(expandurl) if m is not None: m.tag('shrunken') - except ShrinkError, e: + except ShrinkError as e: irc.error(str(e)) expand = thread(wrap(expand, ['url'])) diff --git a/plugins/String/plugin.py b/plugins/String/plugin.py index 212c12cab..a22a1b5cb 100644 --- a/plugins/String/plugin.py +++ b/plugins/String/plugin.py @@ -203,7 +203,7 @@ class String(callbacks.Plugin): try: v = process(f, text, timeout=t, pn=self.name(), cn='re') irc.reply(v) - except commands.ProcessTimeoutError, e: + except commands.ProcessTimeoutError as e: irc.error("ProcessTimeoutError: %s" % (e,)) re = thread(wrap(re, [first('regexpMatcher', 'regexpReplacer'), 'text'])) diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index dc1065868..b21d07b51 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -125,10 +125,10 @@ class Topic(callbacks.Plugin): self.redos = pickle.load(pkl) self.lastTopics = pickle.load(pkl) self.watchingFor332 = pickle.load(pkl) - except Exception, e: + except Exception as e: self.log.debug('Unable to load pickled data: %s', e) pkl.close() - except IOError, e: + except IOError as e: self.log.debug('Unable to open pickle file: %s', e) world.flushers.append(self._flush) @@ -145,11 +145,11 @@ class Topic(callbacks.Plugin): pickle.dump(self.redos, pkl) pickle.dump(self.lastTopics, pkl) pickle.dump(self.watchingFor332, pkl) - except Exception, e: + except Exception as e: self.log.warning('Unable to store pickled data: %s', e) pkl.close() shutil.move(tempfn, filename) - except (IOError, shutil.Error), e: + except (IOError, shutil.Error) as e: self.log.warning('File error: %s', e) def _splitTopic(self, topic, channel): diff --git a/plugins/Unix/plugin.py b/plugins/Unix/plugin.py index 436e25162..2a8fa77f4 100644 --- a/plugins/Unix/plugin.py +++ b/plugins/Unix/plugin.py @@ -153,7 +153,7 @@ class Unix(callbacks.Plugin): stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE) - except OSError, e: + except OSError as e: irc.error(e, Raise=True) ret = inst.poll() if ret is not None: @@ -214,7 +214,7 @@ class Unix(callbacks.Plugin): stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=open(os.devnull)) - except OSError, e: + except OSError as e: irc.error(_('It seems the configured fortune command was ' 'not available.'), Raise=True) (out, err) = inst.communicate() @@ -294,7 +294,7 @@ class Unix(callbacks.Plugin): inst = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=open(os.devnull)) - except OSError, e: + except OSError as e: irc.error('It seems the configured ping command was ' 'not available (%s).' % e, Raise=True) result = inst.communicate() @@ -327,7 +327,7 @@ class Unix(callbacks.Plugin): stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=open(os.devnull)) - except OSError, e: + except OSError as e: irc.error('It seems the configured uptime command was ' 'not available.', Raise=True) (out, err) = inst.communicate() @@ -355,7 +355,7 @@ class Unix(callbacks.Plugin): stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=open(os.devnull)) - except OSError, e: + except OSError as e: irc.error('It seems the configured uptime command was ' 'not available.', Raise=True) (out, err) = inst.communicate() @@ -384,7 +384,7 @@ class Unix(callbacks.Plugin): inst = subprocess.Popen(args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=open(os.devnull)) - except OSError, e: + except OSError as e: irc.error('It seems the requested command was ' 'not available (%s).' % e, Raise=True) result = inst.communicate() diff --git a/plugins/User/plugin.py b/plugins/User/plugin.py index 384ef930d..b35da1434 100644 --- a/plugins/User/plugin.py +++ b/plugins/User/plugin.py @@ -349,11 +349,11 @@ class User(callbacks.Plugin): Raise=True) try: user.addHostmask(hostmask) - except ValueError, e: + except ValueError as e: irc.error(str(e), Raise=True) try: ircdb.users.setUser(user) - except ValueError, e: + except ValueError as e: irc.error(str(e), Raise=True) except ircdb.DuplicateHostmask: irc.error(_('That hostmask is already registered.'), diff --git a/plugins/Utilities/plugin.py b/plugins/Utilities/plugin.py index 50f49cf4e..3050e4afd 100644 --- a/plugins/Utilities/plugin.py +++ b/plugins/Utilities/plugin.py @@ -113,7 +113,7 @@ class Utilities(callbacks.Plugin): try: samp = random.sample(things, num) irc.reply(' '.join(samp)) - except ValueError, e: + except ValueError as e: irc.error('%s' % (e,)) sample = wrap(sample, ['positiveInt', many('anything')]) diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index a90b5d1bf..d9ec16893 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -135,7 +135,7 @@ class Web(callbacks.PluginRegexp): fd = utils.web.getUrlFd(url) text = fd.read(size) fd.close() - except socket.timeout, e: + except socket.timeout as e: self.log.info('Couldn\'t snarf title of %u: %s.', url, e) if self.registryValue('snarferReportIOExceptions', channel): irc.reply(url+" : "+utils.web.TIMED_OUT, prefixNick=False) diff --git a/plugins/__init__.py b/plugins/__init__.py index 597a52b72..bde416a26 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -233,7 +233,7 @@ class ChannelUserDB(ChannelUserDictionary): self.filename = filename try: fd = open(self.filename) - except EnvironmentError, e: + except EnvironmentError as e: log.warning('Couldn\'t open %s: %s.', self.filename, e) return reader = csv.reader(fd) @@ -251,11 +251,11 @@ class ChannelUserDB(ChannelUserDictionary): pass v = self.deserialize(channel, id, t) self[channel, id] = v - except Exception, e: + except Exception as e: log.warning('Invalid line #%s in %s.', lineno, self.__class__.__name__) log.debug('Exception: %s', utils.exnToString(e)) - except Exception, e: # This catches exceptions from csv.reader. + except Exception as e: # This catches exceptions from csv.reader. log.warning('Invalid line #%s in %s.', lineno, self.__class__.__name__) log.debug('Exception: %s', utils.exnToString(e)) @@ -525,10 +525,10 @@ class PeriodicFileDownloader(object): try: try: infd = utils.web.getUrlFd(url) - except IOError, e: + except IOError as e: self.log.warning('Error downloading %s: %s', url, e) return - except utils.web.Error, e: + except utils.web.Error as e: self.log.warning('Error downloading %s: %s', url, e) return confDir = conf.supybot.directories.data() diff --git a/setup.py b/setup.py index 9ffbbe9d6..60c9c08fc 100644 --- a/setup.py +++ b/setup.py @@ -149,7 +149,7 @@ try: log.debug(msg, *args) fixer_names = ['fix_basestring', - 'fix_dict', 'fix_except', + 'fix_dict', 'fix_funcattrs', 'fix_imports', 'fix_itertools', 'fix_itertools_imports', 'fix_long', diff --git a/src/callbacks.py b/src/callbacks.py index a437aa29b..3ac8b6538 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -384,7 +384,7 @@ def tokenize(s, channel=None): try: ret = Tokenizer(brackets=brackets,pipe=pipe,quotes=quotes).tokenize(s) return ret - except ValueError, e: + except ValueError as e: raise SyntaxError(str(e)) def formatCommand(command): @@ -424,7 +424,7 @@ def checkCommandCapability(msg, cb, commandName): return not (default or \ any(lambda x: ircdb.checkCapability(msg.prefix, x), checkAtEnd)) - except RuntimeError, e: + except RuntimeError as e: s = ircdb.unAntiCapability(str(e)) return s @@ -717,9 +717,9 @@ class NestedCommandsIrcProxy(ReplyIrcProxy): log.debug('Calling %s.invalidCommand.', cb.name()) try: cb.invalidCommand(self, self.msg, self.args) - except Error, e: + except Error as e: self.error(str(e)) - except Exception, e: + except Exception as e: log.exception('Uncaught exception in %s.invalidCommand.', cb.name()) log.debug('Finished calling %s.invalidCommand.', cb.name()) @@ -1269,7 +1269,7 @@ class Commands(BasePlugin): self.callingCommand = None except SilentError: pass - except (getopt.GetoptError, ArgumentError), e: + except (getopt.GetoptError, ArgumentError) as e: self.log.debug('Got %s, giving argument error.', utils.exnToString(e)) help = self.getCommandHelp(command) @@ -1277,10 +1277,10 @@ class Commands(BasePlugin): irc.error(_('Invalid arguments for %s.') % method.__name__) else: irc.reply(help) - except (SyntaxError, Error), e: + except (SyntaxError, Error) as e: self.log.debug('Error return: %s', utils.exnToString(e)) irc.error(str(e)) - except Exception, e: + except Exception as e: self.log.exception('Uncaught exception in %s.', command) if conf.supybot.reply.error.detailed(): irc.error(utils.exnToString(e)) @@ -1444,9 +1444,9 @@ class PluginRegexp(Plugin): method = getattr(self, name) try: method(irc, msg, m) - except Error, e: + except Error as e: irc.error(str(e)) - except Exception, e: + except Exception as e: self.log.exception('Uncaught exception in _callRegexp:') def invalidCommand(self, irc, msg, tokens): diff --git a/src/commands.py b/src/commands.py index a6f3f2e2c..981664fe7 100644 --- a/src/commands.py +++ b/src/commands.py @@ -160,7 +160,7 @@ class UrlSnarfThread(world.SupyThread): def run(self): try: super(UrlSnarfThread, self).run() - except utils.web.Error, e: + except utils.web.Error as e: log.debug('Exception in urlSnarfer: %s', utils.exnToString(e)) class SnarfQueue(ircutils.FloodQueue): @@ -301,7 +301,7 @@ def getId(irc, msg, args, state, kind=None): try: args[0] = args[0].lstrip('#') getInt(irc, msg, args, state, type=type) - except Exception, e: + except Exception as e: args[0] = original raise @@ -798,7 +798,7 @@ class UnknownConverter(KeyError): def getConverter(name): try: return wrappers[name] - except KeyError, e: + except KeyError as e: raise UnknownConverter(str(e)) def callConverter(name, irc, msg, args, state, *L): @@ -852,7 +852,7 @@ class rest(context): args[:] = [' '.join(args)] try: super(rest, self).__call__(irc, msg, args, state) - except Exception, e: + except Exception as e: args[:] = original else: raise IndexError @@ -878,7 +878,7 @@ class optional(additional): def __call__(self, irc, msg, args, state): try: super(optional, self).__call__(irc, msg, args, state) - except (callbacks.ArgumentError, callbacks.Error), e: + except (callbacks.ArgumentError, callbacks.Error) as e: log.debug('Got %s, returning default.', utils.exnToString(e)) state.errored = False setDefault(state, self.default) @@ -896,7 +896,7 @@ class any(context): self.__parent.__call__(irc, msg, args, st) except IndexError: pass - except (callbacks.ArgumentError, callbacks.Error), e: + except (callbacks.ArgumentError, callbacks.Error) as e: if not self.continueOnError: raise else: @@ -925,7 +925,7 @@ class first(context): try: spec(irc, msg, args, state) return - except Exception, e: + except Exception as e: e2 = e # 'e' is local. errored = state.errored state.errored = False @@ -956,7 +956,7 @@ class commalist(context): if part: # trailing commas super(commalist, self).__call__(irc, msg, [part], st) state.args.append(st.args) - except Exception, e: + except Exception as e: args[:] = original raise diff --git a/src/dbi.py b/src/dbi.py index 5a0c809a5..ab3999e48 100644 --- a/src/dbi.py +++ b/src/dbi.py @@ -117,7 +117,7 @@ class DirMapping(MappingInterface): try: fd = open(self._makeFilename(id)) return fd.read() - except EnvironmentError, e: + except EnvironmentError as e: exn = NoRecordError(id) exn.realException = e raise exn @@ -141,7 +141,7 @@ class DirMapping(MappingInterface): def remove(self, id): try: os.remove(self._makeFilename(id)) - except EnvironmentError, e: + except EnvironmentError as e: raise NoRecordError(id) class FlatfileMapping(MappingInterface): @@ -155,7 +155,7 @@ class FlatfileMapping(MappingInterface): self.currentId = int(strId) except ValueError: raise Error('Invalid file for FlatfileMapping: %s' % filename) - except EnvironmentError, e: + except EnvironmentError as e: # File couldn't be opened. self.maxSize = int(math.log10(maxSize)) self.currentId = 0 diff --git a/src/drivers/Socket.py b/src/drivers/Socket.py index b49c52e74..98be09eca 100644 --- a/src/drivers/Socket.py +++ b/src/drivers/Socket.py @@ -140,7 +140,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): sent = self.conn.send(self.outbuffer.encode()) self.outbuffer = self.outbuffer[sent:] self.eagains = 0 - except socket.error, e: + except socket.error as e: self._handleSocketError(e) if self.zombie and not self.outbuffer: self._reallyDie() @@ -233,13 +233,13 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): self.irc.feedMsg(msg) except socket.timeout: pass - except SSLError, e: + except 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 as e: self._handleSocketError(e) return if self.irc and not self.irc.zombie: @@ -295,7 +295,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): self.conn = utils.net.getSocket(address, socks_proxy) vhost = conf.supybot.protocols.irc.vhost() self.conn.bind((vhost, 0)) - except socket.error, e: + except socket.error as e: drivers.log.connectError(self.currentServer, e) self.scheduleReconnect() return @@ -321,7 +321,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin): setTimeout() self.connected = True self.resetDelay() - except socket.error, e: + except socket.error as e: if e.args[0] == 115: now = time.time() when = now + 60 diff --git a/src/ircdb.py b/src/ircdb.py index b82cdffc0..a888b3fb4 100644 --- a/src/ircdb.py +++ b/src/ircdb.py @@ -628,10 +628,10 @@ class UsersDictionary(utils.IterableMap): reader.readFile(filename) self.noFlush = False self.flush() - except EnvironmentError, e: + except EnvironmentError as e: log.error('Invalid user dictionary file, resetting to empty.') log.error('Exact error: %s', utils.exnToString(e)) - except Exception, e: + except Exception as e: log.exception('Exact error:') finally: self.noFlush = False @@ -645,7 +645,7 @@ class UsersDictionary(utils.IterableMap): if self.filename is not None: try: self.open(self.filename) - except EnvironmentError, e: + except EnvironmentError as e: log.warning('UsersDictionary.reload failed: %s', e) else: log.error('UsersDictionary.reload called with no filename.') @@ -834,10 +834,10 @@ class ChannelsDictionary(utils.IterableMap): reader.readFile(filename) self.noFlush = False self.flush() - except EnvironmentError, e: + except EnvironmentError as e: log.error('Invalid channel database, resetting to empty.') log.error('Exact error: %s', utils.exnToString(e)) - except Exception, e: + except Exception as e: log.error('Invalid channel database, resetting to empty.') log.exception('Exact error:') finally: @@ -870,7 +870,7 @@ class ChannelsDictionary(utils.IterableMap): self.channels.clear() try: self.open(self.filename) - except EnvironmentError, e: + except EnvironmentError as e: log.warning('ChannelsDictionary.reload failed: %s', e) else: log.warning('ChannelsDictionary.reload without self.filename.') @@ -913,7 +913,7 @@ class IgnoresDB(object): else: expiration = 0 self.add(hostmask, expiration) - except Exception, e: + except Exception as e: log.error('Invalid line in ignores database: %q', line) fd.close() @@ -941,7 +941,7 @@ class IgnoresDB(object): self.hostmasks.clear() try: self.open(self.filename) - except EnvironmentError, e: + except EnvironmentError as e: log.warning('IgnoresDB.reload failed: %s', e) # Let's be somewhat transactional. self.hostmasks.update(oldhostmasks) @@ -971,7 +971,7 @@ try: userFile = os.path.join(confDir, conf.supybot.databases.users.filename()) users = UsersDictionary() users.open(userFile) -except EnvironmentError, e: +except EnvironmentError as e: log.warning('Couldn\'t open user database: %s', e) try: @@ -979,7 +979,7 @@ try: conf.supybot.databases.channels.filename()) channels = ChannelsDictionary() channels.open(channelFile) -except EnvironmentError, e: +except EnvironmentError as e: log.warning('Couldn\'t open channel database: %s', e) try: @@ -987,7 +987,7 @@ try: conf.supybot.databases.ignores.filename()) ignores = IgnoresDB() ignores.open(ignoreFile) -except EnvironmentError, e: +except EnvironmentError as e: log.warning('Couldn\'t open ignore database: %s', e) @@ -1083,7 +1083,7 @@ def checkCapability(hostmask, capability, users=users, channels=channels, # Raised when no hostmasks match. return _checkCapabilityForUnknownUser(capability, users=users, channels=channels) - except ValueError, e: + except ValueError as e: # Raised when multiple hostmasks match. log.warning('%s: %s', hostmask, e) return _checkCapabilityForUnknownUser(capability, users=users, diff --git a/src/irclib.py b/src/irclib.py index a7cac3acf..fd599b6cd 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -475,7 +475,7 @@ class IrcState(IrcCommandDispatcher): converter = self._005converters.get(name, lambda x: x) try: self.supported[name] = converter(value) - except Exception, e: + except Exception as e: log.exception('Uncaught exception in 005 converter:') log.error('Name: %s, Converter: %s', name, converter) else: diff --git a/src/log.py b/src/log.py index d811a717b..3922f6963 100644 --- a/src/log.py +++ b/src/log.py @@ -107,7 +107,7 @@ class StdoutStreamHandler(logging.StreamHandler): if conf.supybot.log.stdout() and not conf.daemonized: try: logging.StreamHandler.emit(self, record) - except ValueError, e: # Raised if sys.stdout is closed. + except ValueError as e: # Raised if sys.stdout is closed. self.disable() error('Error logging to stdout. Removing stdout handler.') exception('Uncaught exception in StdoutStreamHandler:') @@ -184,7 +184,7 @@ if not os.path.exists(pluginLogDir): try: messagesLogFilename = os.path.join(_logDir, 'messages.log') _handler = BetterFileHandler(messagesLogFilename) -except EnvironmentError, e: +except EnvironmentError as e: raise SystemExit('Error opening messages logfile (%s). ' \ 'Generally, this is because you are running Supybot in a directory ' \ 'you don\'t have permissions to add files in, or you\'re running ' \ @@ -348,14 +348,14 @@ def firewall(f, errorHandler=None): def m(self, *args, **kwargs): try: return f(self, *args, **kwargs) - except Exception, e: + except Exception as e: if testing: raise logException(self) if errorHandler is not None: try: return errorHandler(self, *args, **kwargs) - except Exception, e: + except Exception as e: logException(self, 'Uncaught exception in errorHandler') m = utils.python.changeFunctionName(m, f.func_name, f.__doc__) return m diff --git a/src/plugin.py b/src/plugin.py index 3517aa3ce..448a017e6 100644 --- a/src/plugin.py +++ b/src/plugin.py @@ -85,7 +85,7 @@ def loadPluginClass(irc, module, register=None): """Loads the plugin Class from the given module into the given Irc.""" try: cb = module.Class(irc) - except TypeError, e: + except TypeError as e: s = str(e) if '2 given' in s and '__init__' in s: raise callbacks.Error('In our switch from CVS to Darcs (after 0.80.1), we ' \ @@ -100,7 +100,7 @@ def loadPluginClass(irc, module, register=None): module.__name__) else: raise - except AttributeError, e: + except AttributeError as e: if 'Class' in str(e): raise callbacks.Error('This plugin module doesn\'t have a "Class" ' \ 'attribute to specify which plugin should be ' \ @@ -127,7 +127,7 @@ def loadPluginClass(irc, module, register=None): renameCommand(cb, command, newName) else: conf.supybot.commands.renames.unregister(plugin) - except registry.NonExistentRegistryEntry, e: + except registry.NonExistentRegistryEntry as e: pass # The plugin isn't there. irc.addCallback(cb) return cb diff --git a/src/registry.py b/src/registry.py index 194f421ba..b6779c636 100644 --- a/src/registry.py +++ b/src/registry.py @@ -127,12 +127,12 @@ def close(registry, filename, private=True): lines.append('#\n') try: x = value.__class__(value._default, value._help) - except Exception, e: + except Exception as e: exception('Exception instantiating default for %s:' % value._name) try: lines.append('# Default value: %s\n' % x) - except Exception, e: + except Exception as e: exception('Exception printing default value of %s:' % value._name) lines.append('###\n') @@ -144,7 +144,7 @@ def close(registry, filename, private=True): else: s = 'CENSORED' fd.write('%s: %s\n' % (name, s)) - except Exception, e: + except Exception as e: exception('Exception printing value:') fd.close() @@ -615,7 +615,7 @@ class Regexp(Value): self.setValue(utils.str.perlReToPythonRe(s), sr=s) else: self.setValue(None) - except ValueError, e: + except ValueError as e: self.error(e) def setValue(self, v, sr=None): diff --git a/src/schedule.py b/src/schedule.py index be0fd05fd..7019790ae 100644 --- a/src/schedule.py +++ b/src/schedule.py @@ -140,7 +140,7 @@ class Schedule(drivers.IrcDriver): del self.events[name] try: f(*args, **kwargs) - except Exception, e: + except Exception as e: log.exception('Uncaught exception in scheduled function:') diff --git a/src/test.py b/src/test.py index f3e85a815..f1ee7c7e4 100644 --- a/src/test.py +++ b/src/test.py @@ -81,7 +81,7 @@ class TestPlugin(callbacks.Plugin): irc.reply(repr(eval(' '.join(args)))) except callbacks.ArgumentError: raise - except Exception, e: + except Exception as e: irc.reply(utils.exnToString(e)) # Since we know we don't now need the Irc object, we just give None. This # might break if callbacks.Privmsg ever *requires* the Irc object. diff --git a/src/utils/gen.py b/src/utils/gen.py index 7327743cf..38f0100fd 100644 --- a/src/utils/gen.py +++ b/src/utils/gen.py @@ -160,7 +160,7 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}): without unsafely using eval().""" try: node = ast.parse(s) - except SyntaxError, e: + except SyntaxError as e: raise ValueError('Invalid string: %s.' % e) nodes = ast.parse(s).body if not nodes: diff --git a/src/utils/str.py b/src/utils/str.py index a080653f5..a5e49597a 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -194,7 +194,7 @@ def perlReToPythonRe(s): raise ValueError('Invalid flag: %s' % c) try: return re.compile(regexp, flag) - except re.error, e: + except re.error as e: raise ValueError(str(e)) def perlReToReplacer(s): diff --git a/src/utils/transaction.py b/src/utils/transaction.py index b91f14783..8a4e09d6b 100644 --- a/src/utils/transaction.py +++ b/src/utils/transaction.py @@ -107,7 +107,7 @@ class Transaction(TransactionMixin): raise FailedAcquisition(self.txnDir) try: os.rename(self.txnDir, self.dir) - except EnvironmentError, e: + except EnvironmentError as e: raise FailedAcquisition(self.txnDir, e) os.mkdir(self.dirize(self.ORIGINALS)) os.mkdir(self.dirize(self.REPLACEMENTS)) diff --git a/src/utils/web.py b/src/utils/web.py index 422e9eec3..dec904de0 100644 --- a/src/utils/web.py +++ b/src/utils/web.py @@ -125,18 +125,18 @@ def getUrlFd(url, headers=None, data=None, timeout=None): request.set_proxy(httpProxy, 'http') fd = urllib2.urlopen(request, timeout=timeout) return fd - except socket.timeout, e: + except socket.timeout as e: raise Error(TIMED_OUT) - except sockerrors, e: + except sockerrors as e: raise Error(strError(e)) - except httplib.InvalidURL, e: + except httplib.InvalidURL as e: raise Error('Invalid URL: %s' % e) - except urllib2.HTTPError, e: + except urllib2.HTTPError as e: raise Error(strError(e)) - except urllib2.URLError, e: + except urllib2.URLError as e: raise Error(strError(e.reason)) # Raised when urllib doesn't recognize the url type - except ValueError, e: + except ValueError as e: raise Error(strError(e)) def getUrl(url, size=None, headers=None, data=None): @@ -151,7 +151,7 @@ def getUrl(url, size=None, headers=None, data=None): text = fd.read() else: text = fd.read(size) - except socket.timeout, e: + except socket.timeout as e: raise Error(TIMED_OUT) fd.close() return text diff --git a/src/world.py b/src/world.py index 3a6d53bd8..a59a59973 100644 --- a/src/world.py +++ b/src/world.py @@ -118,7 +118,7 @@ def flush(): for (i, f) in enumerate(flushers): try: f() - except Exception, e: + except Exception as e: log.exception('Uncaught exception in flusher #%s (%s):', i, f) def debugFlush(s=''):