Merge remote-tracking branch 'origin/speed-up-2to3' into testing

Conflicts:
	locales/fr.po
	plugins/Misc/plugin.py
	sandbox/check_trans.py
	src/i18n.py
This commit is contained in:
Valentin Lorentz 2014-02-02 22:28:19 +01:00
commit 5d301b653f
83 changed files with 607 additions and 533 deletions

View File

@ -151,7 +151,7 @@ class Admin(callbacks.Plugin):
networkGroup.channels().add(channel) networkGroup.channels().add(channel)
if key: if key:
networkGroup.channels.key.get(channel).setValue(key) networkGroup.channels.key.get(channel).setValue(key)
maxchannels = irc.state.supported.get('maxchannels', sys.maxint) maxchannels = irc.state.supported.get('maxchannels', sys.maxsize)
if len(irc.state.channels) + 1 > maxchannels: if len(irc.state.channels) + 1 > maxchannels:
irc.error(_('I\'m already too close to maximum number of ' irc.error(_('I\'m already too close to maximum number of '
'channels for this network.'), Raise=True) 'channels for this network.'), Raise=True)
@ -351,7 +351,7 @@ class Admin(callbacks.Plugin):
""" """
# XXX Add the expirations. # XXX Add the expirations.
if ircdb.ignores.hostmasks: if ircdb.ignores.hostmasks:
irc.reply(format('%L', (map(repr,ircdb.ignores.hostmasks)))) irc.reply(format('%L', (list(map(repr,ircdb.ignores.hostmasks)))))
else: else:
irc.reply(_('I\'m not currently globally ignoring anyone.')) irc.reply(_('I\'m not currently globally ignoring anyone.'))
list = wrap(list) list = wrap(list)

View File

@ -349,7 +349,7 @@ class RecursiveAlias(AkaError):
dollarRe = re.compile(r'\$(\d+)') dollarRe = re.compile(r'\$(\d+)')
def findBiggestDollar(alias): def findBiggestDollar(alias):
dollars = dollarRe.findall(alias) dollars = dollarRe.findall(alias)
dollars = map(int, dollars) dollars = list(map(int, dollars))
dollars.sort() dollars.sort()
if dollars: if dollars:
return dollars[-1] return dollars[-1]
@ -359,7 +359,7 @@ def findBiggestDollar(alias):
atRe = re.compile(r'@(\d+)') atRe = re.compile(r'@(\d+)')
def findBiggestAt(alias): def findBiggestAt(alias):
ats = atRe.findall(alias) ats = atRe.findall(alias)
ats = map(int, ats) ats = list(map(int, ats))
ats.sort() ats.sort()
if ats: if ats:
return ats[-1] return ats[-1]
@ -396,15 +396,15 @@ class Aka(callbacks.Plugin):
def listCommands(self): def listCommands(self):
channel = dynamic.channel or 'global' channel = dynamic.channel or 'global'
return list(set(map(callbacks.formatCommand, return list(set(list(map(callbacks.formatCommand,
self._db.get_aka_list(channel) + self._db.get_aka_list(channel) +
self._db.get_aka_list('global')) + self._db.get_aka_list('global'))) +
['add', 'remove', 'lock', 'unlock', 'importaliasdatabase'])) ['add', 'remove', 'lock', 'unlock', 'importaliasdatabase']))
def getCommand(self, args, check_other_plugins=True): def getCommand(self, args, check_other_plugins=True):
canonicalName = callbacks.canonicalName canonicalName = callbacks.canonicalName
# All the code from here to the 'for' loop is copied from callbacks.py # All the code from here to the 'for' loop is copied from callbacks.py
assert args == map(canonicalName, args) assert args == list(map(canonicalName, args))
first = args[0] first = args[0]
for cb in self.cbs: for cb in self.cbs:
if first == cb.canonicalName(): if first == cb.canonicalName():
@ -439,7 +439,7 @@ class Aka(callbacks.Plugin):
args = getArgs(args, required=biggestDollar, optional=biggestAt, args = getArgs(args, required=biggestDollar, optional=biggestAt,
wildcard=wildcard) wildcard=wildcard)
max_len = conf.supybot.reply.maximumLength() max_len = conf.supybot.reply.maximumLength()
args = list(map(lambda x:x[:max_len], args)) args = list([x[:max_len] for x in args])
def regexpReplace(m): def regexpReplace(m):
idx = int(m.group(1)) idx = int(m.group(1))
return args[idx-1] return args[idx-1]
@ -649,7 +649,7 @@ class Aka(callbacks.Plugin):
if errors: if errors:
irc.error(format(_('Error occured when importing the %n: %L'), irc.error(format(_('Error occured when importing the %n: %L'),
(len(errors), 'following', 'command'), (len(errors), 'following', 'command'),
map(lambda x:'%s (%s)' % x, errors.items()))) ['%s (%s)' % x for x in errors.items()]))
else: else:
irc.replySuccess() irc.replySuccess()
importaliasdatabase = wrap(importaliasdatabase, ['owner']) importaliasdatabase = wrap(importaliasdatabase, ['owner'])

View File

@ -57,13 +57,13 @@ def getChannel(msg, args=()):
'variable ' \ 'variable ' \
'supybot.reply.requireChannelCommandsToBeSentInChannel ' \ 'supybot.reply.requireChannelCommandsToBeSentInChannel ' \
'to False.' 'to False.'
raise callbacks.Error, s raise callbacks.Error(s)
return args.pop(0) return args.pop(0)
elif ircutils.isChannel(msg.args[0]): elif ircutils.isChannel(msg.args[0]):
return msg.args[0] return msg.args[0]
else: else:
raise callbacks.Error, 'Command must be sent in a channel or ' \ raise callbacks.Error('Command must be sent in a channel or ' \
'include a channel in its arguments.' 'include a channel in its arguments.')
def getArgs(args, required=1, optional=0, wildcard=0): def getArgs(args, required=1, optional=0, wildcard=0):
if len(args) < required: if len(args) < required:
@ -87,7 +87,7 @@ class RecursiveAlias(AliasError):
dollarRe = re.compile(r'\$(\d+)') dollarRe = re.compile(r'\$(\d+)')
def findBiggestDollar(alias): def findBiggestDollar(alias):
dollars = dollarRe.findall(alias) dollars = dollarRe.findall(alias)
dollars = map(int, dollars) dollars = list(map(int, dollars))
dollars.sort() dollars.sort()
if dollars: if dollars:
return dollars[-1] return dollars[-1]
@ -97,7 +97,7 @@ def findBiggestDollar(alias):
atRe = re.compile(r'@(\d+)') atRe = re.compile(r'@(\d+)')
def findBiggestAt(alias): def findBiggestAt(alias):
ats = atRe.findall(alias) ats = atRe.findall(alias)
ats = map(int, ats) ats = list(map(int, ats))
ats.sort() ats.sort()
if ats: if ats:
return ats[-1] return ats[-1]
@ -163,12 +163,12 @@ def makeNewAlias(name, alias):
biggestAt = findBiggestAt(original) biggestAt = findBiggestAt(original)
wildcard = '$*' in original wildcard = '$*' in original
if biggestAt and wildcard: if biggestAt and wildcard:
raise AliasError, 'Can\'t mix $* and optional args (@1, etc.)' raise AliasError('Can\'t mix $* and optional args (@1, etc.)')
if original.count('$*') > 1: if original.count('$*') > 1:
raise AliasError, 'There can be only one $* in an alias.' raise AliasError('There can be only one $* in an alias.')
testTokens = callbacks.tokenize(original) testTokens = callbacks.tokenize(original)
if testTokens and isinstance(testTokens[0], list): if testTokens and isinstance(testTokens[0], list):
raise AliasError, 'Commands may not be the result of nesting.' raise AliasError('Commands may not be the result of nesting.')
def f(self, irc, msg, args): def f(self, irc, msg, args):
alias = original.replace('$nick', msg.nick) alias = original.replace('$nick', msg.nick)
if '$channel' in original: if '$channel' in original:
@ -179,7 +179,7 @@ def makeNewAlias(name, alias):
args = getArgs(args, required=biggestDollar, optional=biggestAt, args = getArgs(args, required=biggestDollar, optional=biggestAt,
wildcard=wildcard) wildcard=wildcard)
max_len = conf.supybot.reply.maximumLength() max_len = conf.supybot.reply.maximumLength()
args = list(map(lambda x:x[:max_len], args)) args = list([x[:max_len] for x in args])
def regexpReplace(m): def regexpReplace(m):
idx = int(m.group(1)) idx = int(m.group(1))
return args[idx-1] return args[idx-1]
@ -272,7 +272,7 @@ class Alias(callbacks.Plugin):
for (alias, (command, locked, _)) in self.aliases.items(): for (alias, (command, locked, _)) in self.aliases.items():
try: try:
self.addAlias(irc, alias, command, locked) self.addAlias(irc, alias, command, locked)
except Exception, e: except Exception as e:
self.log.exception('Exception when trying to add alias %s. ' self.log.exception('Exception when trying to add alias %s. '
'Removing from the Alias database.', alias) 'Removing from the Alias database.', alias)
del self.aliases[alias] del self.aliases[alias]
@ -333,21 +333,21 @@ class Alias(callbacks.Plugin):
realName = callbacks.canonicalName(name) realName = callbacks.canonicalName(name)
if name != realName: if name != realName:
s = format(_('That name isn\'t valid. Try %q instead.'), realName) s = format(_('That name isn\'t valid. Try %q instead.'), realName)
raise AliasError, s raise AliasError(s)
name = realName name = realName
if self.isCommandMethod(name): if self.isCommandMethod(name):
if realName not in self.aliases: if realName not in self.aliases:
s = 'You can\'t overwrite commands in this plugin.' s = 'You can\'t overwrite commands in this plugin.'
raise AliasError, s raise AliasError(s)
if name in self.aliases: if name in self.aliases:
(currentAlias, locked, _) = self.aliases[name] (currentAlias, locked, _) = self.aliases[name]
if locked and currentAlias != alias: if locked and currentAlias != alias:
raise AliasError, format('Alias %q is locked.', name) raise AliasError(format('Alias %q is locked.', name))
try: try:
f = makeNewAlias(name, alias) f = makeNewAlias(name, alias)
f = types.MethodType(f, self) f = types.MethodType(f, self)
except RecursiveAlias: except RecursiveAlias:
raise AliasError, 'You can\'t define a recursive alias.' raise AliasError('You can\'t define a recursive alias.')
if '.' in name or '|' in name: if '.' in name or '|' in name:
aliasGroup = self.registryValue('escapedaliases', value=False) aliasGroup = self.registryValue('escapedaliases', value=False)
confname = escapeAlias(name) confname = escapeAlias(name)
@ -374,9 +374,9 @@ class Alias(callbacks.Plugin):
else: else:
conf.supybot.plugins.Alias.aliases.unregister(name) conf.supybot.plugins.Alias.aliases.unregister(name)
else: else:
raise AliasError, 'That alias is locked.' raise AliasError('That alias is locked.')
else: else:
raise AliasError, 'There is no such alias.' raise AliasError('There is no such alias.')
@internationalizeDocstring @internationalizeDocstring
def add(self, irc, msg, args, name, alias): def add(self, irc, msg, args, name, alias):
@ -397,7 +397,7 @@ class Alias(callbacks.Plugin):
self.log.info('Adding alias %q for %q (from %s)', self.log.info('Adding alias %q for %q (from %s)',
name, alias, msg.prefix) name, alias, msg.prefix)
irc.replySuccess() irc.replySuccess()
except AliasError, e: except AliasError as e:
irc.error(str(e)) irc.error(str(e))
add = wrap(add, ['commandName', 'text']) add = wrap(add, ['commandName', 'text'])
@ -411,7 +411,7 @@ class Alias(callbacks.Plugin):
self.removeAlias(name) self.removeAlias(name)
self.log.info('Removing alias %q (from %s)', name, msg.prefix) self.log.info('Removing alias %q (from %s)', name, msg.prefix)
irc.replySuccess() irc.replySuccess()
except AliasError, e: except AliasError as e:
irc.error(str(e)) irc.error(str(e))
remove = wrap(remove, ['commandName']) remove = wrap(remove, ['commandName'])

View File

@ -279,7 +279,7 @@ class Channel(callbacks.Plugin):
irc.error(_('I cowardly refuse to kick myself.'), Raise=True) irc.error(_('I cowardly refuse to kick myself.'), Raise=True)
if not reason: if not reason:
reason = msg.nick reason = msg.nick
kicklen = irc.state.supported.get('kicklen', sys.maxint) kicklen = irc.state.supported.get('kicklen', sys.maxsize)
if len(reason) > kicklen: if len(reason) > kicklen:
irc.error(_('The reason you gave is longer than the allowed ' irc.error(_('The reason you gave is longer than the allowed '
'length for a KICK reason on this server.'), 'length for a KICK reason on this server.'),
@ -667,7 +667,7 @@ class Channel(callbacks.Plugin):
irc.reply(s) irc.reply(s)
else: else:
L = sorted(c.ignores) L = sorted(c.ignores)
irc.reply(utils.str.commaAndify(map(repr, L))) irc.reply(utils.str.commaAndify(list(map(repr, L))))
list = wrap(list, ['op']) list = wrap(list, ['op'])
class capability(callbacks.Commands): class capability(callbacks.Commands):
@ -808,7 +808,7 @@ class Channel(callbacks.Plugin):
'called %s.'), plugin.name(), command) 'called %s.'), plugin.name(), command)
elif command: elif command:
# findCallbackForCommand # findCallbackForCommand
if filter(None, irc.findCallbacksForArgs([command])): if list(filter(None, irc.findCallbacksForArgs([command]))):
s = '-%s' % command s = '-%s' % command
else: else:
failMsg = format(_('No plugin or command named %s could be ' failMsg = format(_('No plugin or command named %s could be '
@ -847,7 +847,7 @@ class Channel(callbacks.Plugin):
'called %s.'), plugin.name(), command) 'called %s.'), plugin.name(), command)
elif command: elif command:
# findCallbackForCommand # findCallbackForCommand
if filter(None, irc.findCallbacksForArgs([command])): if list(filter(None, irc.findCallbacksForArgs([command]))):
s = '-%s' % command s = '-%s' % command
else: else:
failMsg = format(_('No plugin or command named %s could be ' failMsg = format(_('No plugin or command named %s could be '

View File

@ -98,7 +98,7 @@ class ChannelLogger(callbacks.Plugin):
for log in self._logs(): for log in self._logs():
try: try:
log.flush() log.flush()
except ValueError, e: except ValueError as e:
if e.args[0] != 'I/O operation on a closed file': if e.args[0] != 'I/O operation on a closed file':
self.log.exception('Odd exception:') self.log.exception('Odd exception:')

View File

@ -135,7 +135,7 @@ class StatsDB(plugins.ChannelUserDB):
return v.values() return v.values()
def deserialize(self, channel, id, L): def deserialize(self, channel, id, L):
L = map(int, L) L = list(map(int, L))
if id == 'channelStats': if id == 'channelStats':
return ChannelStat(*L) return ChannelStat(*L)
else: else:
@ -336,9 +336,9 @@ class ChannelStats(callbacks.Plugin):
v = eval(expr, e, e) v = eval(expr, e, e)
except ZeroDivisionError: except ZeroDivisionError:
v = float('inf') v = float('inf')
except NameError, e: except NameError as e:
irc.errorInvalid(_('stat variable'), str(e).split()[1]) irc.errorInvalid(_('stat variable'), str(e).split()[1])
except Exception, e: except Exception as e:
irc.error(utils.exnToString(e), Raise=True) irc.error(utils.exnToString(e), Raise=True)
if id == 0: if id == 0:
users.append((v, irc.nick)) users.append((v, irc.nick))

View File

@ -65,7 +65,7 @@ class Conditional(callbacks.Plugin):
tokens = callbacks.tokenize(command) tokens = callbacks.tokenize(command)
try: try:
self.Proxy(irc.irc, msg, tokens) self.Proxy(irc.irc, msg, tokens)
except Exception, e: except Exception as e:
self.log.exception('Uncaught exception in requested function:') self.log.exception('Uncaught exception in requested function:')
@internationalizeDocstring @internationalizeDocstring

View File

@ -51,7 +51,7 @@ _ = PluginInternationalization('Config')
def getWrapper(name): def getWrapper(name):
parts = registry.split(name) parts = registry.split(name)
if not parts or parts[0] not in ('supybot', 'users'): if not parts or parts[0] not in ('supybot', 'users'):
raise InvalidRegistryName, name raise InvalidRegistryName(name)
group = getattr(conf, parts.pop(0)) group = getattr(conf, parts.pop(0))
while parts: while parts:
try: try:
@ -60,7 +60,7 @@ def getWrapper(name):
# that we have a useful error message for the user. # that we have a useful error message for the user.
except (registry.NonExistentRegistryEntry, except (registry.NonExistentRegistryEntry,
registry.InvalidRegistryName): registry.InvalidRegistryName):
raise registry.InvalidRegistryName, name raise registry.InvalidRegistryName(name)
return group return group
def getCapability(name): def getCapability(name):
@ -99,7 +99,7 @@ def getConfigVar(irc, msg, args, state):
group = getWrapper(name) group = getWrapper(name)
state.args.append(group) state.args.append(group)
del args[0] del args[0]
except registry.InvalidRegistryName, e: except registry.InvalidRegistryName as e:
state.errorInvalid(_('configuration variable'), str(e)) state.errorInvalid(_('configuration variable'), str(e))
addConverter('configVar', getConfigVar) addConverter('configVar', getConfigVar)
@ -114,7 +114,7 @@ class Config(callbacks.Plugin):
def callCommand(self, command, irc, msg, *args, **kwargs): def callCommand(self, command, irc, msg, *args, **kwargs):
try: try:
super(Config, self).callCommand(command, irc, msg, *args, **kwargs) super(Config, self).callCommand(command, irc, msg, *args, **kwargs)
except registry.InvalidRegistryValue, e: except registry.InvalidRegistryValue as e:
irc.error(str(e)) irc.error(str(e))
def _list(self, group): def _list(self, group):

View File

@ -65,15 +65,15 @@ class Connection:
code, text = self.getresultcode() code, text = self.getresultcode()
if code < 200 or code >= 300: if code < 200 or code >= 300:
raise Exception, "Got '%s' when 200-class response expected" % \ raise Exception("Got '%s' when 200-class response expected" % \
line line)
return [code, text] return [code, text]
def get100block(self): def get100block(self):
"""Used when expecting multiple lines of text -- gets the block """Used when expecting multiple lines of text -- gets the block
part only. Does not get any codes or anything! Returns a string.""" part only. Does not get any codes or anything! Returns a string."""
data = [] data = []
while 1: while True:
line = self.rfile.readline().decode('utf8').strip() line = self.rfile.readline().decode('utf8').strip()
if line == '.': if line == '.':
break break
@ -86,8 +86,8 @@ class Connection:
finalcode]""" finalcode]"""
code, text = self.getresultcode() code, text = self.getresultcode()
if code < 100 or code >= 200: if code < 100 or code >= 200:
raise Exception, "Got '%s' when 100-class response expected" % \ raise Exception("Got '%s' when 100-class response expected" % \
code code)
bodylines = self.get100block().split("\n") bodylines = self.get100block().split("\n")
@ -149,7 +149,7 @@ class Connection:
if not hasattr(self, 'dbobjs'): if not hasattr(self, 'dbobjs'):
self.dbobjs = {} self.dbobjs = {}
if self.dbobjs.has_key(dbname): if dbname in self.dbobjs:
return self.dbobjs[dbname] return self.dbobjs[dbname]
# We use self.dbdescs explicitly since we don't want to # We use self.dbdescs explicitly since we don't want to
@ -157,7 +157,7 @@ class Connection:
if dbname != '*' and dbname != '!' and \ if dbname != '*' and dbname != '!' and \
not dbname in self.dbdescs.keys(): not dbname in self.dbdescs.keys():
raise Exception, "Invalid database name '%s'" % dbname raise Exception("Invalid database name '%s'" % dbname)
self.dbobjs[dbname] = Database(self, dbname) self.dbobjs[dbname] = Database(self, dbname)
return self.dbobjs[dbname] return self.dbobjs[dbname]
@ -181,7 +181,7 @@ class Connection:
if database != '*' and database != '!' and \ if database != '*' and database != '!' and \
not database in self.getdbdescs(): not database in self.getdbdescs():
raise Exception, "Invalid database '%s' specified" % database raise Exception("Invalid database '%s' specified" % database)
self.sendcommand("DEFINE " + enquote(database) + " " + enquote(word)) self.sendcommand("DEFINE " + enquote(database) + " " + enquote(word))
code = self.getresultcode()[0] code = self.getresultcode()[0]
@ -192,9 +192,9 @@ class Connection:
# No definitions. # No definitions.
return [] return []
if code != 150: if code != 150:
raise Exception, "Unknown code %d" % code raise Exception("Unknown code %d" % code)
while 1: while True:
code, text = self.getresultcode() code, text = self.getresultcode()
if code != 151 or code is None: if code != 151 or code is None:
break break
@ -217,10 +217,10 @@ class Connection:
self.getstratdescs() # Prime the cache self.getstratdescs() # Prime the cache
self.getdbdescs() # Prime the cache self.getdbdescs() # Prime the cache
if not strategy in self.getstratdescs().keys(): if not strategy in self.getstratdescs().keys():
raise Exception, "Invalid strategy '%s'" % strategy raise Exception("Invalid strategy '%s'" % strategy)
if database != '*' and database != '!' and \ if database != '*' and database != '!' and \
not database in self.getdbdescs().keys(): not database in self.getdbdescs().keys():
raise Exception, "Invalid database name '%s'" % database raise Exception("Invalid database name '%s'" % database)
self.sendcommand("MATCH %s %s %s" % (enquote(database), self.sendcommand("MATCH %s %s %s" % (enquote(database),
enquote(strategy), enquote(strategy),
@ -230,7 +230,7 @@ class Connection:
# No Matches # No Matches
return [] return []
if code != 152: if code != 152:
raise Exception, "Unexpected code %d" % code raise Exception("Unexpected code %d" % code)
retval = [] retval = []
@ -239,7 +239,7 @@ class Connection:
retval.append(Definition(self, self.getdbobj(matchdict), retval.append(Definition(self, self.getdbobj(matchdict),
dequote(matchword))) dequote(matchword)))
if self.getresultcode()[0] != 250: if self.getresultcode()[0] != 250:
raise Exception, "Unexpected end-of-list code %d" % code raise Exception("Unexpected end-of-list code %d" % code)
return retval return retval
class Database: class Database:

View File

@ -56,7 +56,7 @@ class Dict(callbacks.Plugin):
dbs = list(conn.getdbdescs().keys()) dbs = list(conn.getdbdescs().keys())
dbs.sort() dbs.sort()
irc.reply(format('%L', dbs)) irc.reply(format('%L', dbs))
except socket.error, e: except socket.error as e:
irc.error(utils.web.strError(e)) irc.error(utils.web.strError(e))
dictionaries = wrap(dictionaries) dictionaries = wrap(dictionaries)
@ -71,7 +71,7 @@ class Dict(callbacks.Plugin):
conn = dictclient.Connection(server) conn = dictclient.Connection(server)
dbs = conn.getdbdescs().keys() dbs = conn.getdbdescs().keys()
irc.reply(utils.iter.choice(dbs)) irc.reply(utils.iter.choice(dbs))
except socket.error, e: except socket.error as e:
irc.error(utils.web.strError(e)) irc.error(utils.web.strError(e))
random = wrap(random) random = wrap(random)
@ -85,7 +85,7 @@ class Dict(callbacks.Plugin):
try: try:
server = conf.supybot.plugins.Dict.server() server = conf.supybot.plugins.Dict.server()
conn = dictclient.Connection(server) conn = dictclient.Connection(server)
except socket.error, e: except socket.error as e:
irc.error(utils.web.strError(e), Raise=True) irc.error(utils.web.strError(e), Raise=True)
dbs = set(conn.getdbdescs()) dbs = set(conn.getdbdescs())
if words[0] in dbs: if words[0] in dbs:
@ -139,7 +139,7 @@ class Dict(callbacks.Plugin):
try: try:
server = conf.supybot.plugins.Dict.server() server = conf.supybot.plugins.Dict.server()
conn = dictclient.Connection(server) conn = dictclient.Connection(server)
except socket.error, e: except socket.error as e:
irc.error(utils.web.strError(e), Raise=True) irc.error(utils.web.strError(e), Raise=True)
dictionary = 'moby-thes' dictionary = 'moby-thes'

View File

@ -244,7 +244,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
def getCommandHelp(self, command, simpleSyntax=None): def getCommandHelp(self, command, simpleSyntax=None):
method = self.getCommandMethod(command) method = self.getCommandMethod(command)
if method.im_func.func_name == 'learn': if method.im_func.__name__ == 'learn':
chan = None chan = None
if dynamic.msg is not None: if dynamic.msg is not None:
chan = dynamic.msg.args[0] chan = dynamic.msg.args[0]
@ -352,7 +352,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler):
return [] return []
flkeys = [line[0] for line in flkeys] flkeys = [line[0] for line in flkeys]
dl_metrics = [dameraulevenshtein(key, sourcekey) for sourcekey in flkeys] dl_metrics = [dameraulevenshtein(key, sourcekey) for sourcekey in flkeys]
dict_metrics = dict(zip(flkeys, dl_metrics)) dict_metrics = dict(list(zip(flkeys, dl_metrics)))
if min(dl_metrics) <= 2: if min(dl_metrics) <= 2:
return [key for key,item in dict_metrics.iteritems() if item <= 2] return [key for key,item in dict_metrics.iteritems() if item <= 2]
if min(dl_metrics) <= 3: if min(dl_metrics) <= 3:

View File

@ -241,8 +241,8 @@ class Filter(callbacks.Plugin):
irc.reply(text) irc.reply(text)
lithp = wrap(lithp, ['text']) lithp = wrap(lithp, ['text'])
_leettrans = utils.str.MultipleReplacer(dict(zip('oOaAeElBTiIts', _leettrans = utils.str.MultipleReplacer(dict(list(zip('oOaAeElBTiIts',
'004433187!1+5'))) '004433187!1+5'))))
_leetres = [(re.compile(r'\b(?:(?:[yY][o0O][oO0uU])|u)\b'), 'j00'), _leetres = [(re.compile(r'\b(?:(?:[yY][o0O][oO0uU])|u)\b'), 'j00'),
(re.compile(r'fear'), 'ph33r'), (re.compile(r'fear'), 'ph33r'),
(re.compile(r'[aA][tT][eE]'), '8'), (re.compile(r'[aA][tT][eE]'), '8'),
@ -416,7 +416,7 @@ class Filter(callbacks.Plugin):
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
text = text.decode('utf-8') text = text.decode('utf-8')
colors = utils.iter.cycle(['04', '07', '08', '03', '02', '12', '06']) colors = utils.iter.cycle(['04', '07', '08', '03', '02', '12', '06'])
L = [self._color(c, fg=colors.next()) for c in text] L = [self._color(c, fg=next(colors)) for c in text]
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
L = [c.encode('utf-8') for c in L] L = [c.encode('utf-8') for c in L]
irc.reply(''.join(L) + '\x03') irc.reply(''.join(L) + '\x03')
@ -662,7 +662,7 @@ class Filter(callbacks.Plugin):
irc.reply(text) irc.reply(text)
shrink = wrap(shrink, ['text']) shrink = wrap(shrink, ['text'])
_azn_trans = utils.str.MultipleReplacer(dict(zip('rlRL', 'lrLR'))) _azn_trans = utils.str.MultipleReplacer(dict(list(zip('rlRL', 'lrLR'))))
@internationalizeDocstring @internationalizeDocstring
def azn(self, irc, msg, args, text): def azn(self, irc, msg, args, text):
"""<text> """<text>

View File

@ -102,7 +102,7 @@ class Format(callbacks.Plugin):
if len(bad) != len(good): if len(bad) != len(good):
irc.error(_('<chars to translate> must be the same length as ' irc.error(_('<chars to translate> must be the same length as '
'<chars to replace those with>.'), Raise=True) '<chars to replace those with>.'), Raise=True)
irc.reply(utils.str.MultipleReplacer(dict(zip(bad, good)))(text)) irc.reply(utils.str.MultipleReplacer(dict(list(zip(bad, good))))(text))
translate = wrap(translate, ['something', 'something', 'text']) translate = wrap(translate, ['something', 'something', 'text'])
@internationalizeDocstring @internationalizeDocstring
@ -208,7 +208,7 @@ class Format(callbacks.Plugin):
try: try:
s %= tuple(args) s %= tuple(args)
irc.reply(s) irc.reply(s)
except TypeError, e: except TypeError as e:
self.log.debug(utils.exnToString(e)) self.log.debug(utils.exnToString(e))
irc.error(_('Not enough arguments for the format string.'), irc.error(_('Not enough arguments for the format string.'),
Raise=True) Raise=True)

View File

@ -30,7 +30,7 @@
import re import re
import random import random
from itertools import imap
import supybot.utils as utils import supybot.utils as utils
from supybot.commands import * from supybot.commands import *
@ -62,7 +62,7 @@ class Games(callbacks.Plugin):
For example, 2d6 will roll 2 six-sided dice; 10d10 will roll 10 For example, 2d6 will roll 2 six-sided dice; 10d10 will roll 10
ten-sided dice. ten-sided dice.
""" """
(dice, sides) = imap(int, m.groups()) (dice, sides) = list(map(int, m.groups()))
if dice > 1000: if dice > 1000:
irc.error(_('You can\'t roll more than 1000 dice.')) irc.error(_('You can\'t roll more than 1000 dice.'))
elif sides > 100: elif sides > 100:

View File

@ -120,7 +120,7 @@ class Google(callbacks.PluginRegexp):
headers=headers).decode('utf8') headers=headers).decode('utf8')
data = json.loads(text) data = json.loads(text)
if data['responseStatus'] != 200: if data['responseStatus'] != 200:
raise callbacks.Error, _('We broke The Google!') raise callbacks.Error(_('We broke The Google!'))
return data return data
def formatData(self, data, bold=True, max=0, onetoone=False): def formatData(self, data, bold=True, max=0, onetoone=False):
@ -143,7 +143,7 @@ class Google(callbacks.PluginRegexp):
results.append(url) results.append(url)
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
repl = lambda x:x if isinstance(x, unicode) else unicode(x, 'utf8') repl = lambda x:x if isinstance(x, unicode) else unicode(x, 'utf8')
results = map(repl, results) results = list(map(repl, results))
if not results: if not results:
return [_('No matches found.')] return [_('No matches found.')]
elif onetoone: elif onetoone:
@ -162,7 +162,7 @@ class Google(callbacks.PluginRegexp):
data = self.search(text, msg.args[0], {'smallsearch': True}) data = self.search(text, msg.args[0], {'smallsearch': True})
if data['responseData']['results']: if data['responseData']['results']:
url = data['responseData']['results'][0]['unescapedUrl'] url = data['responseData']['results'][0]['unescapedUrl']
if opts.has_key('snippet'): if 'snippet' in opts:
snippet = data['responseData']['results'][0]['content'] snippet = data['responseData']['results'][0]['content']
snippet = " | " + utils.web.htmlToText(snippet, tagReplace='') snippet = " | " + utils.web.htmlToText(snippet, tagReplace='')
else: else:

View File

@ -82,7 +82,7 @@ class Internet(callbacks.Plugin):
try: try:
sock = utils.net.getSocket('%s.whois-servers.net' % usertld) sock = utils.net.getSocket('%s.whois-servers.net' % usertld)
sock.connect(('%s.whois-servers.net' % usertld, 43)) sock.connect(('%s.whois-servers.net' % usertld, 43))
except socket.error, e: except socket.error as e:
irc.error(str(e)) irc.error(str(e))
return return
sock.settimeout(5) sock.settimeout(5)
@ -130,7 +130,7 @@ class Internet(callbacks.Plugin):
status = 'unknown' status = 'unknown'
try: try:
t = telnetlib.Telnet('whois.pir.org', 43) t = telnetlib.Telnet('whois.pir.org', 43)
except socket.error, e: except socket.error as e:
irc.error(str(e)) irc.error(str(e))
return return
t.write(b'registrar ') t.write(b'registrar ')

View File

@ -88,12 +88,12 @@ class SqliteKarmaDB(object):
if len(results) == 0: if len(results) == 0:
return None return None
else: else:
return map(int, results[0]) return list(map(int, results[0]))
def gets(self, channel, things): def gets(self, channel, things):
db = self._getDb(channel) db = self._getDb(channel)
cursor = db.cursor() cursor = db.cursor()
normalizedThings = dict(zip(map(lambda s: s.lower(), things), things)) normalizedThings = dict(list(zip([s.lower() for s in things], things)))
criteria = ' OR '.join(['normalized=?'] * len(normalizedThings)) criteria = ' OR '.join(['normalized=?'] * len(normalizedThings))
sql = """SELECT name, added-subtracted FROM karma sql = """SELECT name, added-subtracted FROM karma
WHERE %s ORDER BY added-subtracted DESC""" % criteria WHERE %s ORDER BY added-subtracted DESC""" % criteria
@ -167,7 +167,7 @@ class SqliteKarmaDB(object):
elif kind == 'active': elif kind == 'active':
orderby = 'added+subtracted' orderby = 'added+subtracted'
else: else:
raise ValueError, 'invalid kind' raise ValueError('invalid kind')
sql = """SELECT name, %s FROM karma ORDER BY %s DESC LIMIT %s""" % \ sql = """SELECT name, %s FROM karma ORDER BY %s DESC LIMIT %s""" % \
(orderby, orderby, limit) (orderby, orderby, limit)
db = self._getDb(channel) db = self._getDb(channel)

View File

@ -56,7 +56,7 @@ class Lart(plugins.ChannelIdDatabasePlugin):
only necessary if the message isn't sent in the channel itself. only necessary if the message isn't sent in the channel itself.
""" """
if ' for ' in text: if ' for ' in text:
(target, reason) = map(str.strip, text.split(' for ', 1)) (target, reason) = list(map(str.strip, text.split(' for ', 1)))
else: else:
(target, reason) = (text, '') (target, reason) = (text, '')
if id is not None: if id is not None:

View File

@ -69,7 +69,7 @@ class Later(callbacks.Plugin):
def _openNotes(self): def _openNotes(self):
try: try:
fd = open(self.filename) fd = open(self.filename)
except EnvironmentError, e: except EnvironmentError as e:
self.log.warning('Couldn\'t open %s: %s', self.filename, e) self.log.warning('Couldn\'t open %s: %s', self.filename, e)
return return
reader = csv.reader(fd) reader = csv.reader(fd)

View File

@ -937,12 +937,12 @@ class UnitGroup:
while tmpList: while tmpList:
count += 1 count += 1
if count > 5000: if count > 5000:
raise UnitDataError, 'Circular unit definition' raise UnitDataError('Circular unit definition')
unit = tmpList.pop(0) unit = tmpList.pop(0)
if unit.equiv == '!': if unit.equiv == '!':
self.reducedList.append(copy.copy(unit)) self.reducedList.append(copy.copy(unit))
elif not unit.equiv: elif not unit.equiv:
raise UnitDataError, 'Invalid conversion for "%s"' % unit.name raise UnitDataError('Invalid conversion for "%s"' % unit.name)
else: else:
if unit.fromEqn: if unit.fromEqn:
self.linear = 0 self.linear = 0
@ -1029,7 +1029,7 @@ class UnitGroup:
except OverflowError: except OverflowError:
return 1e9999 return 1e9999
except: except:
raise UnitDataError, 'Bad equation for %s' % self.unitList[0].name raise UnitDataError('Bad equation for %s' % self.unitList[0].name)
def convertStr(self, num, toGroup): def convertStr(self, num, toGroup):
"Return formatted string of converted number" "Return formatted string of converted number"
@ -1063,7 +1063,7 @@ class UnitData(dict):
lines = f.readlines() lines = f.readlines()
f.close() f.close()
except IOError: except IOError:
raise UnitDataError, 'Can not read "units.dat" file' raise UnitDataError('Can not read "units.dat" file')
for i in range(len(lines)): # join continuation lines for i in range(len(lines)): # join continuation lines
delta = 1 delta = 1
while lines[i].rstrip().endswith('\\'): while lines[i].rstrip().endswith('\\'):
@ -1087,7 +1087,7 @@ class UnitData(dict):
self.sortedKeys.sort() self.sortedKeys.sort()
if len(self.sortedKeys) < len(units): if len(self.sortedKeys) < len(units):
raise UnitDataError, 'Duplicate unit names found' raise UnitDataError('Duplicate unit names found')
return (types, typeUnits) return (types, typeUnits)
@ -1132,7 +1132,7 @@ class Unit:
self.toEqn = self.toEqn.strip() self.toEqn = self.toEqn.strip()
self.fromEqn = self.fromEqn.strip() self.fromEqn = self.fromEqn.strip()
except AttributeError: except AttributeError:
raise UnitDataError, 'Bad equation for "%s"' % self.name raise UnitDataError('Bad equation for "%s"' % self.name)
else: # split factor and equiv unit for linear else: # split factor and equiv unit for linear
parts = self.equiv.split(None, 1) parts = self.equiv.split(None, 1)
if len(parts) > 1 and re.search('[^\d\.eE\+\-\*/]', parts[0]) \ if len(parts) > 1 and re.search('[^\d\.eE\+\-\*/]', parts[0]) \

View File

@ -219,9 +219,9 @@ class Math(callbacks.Plugin):
irc.error(_('The answer exceeded %s or so.') % maxFloat) irc.error(_('The answer exceeded %s or so.') % maxFloat)
except TypeError: except TypeError:
irc.error(_('Something in there wasn\'t a valid number.')) 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]) irc.error(_('%s is not a defined function.') % str(e).split()[1])
except Exception, e: except Exception as e:
irc.error(str(e)) irc.error(str(e))
calc = wrap(calc, ['text']) calc = wrap(calc, ['text'])
@ -253,9 +253,9 @@ class Math(callbacks.Plugin):
irc.error(_('The answer exceeded %s or so.') % maxFloat) irc.error(_('The answer exceeded %s or so.') % maxFloat)
except TypeError: except TypeError:
irc.error(_('Something in there wasn\'t a valid number.')) 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]) irc.error(_('%s is not a defined function.') % str(e).split()[1])
except Exception, e: except Exception as e:
irc.error(utils.exnToString(e)) irc.error(utils.exnToString(e))
icalc = wrap(icalc, [('checkCapability', 'trusted'), 'text']) icalc = wrap(icalc, [('checkCapability', 'trusted'), 'text'])
@ -308,7 +308,7 @@ class Math(callbacks.Plugin):
if len(stack) == 1: if len(stack) == 1:
irc.reply(str(self._complexToString(complex(stack[0])))) irc.reply(str(self._complexToString(complex(stack[0]))))
else: else:
s = ', '.join(map(self._complexToString, map(complex, stack))) s = ', '.join(map(self._complexToString, list(map(complex, stack))))
irc.reply(_('Stack: [%s]') % s) irc.reply(_('Stack: [%s]') % s)
@internationalizeDocstring @internationalizeDocstring
@ -337,7 +337,7 @@ class Math(callbacks.Plugin):
newNum = round(newNum, digits + 1 + zeros) newNum = round(newNum, digits + 1 + zeros)
newNum = self._floatToString(newNum) newNum = self._floatToString(newNum)
irc.reply(str(newNum)) irc.reply(str(newNum))
except convertcore.UnitDataError, ude: except convertcore.UnitDataError as ude:
irc.error(str(ude)) irc.error(str(ude))
convert = wrap(convert, [optional('float', 1.0),'something','to','text']) convert = wrap(convert, [optional('float', 1.0),'something','to','text'])

View File

@ -89,9 +89,9 @@ class MathTestCase(PluginTestCase):
self.assertError('base 4 4') self.assertError('base 4 4')
self.assertError('base 10 12 A') self.assertError('base 10 12 A')
print print()
print "If we have not fixed a bug with Math.base, the following ", print("If we have not fixed a bug with Math.base, the following ")
print "tests will hang the test-suite." print("tests will hang the test-suite.")
self.assertRegexp('base 2 10 [base 10 2 -12]', '-12') self.assertRegexp('base 2 10 [base 10 2 -12]', '-12')
self.assertRegexp('base 16 2 [base 2 16 -110101]', '-110101') self.assertRegexp('base 16 2 [base 2 16 -110101]', '-110101')

View File

@ -128,7 +128,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
tokens = callbacks.tokenize(command) tokens = callbacks.tokenize(command)
try: try:
self.Proxy(irc.irc, msg, tokens) self.Proxy(irc.irc, msg, tokens)
except Exception, e: except Exception as e:
log.exception('Uncaught exception in function called by MessageParser:') log.exception('Uncaught exception in function called by MessageParser:')
def _checkManageCapabilities(self, irc, msg, channel): def _checkManageCapabilities(self, irc, msg, channel):
@ -161,7 +161,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
cursor.execute("SELECT regexp, action FROM triggers") cursor.execute("SELECT regexp, action FROM triggers")
# Fetch results and prepend channel name or 'global'. This # Fetch results and prepend channel name or 'global'. This
# prevents duplicating the following lines. # prevents duplicating the following lines.
results.extend(map(lambda x: (channel,)+x, cursor.fetchall())) results.extend([(channel,)+x for x in cursor.fetchall()])
if len(results) == 0: if len(results) == 0:
return return
max_triggers = self.registryValue('maxTriggers', channel) max_triggers = self.registryValue('maxTriggers', channel)
@ -206,14 +206,14 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
cursor.execute("SELECT id, usage_count, locked FROM triggers WHERE regexp=?", (regexp,)) cursor.execute("SELECT id, usage_count, locked FROM triggers WHERE regexp=?", (regexp,))
results = cursor.fetchall() results = cursor.fetchall()
if len(results) != 0: if len(results) != 0:
(id, usage_count, locked) = map(int, results[0]) (id, usage_count, locked) = list(map(int, results[0]))
else: else:
locked = 0 locked = 0
usage_count = 0 usage_count = 0
if not locked: if not locked:
try: try:
re.compile(regexp) re.compile(regexp)
except Exception, e: except Exception as e:
irc.error(_('Invalid python regexp: %s') % (e,)) irc.error(_('Invalid python regexp: %s') % (e,))
return return
if ircdb.users.hasUser(msg.prefix): if ircdb.users.hasUser(msg.prefix):
@ -252,7 +252,7 @@ class MessageParser(callbacks.Plugin, plugins.ChannelDBHandler):
cursor.execute(sql, (regexp,)) cursor.execute(sql, (regexp,))
results = cursor.fetchall() results = cursor.fetchall()
if len(results) != 0: if len(results) != 0:
(id, locked) = map(int, results[0]) (id, locked) = list(map(int, results[0]))
else: else:
irc.error(_('There is no such regexp trigger.')) irc.error(_('There is no such regexp trigger.'))
return return

View File

@ -34,7 +34,7 @@ import imp
import sys import sys
import json import json
import time import time
from itertools import ifilter
import supybot import supybot
@ -52,6 +52,15 @@ from supybot import commands
from supybot.i18n import PluginInternationalization, internationalizeDocstring from supybot.i18n import PluginInternationalization, internationalizeDocstring
_ = PluginInternationalization('Misc') _ = PluginInternationalization('Misc')
if sys.version_info[0] < 3:
from itertools import ifilter as filter
def get_suffix(file):
for suffix in imp.get_suffixes():
if file[-len(suffix[0]):] == suffix[0]:
return suffix
return None
def getPluginsInDirectory(directory): def getPluginsInDirectory(directory):
# get modules in a given directory # get modules in a given directory
plugins = [] plugins = []
@ -275,7 +284,7 @@ class Misc(callbacks.Plugin):
You may also want to use the 'list' command to list all available You may also want to use the 'list' command to list all available
plugins and commands. plugins and commands.
""" """
command = map(callbacks.canonicalName, command) command = list(map(callbacks.canonicalName, command))
(maxL, cbs) = irc.findCallbacksForArgs(command) (maxL, cbs) = irc.findCallbacksForArgs(command)
if maxL == command: if maxL == command:
if len(cbs) > 1: if len(cbs) > 1:
@ -313,7 +322,7 @@ class Misc(callbacks.Plugin):
newest = _('The newest versions available online are %s.') % \ newest = _('The newest versions available online are %s.') % \
', '.join([_('%s (in %s)') % (y,x) ', '.join([_('%s (in %s)') % (y,x)
for x,y in versions.items()]) 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) self.log.info('Couldn\'t get website version: %s', e)
newest = _('I couldn\'t fetch the newest version ' newest = _('I couldn\'t fetch the newest version '
'from the Limnoria repository.') 'from the Limnoria repository.')
@ -439,11 +448,11 @@ class Misc(callbacks.Plugin):
predicates.setdefault('regexp', []).append(f) predicates.setdefault('regexp', []).append(f)
elif option == 'nolimit': elif option == 'nolimit':
nolimit = True nolimit = True
iterable = ifilter(self._validLastMsg, reversed(irc.state.history)) iterable = filter(self._validLastMsg, reversed(irc.state.history))
if skipfirst: if skipfirst:
# Drop the first message only if our current channel is the same as # Drop the first message only if our current channel is the same as
# the channel we've been instructed to look at. # the channel we've been instructed to look at.
iterable.next() next(iterable)
predicates = list(utils.iter.flatten(predicates.itervalues())) predicates = list(utils.iter.flatten(predicates.itervalues()))
# Make sure the user can't get messages from channels they aren't in # Make sure the user can't get messages from channels they aren't in
def userInChannel(m): def userInChannel(m):

View File

@ -132,8 +132,8 @@ class MiscTestCase(ChannelPluginTestCase):
if network: if network:
def testVersion(self): def testVersion(self):
print '*** This test should start passing when we have our '\ print('*** This test should start passing when we have our '\
'threaded issues resolved.' 'threaded issues resolved.')
self.assertNotError('version') self.assertNotError('version')
def testSource(self): def testSource(self):

View File

@ -54,9 +54,9 @@ class OptionList(object):
return '(%s' % ''.join(ret) #) return '(%s' % ''.join(ret) #)
elif token == ')': elif token == ')':
if '|' in ret: if '|' in ret:
L = map(''.join, L = list(map(''.join,
utils.iter.split('|'.__eq__, ret, utils.iter.split('|'.__eq__, ret,
yieldEmpty=True)) yieldEmpty=True)))
return utils.iter.choice(L) return utils.iter.choice(L)
else: else:
return '(%s)' % ''.join(ret) return '(%s)' % ''.join(ret)
@ -376,8 +376,8 @@ class MoobotFactoids(callbacks.Plugin):
self.log.debug('Invalid tokens for {add,replace}Factoid: %s.', self.log.debug('Invalid tokens for {add,replace}Factoid: %s.',
tokens) tokens)
s = _('Missing an \'is\' or \'_is_\'.') s = _('Missing an \'is\' or \'_is_\'.')
raise ValueError, s raise ValueError(s)
(key, newfact) = map(' '.join, utils.iter.split(p, tokens, maxsplit=1)) (key, newfact) = list(map(' '.join, utils.iter.split(p, tokens, maxsplit=1)))
key = self._sanitizeKey(key) key = self._sanitizeKey(key)
return (key, newfact) return (key, newfact)
@ -387,7 +387,7 @@ class MoobotFactoids(callbacks.Plugin):
id = self._getUserId(irc, msg.prefix) id = self._getUserId(irc, msg.prefix)
try: try:
(key, fact) = self._getKeyAndFactoid(tokens) (key, fact) = self._getKeyAndFactoid(tokens)
except ValueError, e: except ValueError as e:
irc.error(str(e), Raise=True) irc.error(str(e), Raise=True)
# Check and make sure it's not in the DB already # Check and make sure it's not in the DB already
if self.db.getFactoid(channel, key): if self.db.getFactoid(channel, key):
@ -397,8 +397,8 @@ class MoobotFactoids(callbacks.Plugin):
def changeFactoid(self, irc, msg, tokens): def changeFactoid(self, irc, msg, tokens):
id = self._getUserId(irc, msg.prefix) id = self._getUserId(irc, msg.prefix)
(key, regexp) = map(' '.join, (key, regexp) = list(map(' '.join,
utils.iter.split('=~'.__eq__, tokens, maxsplit=1)) utils.iter.split('=~'.__eq__, tokens, maxsplit=1)))
channel = plugins.getChannel(msg.args[0]) channel = plugins.getChannel(msg.args[0])
# Check and make sure it's in the DB # Check and make sure it's in the DB
fact = self._getFactoid(irc, channel, key) fact = self._getFactoid(irc, channel, key)
@ -406,7 +406,7 @@ class MoobotFactoids(callbacks.Plugin):
# It's fair game if we get to here # It's fair game if we get to here
try: try:
r = utils.str.perlReToReplacer(regexp) r = utils.str.perlReToReplacer(regexp)
except ValueError, e: except ValueError as e:
irc.errorInvalid('regexp', regexp, Raise=True) irc.errorInvalid('regexp', regexp, Raise=True)
fact = fact[0] fact = fact[0]
new_fact = r(fact) new_fact = r(fact)
@ -436,7 +436,7 @@ class MoobotFactoids(callbacks.Plugin):
del tokens[0] # remove the "no," del tokens[0] # remove the "no,"
try: try:
(key, fact) = self._getKeyAndFactoid(tokens) (key, fact) = self._getKeyAndFactoid(tokens)
except ValueError, e: except ValueError as e:
irc.error(str(e), Raise=True) irc.error(str(e), Raise=True)
_ = self._getFactoid(irc, channel, key) _ = self._getFactoid(irc, channel, key)
self._checkNotLocked(irc, channel, key) self._checkNotLocked(irc, channel, key)

View File

@ -50,8 +50,7 @@ class Network(callbacks.Plugin):
if irc: if irc:
return irc return irc
else: else:
raise callbacks.Error, \ raise callbacks.Error('I\'m not currently connected to %s.' % network)
'I\'m not currently connected to %s.' % network
@internationalizeDocstring @internationalizeDocstring
def connect(self, irc, msg, args, opts, network, server, password): def connect(self, irc, msg, args, opts, network, server, password):

View File

@ -153,7 +153,7 @@ class News(callbacks.Plugin):
try: try:
record = self.db.get(channel, id) record = self.db.get(channel, id)
irc.reply(str(record)) irc.reply(str(record))
except dbi.NoRecordError, id: except dbi.NoRecordError as id:
irc.errorInvalid(_('news item id'), id) irc.errorInvalid(_('news item id'), id)
news = wrap(news, ['channeldb', additional('positiveInt')]) news = wrap(news, ['channeldb', additional('positiveInt')])
@ -199,7 +199,7 @@ class News(callbacks.Plugin):
try: try:
record = self.db.getOld(channel, id) record = self.db.getOld(channel, id)
irc.reply(str(record)) irc.reply(str(record))
except dbi.NoRecordError, id: except dbi.NoRecordError as id:
irc.errorInvalid(_('news item id'), id) irc.errorInvalid(_('news item id'), id)
else: else:
try: try:

View File

@ -48,10 +48,10 @@ class NewsTestCase(ChannelPluginTestCase):
self.assertRegexp('news', 'subject.*subject2') self.assertRegexp('news', 'subject.*subject2')
self.assertNotError('add 5 subject3: foo3') self.assertNotError('add 5 subject3: foo3')
self.assertRegexp('news', 'subject3') self.assertRegexp('news', 'subject3')
print print()
print 'Sleeping to expire the news item (testAddnews)' print('Sleeping to expire the news item (testAddnews)')
time.sleep(6) time.sleep(6)
print 'Done sleeping.' print('Done sleeping.')
self.assertNotRegexp('news', 'subject3') self.assertNotRegexp('news', 'subject3')
def testNews(self): def testNews(self):
@ -77,10 +77,10 @@ class NewsTestCase(ChannelPluginTestCase):
self.assertRegexp('old', 'No old news') self.assertRegexp('old', 'No old news')
self.assertNotError('add 5 foo: bar') self.assertNotError('add 5 foo: bar')
self.assertRegexp('old', 'No old news') self.assertRegexp('old', 'No old news')
print print()
print 'Sleeping to expire the news item (testOldnews)' print('Sleeping to expire the news item (testOldnews)')
time.sleep(6) time.sleep(6)
print 'Done sleeping.' print('Done sleeping.')
self.assertNotError('old') self.assertNotError('old')

View File

@ -119,8 +119,8 @@ class Nickometer(callbacks.Plugin):
('\\[rkx]0', 1000), ('\\[rkx]0', 1000),
('\\0[rkx]', 1000)] ('\\0[rkx]', 1000)]
letterNumberTranslator = utils.str.MultipleReplacer(dict(zip( letterNumberTranslator = utils.str.MultipleReplacer(dict(list(zip(
'023457+8', 'ozeasttb'))) '023457+8', 'ozeasttb'))))
for special in specialCost: for special in specialCost:
tempNick = nick tempNick = nick
if special[0][0] != '\\': if special[0][0] != '\\':
@ -145,7 +145,7 @@ class Nickometer(callbacks.Plugin):
'%s consecutive non-alphas ' % len(match)) '%s consecutive non-alphas ' % len(match))
# Remove balanced brackets ... # Remove balanced brackets ...
while 1: while True:
nickInitial = nick nickInitial = nick
nick=re.sub('^([^()]*)(\()(.*)(\))([^()]*)$', '\1\3\5', nick, 1) nick=re.sub('^([^()]*)(\()(.*)(\))([^()]*)$', '\1\3\5', nick, 1)
nick=re.sub('^([^{}]*)(\{)(.*)(\})([^{}]*)$', '\1\3\5', nick, 1) nick=re.sub('^([^{}]*)(\{)(.*)(\})([^{}]*)$', '\1\3\5', nick, 1)
@ -163,7 +163,7 @@ class Nickometer(callbacks.Plugin):
# Punish k3wlt0k # Punish k3wlt0k
k3wlt0k_weights = (5, 5, 2, 5, 2, 3, 1, 2, 2, 2) k3wlt0k_weights = (5, 5, 2, 5, 2, 3, 1, 2, 2, 2)
for i in range(len(k3wlt0k_weights)): for i in range(len(k3wlt0k_weights)):
hits=re.findall(`i`, nick) hits=re.findall(repr(i), nick)
if (hits and len(hits)>0): if (hits and len(hits)>0):
score += self.punish(k3wlt0k_weights[i] * len(hits) * 30, score += self.punish(k3wlt0k_weights[i] * len(hits) * 30,
'%s occurrences of %s ' % (len(hits), i)) '%s occurrences of %s ' % (len(hits), i))
@ -225,7 +225,7 @@ class Nickometer(callbacks.Plugin):
(1 - 1 / (1 + score / 5.0)) // 2 (1 - 1 / (1 + score / 5.0)) // 2
# if it's above 99.9%, show as many digits as is interesting # if it's above 99.9%, show as many digits as is interesting
score_string=re.sub('(99\\.9*\\d|\\.\\d).*','\\1',`percentage`) score_string=re.sub('(99\\.9*\\d|\\.\\d).*','\\1',repr(percentage))
irc.reply(_('The "lame nick-o-meter" reading for "%s" is %s%%.') % irc.reply(_('The "lame nick-o-meter" reading for "%s" is %s%%.') %
(originalNick, score_string)) (originalNick, score_string))

View File

@ -142,9 +142,9 @@ class Owner(callbacks.Plugin):
for network in conf.supybot.networks(): for network in conf.supybot.networks():
try: try:
self._connect(network) self._connect(network)
except socket.error, e: except socket.error as e:
self.log.error('Could not connect to %s: %s.', network, 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.exception('Exception connecting to %s:', network)
self.log.error('Could not connect to %s: %s.', network, e) self.log.error('Could not connect to %s: %s.', network, e)
@ -169,8 +169,8 @@ class Owner(callbacks.Plugin):
(server, port) = group.servers()[0] (server, port) = group.servers()[0]
except (registry.NonExistentRegistryEntry, IndexError): except (registry.NonExistentRegistryEntry, IndexError):
if serverPort is None: if serverPort is None:
raise ValueError, 'connect requires a (server, port) ' \ raise ValueError('connect requires a (server, port) ' \
'if the network is not registered.' 'if the network is not registered.')
conf.registerNetwork(network, password, ssl) conf.registerNetwork(network, password, ssl)
serverS = '%s:%s' % serverPort serverS = '%s:%s' % serverPort
conf.supybot.networks.get(network).servers.append(serverS) conf.supybot.networks.get(network).servers.append(serverS)
@ -209,21 +209,21 @@ class Owner(callbacks.Plugin):
m = plugin.loadPluginModule(name, m = plugin.loadPluginModule(name,
ignoreDeprecation=True) ignoreDeprecation=True)
plugin.loadPluginClass(irc, m) plugin.loadPluginClass(irc, m)
except callbacks.Error, e: except callbacks.Error as e:
# This is just an error message. # This is just an error message.
log.warning(str(e)) log.warning(str(e))
except (plugins.NoSuitableDatabase, ImportError), e: except (plugins.NoSuitableDatabase, ImportError) as e:
s = 'Failed to load %s: %s' % (name, e) s = 'Failed to load %s: %s' % (name, e)
if not s.endswith('.'): if not s.endswith('.'):
s += '.' s += '.'
log.warning(s) log.warning(s)
except Exception, e: except Exception as e:
log.exception('Failed to load %s:', name) log.exception('Failed to load %s:', name)
else: else:
# Let's import the module so configuration is preserved. # Let's import the module so configuration is preserved.
try: try:
_ = plugin.loadPluginModule(name) _ = plugin.loadPluginModule(name)
except Exception, e: except Exception as e:
log.debug('Attempted to load %s to preserve its ' log.debug('Attempted to load %s to preserve its '
'configuration, but load failed: %s', 'configuration, but load failed: %s',
name, e) name, e)
@ -267,7 +267,7 @@ class Owner(callbacks.Plugin):
try: try:
tokens = callbacks.tokenize(s, channel=msg.args[0]) tokens = callbacks.tokenize(s, channel=msg.args[0])
self.Proxy(irc, msg, tokens) self.Proxy(irc, msg, tokens)
except SyntaxError, e: except SyntaxError as e:
irc.queueMsg(callbacks.error(msg, str(e))) irc.queueMsg(callbacks.error(msg, str(e)))
def logmark(self, irc, msg, args, text): def logmark(self, irc, msg, args, text):
@ -340,7 +340,7 @@ class Owner(callbacks.Plugin):
""" """
try: try:
m = ircmsgs.IrcMsg(s) m = ircmsgs.IrcMsg(s)
except Exception, e: except Exception as e:
irc.error(utils.exnToString(e)) irc.error(utils.exnToString(e))
else: else:
irc.queueMsg(m) irc.queueMsg(m)
@ -435,7 +435,7 @@ class Owner(callbacks.Plugin):
irc.error('%s is deprecated. Use --deprecated ' irc.error('%s is deprecated. Use --deprecated '
'to force it to load.' % name.capitalize()) 'to force it to load.' % name.capitalize())
return return
except ImportError, e: except ImportError as e:
if str(e).endswith(' ' + name): if str(e).endswith(' ' + name):
irc.error('No plugin named %s exists.' % utils.str.dqrepr(name)) irc.error('No plugin named %s exists.' % utils.str.dqrepr(name))
else: else:

View File

@ -98,7 +98,7 @@ class Plugin(callbacks.Plugin):
plugin = wrap(plugin, [many('something')]) plugin = wrap(plugin, [many('something')])
def _findCallbacks(self, irc, command): def _findCallbacks(self, irc, command):
command = map(callbacks.canonicalName, command) command = list(map(callbacks.canonicalName, command))
plugin_list = [] plugin_list = []
for cb in irc.callbacks: for cb in irc.callbacks:
if not hasattr(cb, 'getCommand'): if not hasattr(cb, 'getCommand'):

View File

@ -61,7 +61,7 @@ class Praise(plugins.ChannelIdDatabasePlugin):
sent in the channel itself. sent in the channel itself.
""" """
if ' for ' in text: if ' for ' in text:
(target, reason) = map(str.strip, text.split(' for ', 1)) (target, reason) = list(map(str.strip, text.split(' for ', 1)))
else: else:
(target, reason) = (text, '') (target, reason) = (text, '')
if ircutils.strEqual(target, irc.nick): if ircutils.strEqual(target, irc.nick):

View File

@ -181,7 +181,8 @@ class RSS(callbacks.Plugin):
#oldresults = self.cachedFeeds[url] #oldresults = self.cachedFeeds[url]
#oldheadlines = self.getHeadlines(oldresults) #oldheadlines = self.getHeadlines(oldresults)
oldheadlines = self.cachedHeadlines[url] oldheadlines = self.cachedHeadlines[url]
oldheadlines = filter(lambda x: t - x[3] < self.registryValue('announce.cachePeriod'), oldheadlines) oldheadlines = list(filter(lambda x: t - x[3] <
self.registryValue('announce.cachePeriod'), oldheadlines))
except KeyError: except KeyError:
oldheadlines = [] oldheadlines = []
newresults = self.getFeed(url) newresults = self.getFeed(url)
@ -198,7 +199,7 @@ class RSS(callbacks.Plugin):
for (i, headline) in enumerate(newheadlines): for (i, headline) in enumerate(newheadlines):
if normalize(headline) in oldheadlinesset: if normalize(headline) in oldheadlinesset:
newheadlines[i] = None newheadlines[i] = None
newheadlines = filter(None, newheadlines) # Removes Nones. newheadlines = list(filter(None, newheadlines)) # Removes Nones.
number_of_headlines = len(oldheadlines) number_of_headlines = len(oldheadlines)
oldheadlines.extend(newheadlines) oldheadlines.extend(newheadlines)
self.cachedHeadlines[url] = oldheadlines self.cachedHeadlines[url] = oldheadlines
@ -228,6 +229,7 @@ class RSS(callbacks.Plugin):
channelnewheadlines = filter(filter_whitelist, channelnewheadlines) channelnewheadlines = filter(filter_whitelist, channelnewheadlines)
if len(blacklist) != 0: if len(blacklist) != 0:
channelnewheadlines = filter(filter_blacklist, channelnewheadlines) channelnewheadlines = filter(filter_blacklist, channelnewheadlines)
channelnewheadlines = list(channelnewheadlines)
if len(channelnewheadlines) == 0: if len(channelnewheadlines) == 0:
return return
bold = self.registryValue('bold', channel) bold = self.registryValue('bold', channel)
@ -284,10 +286,10 @@ class RSS(callbacks.Plugin):
raise results['bozo_exception'] raise results['bozo_exception']
except feedparser.sgmllib.SGMLParseError: except feedparser.sgmllib.SGMLParseError:
self.log.exception('Uncaught exception from feedparser:') self.log.exception('Uncaught exception from feedparser:')
raise callbacks.Error, 'Invalid (unparsable) RSS feed.' raise callbacks.Error('Invalid (unparsable) RSS feed.')
except socket.timeout: except socket.timeout:
return error('Timeout downloading feed.') return error('Timeout downloading feed.')
except Exception, e: except Exception as e:
# These seem mostly harmless. We'll need reports of a # These seem mostly harmless. We'll need reports of a
# kind that isn't. # kind that isn't.
self.log.debug('Allowing bozo_exception %r through.', e) self.log.debug('Allowing bozo_exception %r through.', e)
@ -364,7 +366,7 @@ class RSS(callbacks.Plugin):
self.locks[url] = threading.RLock() self.locks[url] = threading.RLock()
if self.isCommandMethod(name): if self.isCommandMethod(name):
s = format('I already have a command in this plugin named %s.',name) s = format('I already have a command in this plugin named %s.',name)
raise callbacks.Error, s raise callbacks.Error(s)
def f(self, irc, msg, args): def f(self, irc, msg, args):
args.insert(0, url) args.insert(0, url)
self.rss(irc, msg, args) self.rss(irc, msg, args)

View File

@ -171,8 +171,8 @@ class Relay(callbacks.Plugin):
utils.sortBy(ircutils.toLower, voices) utils.sortBy(ircutils.toLower, voices)
utils.sortBy(ircutils.toLower, halfops) utils.sortBy(ircutils.toLower, halfops)
utils.sortBy(ircutils.toLower, usersS) utils.sortBy(ircutils.toLower, usersS)
usersS = ', '.join(filter(None, map(', '.join, usersS = ', '.join(filter(None, list(map(', '.join,
(ops,halfops,voices,usersS)))) (ops,halfops,voices,usersS)))))
users.append(format('%s (%i): %s', users.append(format('%s (%i): %s',
ircutils.bold(network), numUsers, usersS)) ircutils.bold(network), numUsers, usersS))
users.sort() users.sort()

View File

@ -58,12 +58,12 @@ class Scheduler(callbacks.Plugin):
pkl = open(filename, 'rb') pkl = open(filename, 'rb')
try: try:
eventdict = pickle.load(pkl) eventdict = pickle.load(pkl)
except Exception, e: except Exception as e:
self.log.debug('Unable to load pickled data: %s', e) self.log.debug('Unable to load pickled data: %s', e)
return return
finally: finally:
pkl.close() pkl.close()
except IOError, e: except IOError as e:
self.log.debug('Unable to open pickle file: %s', e) self.log.debug('Unable to open pickle file: %s', e)
return return
for name, event in eventdict.iteritems(): for name, event in eventdict.iteritems():
@ -81,7 +81,7 @@ class Scheduler(callbacks.Plugin):
elif event['type'] == 'repeat': # repeating event elif event['type'] == 'repeat': # repeating event
self._repeat(ircobj, event['msg'], name, self._repeat(ircobj, event['msg'], name,
event['time'], event['command'], False) 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.': if str(e) == 'An event with the same name has already been scheduled.':
# we must be reloading the plugin, event is still scheduled # we must be reloading the plugin, event is still scheduled
self.log.info('Event %s already exists, adding to dict.' % (name,)) self.log.info('Event %s already exists, adding to dict.' % (name,))
@ -95,11 +95,11 @@ class Scheduler(callbacks.Plugin):
pkl = os.fdopen(pklfd, 'wb') pkl = os.fdopen(pklfd, 'wb')
try: try:
pickle.dump(self.events, pkl) pickle.dump(self.events, pkl)
except Exception, e: except Exception as e:
self.log.warning('Unable to store pickled data: %s', e) self.log.warning('Unable to store pickled data: %s', e)
pkl.close() pkl.close()
shutil.move(tempfn, filename) shutil.move(tempfn, filename)
except (IOError, shutil.Error), e: except (IOError, shutil.Error) as e:
self.log.warning('File error: %s', e) self.log.warning('File error: %s', e)
def die(self): def die(self):

View File

@ -369,7 +369,7 @@ class Seen(callbacks.Plugin):
msgs = [m for m in irc.state.history[i:end] msgs = [m for m in irc.state.history[i:end]
if m.command == 'PRIVMSG' and ircutils.strEqual(m.args[0], channel)] if m.command == 'PRIVMSG' and ircutils.strEqual(m.args[0], channel)]
if msgs: if msgs:
irc.reply(format('%L', map(ircmsgs.prettyPrint, msgs))) irc.reply(format('%L', list(map(ircmsgs.prettyPrint, msgs))))
else: else:
irc.reply(format(_('Either %s didn\'t leave, ' irc.reply(format(_('Either %s didn\'t leave, '
'or no messages were sent while %s was gone.'), nick, nick)) 'or no messages were sent while %s was gone.'), nick, nick))

View File

@ -58,8 +58,7 @@ def configure(advanced):
class ValidNickOrEmptyString(registry.String): class ValidNickOrEmptyString(registry.String):
def setValue(self, v): def setValue(self, v):
if v and not ircutils.isNick(v): if v and not ircutils.isNick(v):
raise registry.InvalidRegistryValue, \ raise registry.InvalidRegistryValue('Value must be a valid nick or the empty string.')
'Value must be a valid nick or the empty string.'
registry.String.setValue(self, v) registry.String.setValue(self, v)
class ValidNickSet(conf.ValidNicks): class ValidNickSet(conf.ValidNicks):

View File

@ -62,9 +62,8 @@ class ShrinkCycle(registry.SpaceSeparatedListOfStrings):
if L: if L:
self.lastIndex = (self.lastIndex + 1) % len(L) self.lastIndex = (self.lastIndex + 1) % len(L)
return L[self.lastIndex] return L[self.lastIndex]
raise ValueError, \ raise ValueError('No services have been configured for rotation. ' \
'No services have been configured for rotation. ' \ 'See conf.supybot.plugins.ShrinkUrl.serviceRotation.')
'See conf.supybot.plugins.ShrinkUrl.serviceRotation.'
ShrinkUrl = conf.registerPlugin('ShrinkUrl') ShrinkUrl = conf.registerPlugin('ShrinkUrl')
conf.registerChannelValue(ShrinkUrl, 'shrinkSnarfer', conf.registerChannelValue(ShrinkUrl, 'shrinkSnarfer',

View File

@ -98,7 +98,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
def callCommand(self, command, irc, msg, *args, **kwargs): def callCommand(self, command, irc, msg, *args, **kwargs):
try: try:
self.__parent.callCommand(command, irc, msg, *args, **kwargs) self.__parent.callCommand(command, irc, msg, *args, **kwargs)
except utils.web.Error, e: except utils.web.Error as e:
irc.error(str(e)) irc.error(str(e))
def _outFilterThread(self, irc, msg): def _outFilterThread(self, irc, msg):
@ -182,7 +182,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
self.db.set('ln', url, text) self.db.set('ln', url, text)
return text return text
else: else:
raise ShrinkError, text raise ShrinkError(text)
@internationalizeDocstring @internationalizeDocstring
def ln(self, irc, msg, args, url): def ln(self, irc, msg, args, url):
@ -195,7 +195,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
m = irc.reply(lnurl) m = irc.reply(lnurl)
if m is not None: if m is not None:
m.tag('shrunken') m.tag('shrunken')
except ShrinkError, e: except ShrinkError as e:
irc.error(str(e)) irc.error(str(e))
ln = thread(wrap(ln, ['url'])) ln = thread(wrap(ln, ['url']))
@ -207,7 +207,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
text = utils.web.getUrl('http://tinyurl.com/api-create.php?url=' + url) text = utils.web.getUrl('http://tinyurl.com/api-create.php?url=' + url)
text = text.decode() text = text.decode()
if text.startswith('Error'): if text.startswith('Error'):
raise ShrinkError, text[5:] raise ShrinkError(text[5:])
self.db.set('tiny', url, text) self.db.set('tiny', url, text)
return text return text
@ -222,7 +222,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
m = irc.reply(tinyurl) m = irc.reply(tinyurl)
if m is not None: if m is not None:
m.tag('shrunken') m.tag('shrunken')
except ShrinkError, e: except ShrinkError as e:
irc.errorPossibleBug(str(e)) irc.errorPossibleBug(str(e))
tiny = thread(wrap(tiny, ['url'])) tiny = thread(wrap(tiny, ['url']))
@ -236,7 +236,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
data = utils.web.urlencode({'long_url': url}) data = utils.web.urlencode({'long_url': url})
text = utils.web.getUrl(self._xrlApi, data=data).decode() text = utils.web.getUrl(self._xrlApi, data=data).decode()
if text.startswith('ERROR:'): if text.startswith('ERROR:'):
raise ShrinkError, text[6:] raise ShrinkError(text[6:])
self.db.set('xrl', quotedurl, text) self.db.set('xrl', quotedurl, text)
return text return text
@ -251,7 +251,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
m = irc.reply(xrlurl) m = irc.reply(xrlurl)
if m is not None: if m is not None:
m.tag('shrunken') m.tag('shrunken')
except ShrinkError, e: except ShrinkError as e:
irc.error(str(e)) irc.error(str(e))
xrl = thread(wrap(xrl, ['url'])) xrl = thread(wrap(xrl, ['url']))
@ -271,7 +271,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
self.db.set('goo', url, googl) self.db.set('goo', url, googl)
return googl return googl
else: else:
raise ShrinkError, text raise ShrinkError(text)
def goo(self, irc, msg, args, url): def goo(self, irc, msg, args, url):
"""<url> """<url>
@ -283,7 +283,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
m = irc.reply(goourl) m = irc.reply(goourl)
if m is not None: if m is not None:
m.tag('shrunken') m.tag('shrunken')
except ShrinkError, e: except ShrinkError as e:
irc.error(str(e)) irc.error(str(e))
goo = thread(wrap(goo, ['url'])) goo = thread(wrap(goo, ['url']))
@ -301,7 +301,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
self.db.set('ur1', url, ur1ca) self.db.set('ur1', url, ur1ca)
return ur1ca return ur1ca
else: else:
raise ShrinkError, text raise ShrinkError(text)
def ur1(self, irc, msg, args, url): def ur1(self, irc, msg, args, url):
"""<url> """<url>
@ -313,7 +313,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
m = irc.reply(ur1url) m = irc.reply(ur1url)
if m is not None: if m is not None:
m.tag('shrunken') m.tag('shrunken')
except ShrinkError, e: except ShrinkError as e:
irc.error(str(e)) irc.error(str(e))
ur1 = thread(wrap(ur1, ['url'])) ur1 = thread(wrap(ur1, ['url']))
@ -325,7 +325,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
except KeyError: except KeyError:
text = utils.web.getUrl(self._x0Api % url).decode() text = utils.web.getUrl(self._x0Api % url).decode()
if text.startswith('ERROR:'): if text.startswith('ERROR:'):
raise ShrinkError, text[6:] raise ShrinkError(text[6:])
self.db.set('x0', url, text) self.db.set('x0', url, text)
return text return text
@ -340,7 +340,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
m = irc.reply(x0url) m = irc.reply(x0url)
if m is not None: if m is not None:
m.tag('shrunken') m.tag('shrunken')
except ShrinkError, e: except ShrinkError as e:
irc.error(str(e)) irc.error(str(e))
x0 = thread(wrap(x0, ['url'])) x0 = thread(wrap(x0, ['url']))
@ -367,7 +367,7 @@ class ShrinkUrl(callbacks.PluginRegexp):
m = irc.reply(expandurl) m = irc.reply(expandurl)
if m is not None: if m is not None:
m.tag('shrunken') m.tag('shrunken')
except ShrinkError, e: except ShrinkError as e:
irc.error(str(e)) irc.error(str(e))
expand = thread(wrap(expand, ['url'])) expand = thread(wrap(expand, ['url']))

View File

@ -203,7 +203,7 @@ class String(callbacks.Plugin):
try: try:
v = process(f, text, timeout=t, pn=self.name(), cn='re') v = process(f, text, timeout=t, pn=self.name(), cn='re')
irc.reply(v) irc.reply(v)
except commands.ProcessTimeoutError, e: except commands.ProcessTimeoutError as e:
irc.error("ProcessTimeoutError: %s" % (e,)) irc.error("ProcessTimeoutError: %s" % (e,))
re = thread(wrap(re, [first('regexpMatcher', 'regexpReplacer'), re = thread(wrap(re, [first('regexpMatcher', 'regexpReplacer'),
'text'])) 'text']))
@ -216,7 +216,7 @@ class String(callbacks.Plugin):
encryption. encryption.
""" """
chars = utils.iter.cycle(password) chars = utils.iter.cycle(password)
ret = [chr(ord(c) ^ ord(chars.next())) for c in text] ret = [chr(ord(c) ^ ord(next(chars))) for c in text]
irc.reply(''.join(ret)) irc.reply(''.join(ret))
xor = wrap(xor, ['something', 'text']) xor = wrap(xor, ['something', 'text'])

View File

@ -105,7 +105,7 @@ addConverter('topicNumber', getTopicNumber)
addConverter('canChangeTopic', canChangeTopic) addConverter('canChangeTopic', canChangeTopic)
def splitTopic(topic, separator): def splitTopic(topic, separator):
return filter(None, topic.split(separator)) return list(filter(None, topic.split(separator)))
datadir = conf.supybot.directories.data() datadir = conf.supybot.directories.data()
filename = conf.supybot.directories.data.dirize('Topic.pickle') filename = conf.supybot.directories.data.dirize('Topic.pickle')
@ -125,10 +125,10 @@ class Topic(callbacks.Plugin):
self.redos = pickle.load(pkl) self.redos = pickle.load(pkl)
self.lastTopics = pickle.load(pkl) self.lastTopics = pickle.load(pkl)
self.watchingFor332 = 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) self.log.debug('Unable to load pickled data: %s', e)
pkl.close() pkl.close()
except IOError, e: except IOError as e:
self.log.debug('Unable to open pickle file: %s', e) self.log.debug('Unable to open pickle file: %s', e)
world.flushers.append(self._flush) world.flushers.append(self._flush)
@ -145,11 +145,11 @@ class Topic(callbacks.Plugin):
pickle.dump(self.redos, pkl) pickle.dump(self.redos, pkl)
pickle.dump(self.lastTopics, pkl) pickle.dump(self.lastTopics, pkl)
pickle.dump(self.watchingFor332, pkl) pickle.dump(self.watchingFor332, pkl)
except Exception, e: except Exception as e:
self.log.warning('Unable to store pickled data: %s', e) self.log.warning('Unable to store pickled data: %s', e)
pkl.close() pkl.close()
shutil.move(tempfn, filename) shutil.move(tempfn, filename)
except (IOError, shutil.Error), e: except (IOError, shutil.Error) as e:
self.log.warning('File error: %s', e) self.log.warning('File error: %s', e)
def _splitTopic(self, topic, channel): def _splitTopic(self, topic, channel):

View File

@ -153,7 +153,7 @@ class Unix(callbacks.Plugin):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=subprocess.PIPE) stdin=subprocess.PIPE)
except OSError, e: except OSError as e:
irc.error(e, Raise=True) irc.error(e, Raise=True)
ret = inst.poll() ret = inst.poll()
if ret is not None: if ret is not None:
@ -214,13 +214,13 @@ class Unix(callbacks.Plugin):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=open(os.devnull)) stdin=open(os.devnull))
except OSError, e: except OSError as e:
irc.error(_('It seems the configured fortune command was ' irc.error(_('It seems the configured fortune command was '
'not available.'), Raise=True) 'not available.'), Raise=True)
(out, err) = inst.communicate() (out, err) = inst.communicate()
inst.wait() inst.wait()
lines = out.splitlines() lines = out.splitlines()
lines = map(str.rstrip, lines) lines = list(map(str.rstrip, lines))
lines = filter(None, lines) lines = filter(None, lines)
irc.replies(lines, joiner=' ') irc.replies(lines, joiner=' ')
else: else:
@ -294,7 +294,7 @@ class Unix(callbacks.Plugin):
inst = subprocess.Popen(args, stdout=subprocess.PIPE, inst = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=open(os.devnull)) stdin=open(os.devnull))
except OSError, e: except OSError as e:
irc.error('It seems the configured ping command was ' irc.error('It seems the configured ping command was '
'not available (%s).' % e, Raise=True) 'not available (%s).' % e, Raise=True)
result = inst.communicate() result = inst.communicate()
@ -327,7 +327,7 @@ class Unix(callbacks.Plugin):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=open(os.devnull)) stdin=open(os.devnull))
except OSError, e: except OSError as e:
irc.error('It seems the configured uptime command was ' irc.error('It seems the configured uptime command was '
'not available.', Raise=True) 'not available.', Raise=True)
(out, err) = inst.communicate() (out, err) = inst.communicate()
@ -355,7 +355,7 @@ class Unix(callbacks.Plugin):
stdout=subprocess.PIPE, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=open(os.devnull)) stdin=open(os.devnull))
except OSError, e: except OSError as e:
irc.error('It seems the configured uptime command was ' irc.error('It seems the configured uptime command was '
'not available.', Raise=True) 'not available.', Raise=True)
(out, err) = inst.communicate() (out, err) = inst.communicate()
@ -384,7 +384,7 @@ class Unix(callbacks.Plugin):
inst = subprocess.Popen(args, stdout=subprocess.PIPE, inst = subprocess.Popen(args, stdout=subprocess.PIPE,
stderr=subprocess.PIPE, stderr=subprocess.PIPE,
stdin=open(os.devnull)) stdin=open(os.devnull))
except OSError, e: except OSError as e:
irc.error('It seems the requested command was ' irc.error('It seems the requested command was '
'not available (%s).' % e, Raise=True) 'not available (%s).' % e, Raise=True)
result = inst.communicate() result = inst.communicate()

View File

@ -46,7 +46,7 @@ _ = PluginInternationalization('User')
class User(callbacks.Plugin): class User(callbacks.Plugin):
def _checkNotChannel(self, irc, msg, password=' '): def _checkNotChannel(self, irc, msg, password=' '):
if password and irc.isChannel(msg.args[0]): if password and irc.isChannel(msg.args[0]):
raise callbacks.Error, conf.supybot.replies.requiresPrivacy() raise callbacks.Error(conf.supybot.replies.requiresPrivacy())
@internationalizeDocstring @internationalizeDocstring
def list(self, irc, msg, args, optlist, glob): def list(self, irc, msg, args, optlist, glob):
@ -281,7 +281,7 @@ class User(callbacks.Plugin):
command. command.
""" """
def getHostmasks(user): def getHostmasks(user):
hostmasks = map(repr, user.hostmasks) hostmasks = list(map(repr, user.hostmasks))
if hostmasks: if hostmasks:
hostmasks.sort() hostmasks.sort()
return format('%L', hostmasks) return format('%L', hostmasks)
@ -350,11 +350,11 @@ class User(callbacks.Plugin):
Raise=True) Raise=True)
try: try:
user.addHostmask(hostmask) user.addHostmask(hostmask)
except ValueError, e: except ValueError as e:
irc.error(str(e), Raise=True) irc.error(str(e), Raise=True)
try: try:
ircdb.users.setUser(user) ircdb.users.setUser(user)
except ValueError, e: except ValueError as e:
irc.error(str(e), Raise=True) irc.error(str(e), Raise=True)
except ircdb.DuplicateHostmask: except ircdb.DuplicateHostmask:
irc.error(_('That hostmask is already registered.'), irc.error(_('That hostmask is already registered.'),
@ -416,7 +416,7 @@ class User(callbacks.Plugin):
def _expire_tokens(self): def _expire_tokens(self):
now = time.time() now = time.time()
self._tokens = dict(filter(lambda (x,y): y[1]>now, self._tokens = dict(filter(lambda x_y: x_y[1][1]>now,
self._tokens.items())) self._tokens.items()))
@internationalizeDocstring @internationalizeDocstring
@ -511,7 +511,7 @@ class User(callbacks.Plugin):
prefix, expiry = self._tokens.pop(token) prefix, expiry = self._tokens.pop(token)
found = False found = False
for (id, user) in ircdb.users.items(): for (id, user) in ircdb.users.items():
if keyid in map(lambda x:x[-len(keyid):], user.gpgkeys): if keyid in [x[-len(keyid):] for x in user.gpgkeys]:
user.addAuth(msg.prefix) user.addAuth(msg.prefix)
ircdb.users.setUser(user, flush=False) ircdb.users.setUser(user, flush=False)
irc.reply(_('You are now authenticated as %s.') % irc.reply(_('You are now authenticated as %s.') %

View File

@ -75,7 +75,7 @@ class Utilities(callbacks.Plugin):
nested commands to run, but only the output of the last one to be nested commands to run, but only the output of the last one to be
returned. returned.
""" """
args = filter(None, args) args = list(filter(None, args))
if args: if args:
irc.reply(args[-1]) irc.reply(args[-1])
else: else:
@ -113,7 +113,7 @@ class Utilities(callbacks.Plugin):
try: try:
samp = random.sample(things, num) samp = random.sample(things, num)
irc.reply(' '.join(samp)) irc.reply(' '.join(samp))
except ValueError, e: except ValueError as e:
irc.error('%s' % (e,)) irc.error('%s' % (e,))
sample = wrap(sample, ['positiveInt', many('anything')]) sample = wrap(sample, ['positiveInt', many('anything')])
@ -135,7 +135,7 @@ class Utilities(callbacks.Plugin):
args = [token and token or '""' for token in rest] args = [token and token or '""' for token in rest]
text = ' '.join(args) text = ' '.join(args)
commands = command.split() commands = command.split()
commands = map(callbacks.canonicalName, commands) commands = list(map(callbacks.canonicalName, commands))
tokens = callbacks.tokenize(text) tokens = callbacks.tokenize(text)
allTokens = commands + tokens allTokens = commands + tokens
self.Proxy(irc, msg, allTokens) self.Proxy(irc, msg, allTokens)

View File

@ -93,7 +93,7 @@ def fetch_sandbox(f):
try: try:
replies = commands.process(process, self, irc, *args, replies = commands.process(process, self, irc, *args,
timeout=5, heap_size=1024*1024, timeout=5, heap_size=1024*1024,
pn=self.name(), cn=f.func_name) pn=self.name(), cn=f.__name__)
except commands.ProcessTimeoutError: except commands.ProcessTimeoutError:
raise utils.web.Error(_('Page is too big.')) raise utils.web.Error(_('Page is too big.'))
else: else:
@ -135,7 +135,7 @@ class Web(callbacks.PluginRegexp):
fd = utils.web.getUrlFd(url) fd = utils.web.getUrlFd(url)
text = fd.read(size) text = fd.read(size)
fd.close() fd.close()
except socket.timeout, e: except socket.timeout as e:
self.log.info('Couldn\'t snarf title of %u: %s.', url, e) self.log.info('Couldn\'t snarf title of %u: %s.', url, e)
if self.registryValue('snarferReportIOExceptions', channel): if self.registryValue('snarferReportIOExceptions', channel):
irc.reply(url+" : "+utils.web.TIMED_OUT, prefixNick=False) irc.reply(url+" : "+utils.web.TIMED_OUT, prefixNick=False)

View File

@ -65,9 +65,9 @@ class WebTestCase(ChannelPluginTestCase):
# part of it. # part of it.
self.assertRegexp('title http://www.n-e-r-d.com/', 'N.*E.*R.*D') self.assertRegexp('title http://www.n-e-r-d.com/', 'N.*E.*R.*D')
# Checks that the parser doesn't hang on invalid tags # Checks that the parser doesn't hang on invalid tags
print print()
print "If we have not fixed a bug with the parser, the following", print("If we have not fixed a bug with the parser, the following")
print "test will hang the test-suite." print("test will hang the test-suite.")
self.assertNotError( self.assertNotError(
'title http://www.youtube.com/watch?v=x4BtiqPN4u8') 'title http://www.youtube.com/watch?v=x4BtiqPN4u8')

View File

@ -83,7 +83,7 @@ def DB(filename, types):
return types[type](fn, *args, **kwargs) return types[type](fn, *args, **kwargs)
except KeyError: except KeyError:
continue continue
raise NoSuitableDatabase, types.keys() raise NoSuitableDatabase(types.keys())
return MakeDB return MakeDB
def makeChannelFilename(filename, channel=None, dirname=None): def makeChannelFilename(filename, channel=None, dirname=None):
@ -191,15 +191,18 @@ class ChannelUserDictionary(collections.MutableMapping):
def __init__(self): def __init__(self):
self.channels = ircutils.IrcDict() self.channels = ircutils.IrcDict()
def __getitem__(self, (channel, id)): def __getitem__(self, key):
(channel, id) = key
return self.channels[channel][id] return self.channels[channel][id]
def __setitem__(self, (channel, id), v): def __setitem__(self, key, v):
(channel, id) = key
if channel not in self.channels: if channel not in self.channels:
self.channels[channel] = self.IdDict() self.channels[channel] = self.IdDict()
self.channels[channel][id] = v self.channels[channel][id] = v
def __delitem__(self, (channel, id)): def __delitem__(self, key):
(channel, id) = key
del self.channels[channel][id] del self.channels[channel][id]
def __iter__(self): def __iter__(self):
@ -233,7 +236,7 @@ class ChannelUserDB(ChannelUserDictionary):
self.filename = filename self.filename = filename
try: try:
fd = open(self.filename) fd = open(self.filename)
except EnvironmentError, e: except EnvironmentError as e:
log.warning('Couldn\'t open %s: %s.', self.filename, e) log.warning('Couldn\'t open %s: %s.', self.filename, e)
return return
reader = csv.reader(fd) reader = csv.reader(fd)
@ -251,11 +254,11 @@ class ChannelUserDB(ChannelUserDictionary):
pass pass
v = self.deserialize(channel, id, t) v = self.deserialize(channel, id, t)
self[channel, id] = v self[channel, id] = v
except Exception, e: except Exception as e:
log.warning('Invalid line #%s in %s.', log.warning('Invalid line #%s in %s.',
lineno, self.__class__.__name__) lineno, self.__class__.__name__)
log.debug('Exception: %s', utils.exnToString(e)) 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.', log.warning('Invalid line #%s in %s.',
lineno, self.__class__.__name__) lineno, self.__class__.__name__)
log.debug('Exception: %s', utils.exnToString(e)) log.debug('Exception: %s', utils.exnToString(e))
@ -503,7 +506,7 @@ class PeriodicFileDownloader(object):
periodicFiles = None periodicFiles = None
def __init__(self): def __init__(self):
if self.periodicFiles is None: if self.periodicFiles is None:
raise ValueError, 'You must provide files to download' raise ValueError('You must provide files to download')
self.lastDownloaded = {} self.lastDownloaded = {}
self.downloadedCounter = {} self.downloadedCounter = {}
for filename in self.periodicFiles: for filename in self.periodicFiles:
@ -525,10 +528,10 @@ class PeriodicFileDownloader(object):
try: try:
try: try:
infd = utils.web.getUrlFd(url) infd = utils.web.getUrlFd(url)
except IOError, e: except IOError as e:
self.log.warning('Error downloading %s: %s', url, e) self.log.warning('Error downloading %s: %s', url, e)
return return
except utils.web.Error, e: except utils.web.Error as e:
self.log.warning('Error downloading %s: %s', url, e) self.log.warning('Error downloading %s: %s', url, e)
return return
confDir = conf.supybot.directories.data() confDir = conf.supybot.directories.data()

View File

@ -148,10 +148,17 @@ try:
def log_debug(self, msg, *args): def log_debug(self, msg, *args):
log.debug(msg, *args) log.debug(msg, *args)
fixer_names = get_fixers_from_package('lib2to3.fixes') fixer_names = ['fix_basestring',
fixer_names.remove('lib2to3.fixes.fix_import') 'fix_dict',
fixer_names += get_fixers_from_package('2to3') 'fix_imports',
r = DistutilsRefactoringTool(fixer_names, options=options) 'fix_long',
'fix_metaclass', 'fix_methodattrs',
'fix_numliterals',
'fix_types',
'fix_unicode', 'fix_urllib', 'fix_xrange']
fixers = list(map(lambda x:'lib2to3.fixes.'+x, fixer_names))
fixers += get_fixers_from_package('2to3')
r = DistutilsRefactoringTool(fixers, options=options)
r.refactor(files, write=True) r.refactor(files, write=True)
except ImportError: except ImportError:
# 2.x # 2.x

View File

@ -91,7 +91,7 @@ def _addressed(nick, msg, prefixChars=None, nicks=None,
return payload[1:].strip() return payload[1:].strip()
if nicks is None: if nicks is None:
nicks = get(conf.supybot.reply.whenAddressedBy.nicks) nicks = get(conf.supybot.reply.whenAddressedBy.nicks)
nicks = map(ircutils.toLower, nicks) nicks = list(map(ircutils.toLower, nicks))
else: else:
nicks = list(nicks) # Just in case. nicks = list(nicks) # Just in case.
nicks.insert(0, ircutils.toLower(nick)) nicks.insert(0, ircutils.toLower(nick))
@ -315,11 +315,11 @@ class Tokenizer(object):
while True: while True:
token = lexer.get_token() token = lexer.get_token()
if not token: if not token:
raise SyntaxError, _('Missing "%s". You may want to ' raise SyntaxError(_('Missing "%s". You may want to '
'quote your arguments with double ' 'quote your arguments with double '
'quotes in order to prevent extra ' 'quotes in order to prevent extra '
'brackets from being evaluated ' 'brackets from being evaluated '
'as nested commands.') % self.right 'as nested commands.') % self.right)
elif token == self.right: elif token == self.right:
return ret return ret
elif token == self.left: elif token == self.left:
@ -345,26 +345,26 @@ class Tokenizer(object):
# for strings like 'foo | bar', where a pipe stands alone as a # for strings like 'foo | bar', where a pipe stands alone as a
# token, but shouldn't be treated specially. # token, but shouldn't be treated specially.
if not args: if not args:
raise SyntaxError, _('"|" with nothing preceding. I ' raise SyntaxError(_('"|" with nothing preceding. I '
'obviously can\'t do a pipe with ' 'obviously can\'t do a pipe with '
'nothing before the |.') 'nothing before the |.'))
ends.append(args) ends.append(args)
args = [] args = []
elif token == self.left: elif token == self.left:
args.append(self._insideBrackets(lexer)) args.append(self._insideBrackets(lexer))
elif token == self.right: elif token == self.right:
raise SyntaxError, _('Spurious "%s". You may want to ' raise SyntaxError(_('Spurious "%s". You may want to '
'quote your arguments with double ' 'quote your arguments with double '
'quotes in order to prevent extra ' 'quotes in order to prevent extra '
'brackets from being evaluated ' 'brackets from being evaluated '
'as nested commands.') % self.right 'as nested commands.') % self.right)
else: else:
args.append(self._handleToken(token)) args.append(self._handleToken(token))
if ends: if ends:
if not args: if not args:
raise SyntaxError, _('"|" with nothing following. I ' raise SyntaxError(_('"|" with nothing following. I '
'obviously can\'t do a pipe with ' 'obviously can\'t do a pipe with '
'nothing after the |.') 'nothing after the |.'))
args.append(ends.pop()) args.append(ends.pop())
while ends: while ends:
args[-1].append(ends.pop()) args[-1].append(ends.pop())
@ -384,8 +384,8 @@ def tokenize(s, channel=None):
try: try:
ret = Tokenizer(brackets=brackets,pipe=pipe,quotes=quotes).tokenize(s) ret = Tokenizer(brackets=brackets,pipe=pipe,quotes=quotes).tokenize(s)
return ret return ret
except ValueError, e: except ValueError as e:
raise SyntaxError, str(e) raise SyntaxError(str(e))
def formatCommand(command): def formatCommand(command):
return ' '.join(command) return ' '.join(command)
@ -399,7 +399,7 @@ def checkCommandCapability(msg, cb, commandName):
if ircdb.checkCapability(msg.prefix, capability): if ircdb.checkCapability(msg.prefix, capability):
log.info('Preventing %s from calling %s because of %s.', log.info('Preventing %s from calling %s because of %s.',
msg.prefix, pluginCommand, capability) msg.prefix, pluginCommand, capability)
raise RuntimeError, capability raise RuntimeError(capability)
try: try:
antiPlugin = ircdb.makeAntiCapability(plugin) antiPlugin = ircdb.makeAntiCapability(plugin)
antiCommand = ircdb.makeAntiCapability(commandName) antiCommand = ircdb.makeAntiCapability(commandName)
@ -424,7 +424,7 @@ def checkCommandCapability(msg, cb, commandName):
return not (default or \ return not (default or \
any(lambda x: ircdb.checkCapability(msg.prefix, x), any(lambda x: ircdb.checkCapability(msg.prefix, x),
checkAtEnd)) checkAtEnd))
except RuntimeError, e: except RuntimeError as e:
s = ircdb.unAntiCapability(str(e)) s = ircdb.unAntiCapability(str(e))
return s return s
@ -497,7 +497,7 @@ class RichReplyMethods(object):
def _error(self, s, Raise=False, **kwargs): def _error(self, s, Raise=False, **kwargs):
if Raise: if Raise:
raise Error, s raise Error(s)
else: else:
return self.error(s, **kwargs) return self.error(s, **kwargs)
@ -598,7 +598,7 @@ class ReplyIrcProxy(RichReplyMethods):
def error(self, s, msg=None, **kwargs): def error(self, s, msg=None, **kwargs):
if 'Raise' in kwargs and kwargs['Raise']: if 'Raise' in kwargs and kwargs['Raise']:
if s: if s:
raise Error, s raise Error(s)
else: else:
raise ArgumentError raise ArgumentError
if msg is None: if msg is None:
@ -717,9 +717,9 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
log.debug('Calling %s.invalidCommand.', cb.name()) log.debug('Calling %s.invalidCommand.', cb.name())
try: try:
cb.invalidCommand(self, self.msg, self.args) cb.invalidCommand(self, self.msg, self.args)
except Error, e: except Error as e:
self.error(str(e)) self.error(str(e))
except Exception, e: except Exception as e:
log.exception('Uncaught exception in %s.invalidCommand.', log.exception('Uncaught exception in %s.invalidCommand.',
cb.name()) cb.name())
log.debug('Finished calling %s.invalidCommand.', cb.name()) log.debug('Finished calling %s.invalidCommand.', cb.name())
@ -738,7 +738,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
"""Returns a two-tuple of (command, plugins) that has the command """Returns a two-tuple of (command, plugins) that has the command
(a list of strings) and the plugins for which it was a command.""" (a list of strings) and the plugins for which it was a command."""
assert isinstance(args, list) assert isinstance(args, list)
args = map(canonicalName, args) args = list(map(canonicalName, args))
cbs = [] cbs = []
maxL = [] maxL = []
for cb in self.irc.callbacks: for cb in self.irc.callbacks:
@ -783,7 +783,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
# 3. Whether an importantPlugin is one of the responses. # 3. Whether an importantPlugin is one of the responses.
important = defaultPlugins.importantPlugins() important = defaultPlugins.importantPlugins()
important = map(canonicalName, important) important = list(map(canonicalName, important))
importants = [] importants = []
for cb in cbs: for cb in cbs:
if cb.canonicalName() in important: if cb.canonicalName() in important:
@ -992,7 +992,7 @@ class NestedCommandsIrcProxy(ReplyIrcProxy):
self.repliedTo = True self.repliedTo = True
if Raise: if Raise:
if s: if s:
raise Error, s raise Error(s)
else: else:
raise ArgumentError raise ArgumentError
if s: if s:
@ -1170,7 +1170,7 @@ class Commands(BasePlugin):
if hasattr(self, name): if hasattr(self, name):
method = getattr(self, name) method = getattr(self, name)
if inspect.ismethod(method): if inspect.ismethod(method):
code = method.im_func.func_code code = method.im_func.__code__
return inspect.getargs(code)[0] == self.commandArgs return inspect.getargs(code)[0] == self.commandArgs
else: else:
return False return False
@ -1188,7 +1188,7 @@ class Commands(BasePlugin):
return self.getCommand(command) == command return self.getCommand(command) == command
def getCommand(self, args, stripOwnName=True): def getCommand(self, args, stripOwnName=True):
assert args == map(canonicalName, args) assert args == list(map(canonicalName, args))
first = args[0] first = args[0]
for cb in self.cbs: for cb in self.cbs:
if first == cb.canonicalName(): if first == cb.canonicalName():
@ -1206,7 +1206,7 @@ class Commands(BasePlugin):
"""Gets the given command from this plugin.""" """Gets the given command from this plugin."""
#print '*** %s.getCommandMethod(%r)' % (self.name(), command) #print '*** %s.getCommandMethod(%r)' % (self.name(), command)
assert not isinstance(command, basestring) assert not isinstance(command, basestring)
assert command == map(canonicalName, command) assert command == list(map(canonicalName, command))
assert self.getCommand(command) == command assert self.getCommand(command) == command
for cb in self.cbs: for cb in self.cbs:
if command[0] == cb.canonicalName(): if command[0] == cb.canonicalName():
@ -1217,7 +1217,7 @@ class Commands(BasePlugin):
else: else:
method = getattr(self, command[0]) method = getattr(self, command[0])
if inspect.ismethod(method): if inspect.ismethod(method):
code = method.im_func.func_code code = method.im_func.__code__
if inspect.getargs(code)[0] == self.commandArgs: if inspect.getargs(code)[0] == self.commandArgs:
return method return method
else: else:
@ -1269,7 +1269,7 @@ class Commands(BasePlugin):
self.callingCommand = None self.callingCommand = None
except SilentError: except SilentError:
pass pass
except (getopt.GetoptError, ArgumentError), e: except (getopt.GetoptError, ArgumentError) as e:
self.log.debug('Got %s, giving argument error.', self.log.debug('Got %s, giving argument error.',
utils.exnToString(e)) utils.exnToString(e))
help = self.getCommandHelp(command) help = self.getCommandHelp(command)
@ -1277,10 +1277,10 @@ class Commands(BasePlugin):
irc.error(_('Invalid arguments for %s.') % method.__name__) irc.error(_('Invalid arguments for %s.') % method.__name__)
else: else:
irc.reply(help) irc.reply(help)
except (SyntaxError, Error), e: except (SyntaxError, Error) as e:
self.log.debug('Error return: %s', utils.exnToString(e)) self.log.debug('Error return: %s', utils.exnToString(e))
irc.error(str(e)) irc.error(str(e))
except Exception, e: except Exception as e:
self.log.exception('Uncaught exception in %s.', command) self.log.exception('Uncaught exception in %s.', command)
if conf.supybot.reply.error.detailed(): if conf.supybot.reply.error.detailed():
irc.error(utils.exnToString(e)) irc.error(utils.exnToString(e))
@ -1444,9 +1444,9 @@ class PluginRegexp(Plugin):
method = getattr(self, name) method = getattr(self, name)
try: try:
method(irc, msg, m) method(irc, msg, m)
except Error, e: except Error as e:
irc.error(str(e)) irc.error(str(e))
except Exception, e: except Exception as e:
self.log.exception('Uncaught exception in _callRegexp:') self.log.exception('Uncaught exception in _callRegexp:')
def invalidCommand(self, irc, msg, tokens): def invalidCommand(self, irc, msg, tokens):

View File

@ -80,7 +80,7 @@ def open_db(filename, mode='r', **kwargs):
maker.finish() maker.finish()
return ReaderWriter(filename, **kwargs) return ReaderWriter(filename, **kwargs)
else: else:
raise ValueError, 'Invalid flag: %s' % mode raise ValueError('Invalid flag: %s' % mode)
def shelf(filename, *args, **kwargs): def shelf(filename, *args, **kwargs):
"""Opens a new shelf database object.""" """Opens a new shelf database object."""
@ -118,7 +118,7 @@ def make(dbFilename, readFilename=None):
else: else:
readfd = open(readFilename, 'rb') readfd = open(readFilename, 'rb')
maker = Maker(dbFilename) maker = Maker(dbFilename)
while 1: while True:
(initchar, key, value) = _readKeyValue(readfd) (initchar, key, value) = _readKeyValue(readfd)
if initchar is None: if initchar is None:
break break
@ -257,7 +257,7 @@ class Reader(utils.IterableMap):
try: try:
return self.default return self.default
except AttributeError: except AttributeError:
raise KeyError, key raise KeyError(key)
def findall(self, key): def findall(self, key):
ret = [] ret = []
@ -318,7 +318,7 @@ class ReaderWriter(utils.IterableMap):
adds = {} adds = {}
try: try:
fd = open(self.journalName, 'r') fd = open(self.journalName, 'r')
while 1: while True:
(initchar, key, value) = _readKeyValue(fd) (initchar, key, value) = _readKeyValue(fd)
if initchar is None: if initchar is None:
break break
@ -377,7 +377,7 @@ class ReaderWriter(utils.IterableMap):
def __getitem__(self, key): def __getitem__(self, key):
if key in self.removals: if key in self.removals:
raise KeyError, key raise KeyError(key)
else: else:
try: try:
return self.adds[key] return self.adds[key]
@ -386,7 +386,7 @@ class ReaderWriter(utils.IterableMap):
def __delitem__(self, key): def __delitem__(self, key):
if key in self.removals: if key in self.removals:
raise KeyError, key raise KeyError(key)
else: else:
if key in self.adds and key in self.cdb: if key in self.adds and key in self.cdb:
self._journalRemoveKey(key) self._journalRemoveKey(key)
@ -398,7 +398,7 @@ class ReaderWriter(utils.IterableMap):
elif key in self.cdb: elif key in self.cdb:
self._journalRemoveKey(key) self._journalRemoveKey(key)
else: else:
raise KeyError, key raise KeyError(key)
self.mods += 1 self.mods += 1
self._flushIfOverLimit() self._flushIfOverLimit()

View File

@ -67,7 +67,7 @@ def thread(f):
t.start() t.start()
else: else:
f(self, irc, msg, args, *L, **kwargs) f(self, irc, msg, args, *L, **kwargs)
return utils.python.changeFunctionName(newf, f.func_name, f.__doc__) return utils.python.changeFunctionName(newf, f.__name__, f.__doc__)
class ProcessTimeoutError(Exception): class ProcessTimeoutError(Exception):
"""Gets raised when a process is killed due to timeout.""" """Gets raised when a process is killed due to timeout."""
@ -121,7 +121,7 @@ def process(f, *args, **kwargs):
p.join(timeout) p.join(timeout)
if p.is_alive(): if p.is_alive():
p.terminate() p.terminate()
raise ProcessTimeoutError, "%s aborted due to timeout." % (p.name,) raise ProcessTimeoutError("%s aborted due to timeout." % (p.name,))
try: try:
v = q.get(block=False) v = q.get(block=False)
except Queue.Empty: except Queue.Empty:
@ -160,7 +160,7 @@ class UrlSnarfThread(world.SupyThread):
def run(self): def run(self):
try: try:
super(UrlSnarfThread, self).run() super(UrlSnarfThread, self).run()
except utils.web.Error, e: except utils.web.Error as e:
log.debug('Exception in urlSnarfer: %s', utils.exnToString(e)) log.debug('Exception in urlSnarfer: %s', utils.exnToString(e))
class SnarfQueue(ircutils.FloodQueue): class SnarfQueue(ircutils.FloodQueue):
@ -219,7 +219,7 @@ def urlSnarfer(f):
L = list(L) L = list(L)
t = UrlSnarfThread(target=doSnarf, url=url) t = UrlSnarfThread(target=doSnarf, url=url)
t.start() t.start()
newf = utils.python.changeFunctionName(newf, f.func_name, f.__doc__) newf = utils.python.changeFunctionName(newf, f.__name__, f.__doc__)
return newf return newf
@ -301,7 +301,7 @@ def getId(irc, msg, args, state, kind=None):
try: try:
args[0] = args[0].lstrip('#') args[0] = args[0].lstrip('#')
getInt(irc, msg, args, state, type=type) getInt(irc, msg, args, state, type=type)
except Exception, e: except Exception as e:
args[0] = original args[0] = original
raise raise
@ -798,8 +798,8 @@ class UnknownConverter(KeyError):
def getConverter(name): def getConverter(name):
try: try:
return wrappers[name] return wrappers[name]
except KeyError, e: except KeyError as e:
raise UnknownConverter, str(e) raise UnknownConverter(str(e))
def callConverter(name, irc, msg, args, state, *L): def callConverter(name, irc, msg, args, state, *L):
getConverter(name)(irc, msg, args, state, *L) getConverter(name)(irc, msg, args, state, *L)
@ -852,7 +852,7 @@ class rest(context):
args[:] = [' '.join(args)] args[:] = [' '.join(args)]
try: try:
super(rest, self).__call__(irc, msg, args, state) super(rest, self).__call__(irc, msg, args, state)
except Exception, e: except Exception as e:
args[:] = original args[:] = original
else: else:
raise IndexError raise IndexError
@ -878,7 +878,7 @@ class optional(additional):
def __call__(self, irc, msg, args, state): def __call__(self, irc, msg, args, state):
try: try:
super(optional, self).__call__(irc, msg, args, state) 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)) log.debug('Got %s, returning default.', utils.exnToString(e))
state.errored = False state.errored = False
setDefault(state, self.default) setDefault(state, self.default)
@ -896,7 +896,7 @@ class any(context):
self.__parent.__call__(irc, msg, args, st) self.__parent.__call__(irc, msg, args, st)
except IndexError: except IndexError:
pass pass
except (callbacks.ArgumentError, callbacks.Error), e: except (callbacks.ArgumentError, callbacks.Error) as e:
if not self.continueOnError: if not self.continueOnError:
raise raise
else: else:
@ -917,7 +917,7 @@ class first(context):
self.default = kw.pop('default') self.default = kw.pop('default')
assert not kw, 'Bad kwargs for first.__init__' assert not kw, 'Bad kwargs for first.__init__'
self.spec = specs # for __repr__ self.spec = specs # for __repr__
self.specs = map(contextify, specs) self.specs = list(map(contextify, specs))
def __call__(self, irc, msg, args, state): def __call__(self, irc, msg, args, state):
errored = False errored = False
@ -925,7 +925,7 @@ class first(context):
try: try:
spec(irc, msg, args, state) spec(irc, msg, args, state)
return return
except Exception, e: except Exception as e:
e2 = e # 'e' is local. e2 = e # 'e' is local.
errored = state.errored errored = state.errored
state.errored = False state.errored = False
@ -956,7 +956,7 @@ class commalist(context):
if part: # trailing commas if part: # trailing commas
super(commalist, self).__call__(irc, msg, [part], st) super(commalist, self).__call__(irc, msg, [part], st)
state.args.append(st.args) state.args.append(st.args)
except Exception, e: except Exception as e:
args[:] = original args[:] = original
raise raise
@ -1024,7 +1024,7 @@ class State(object):
self.errored = True self.errored = True
return getattr(dynamic.irc, attr) return getattr(dynamic.irc, attr)
else: else:
raise AttributeError, attr raise AttributeError(attr)
def essence(self): def essence(self):
st = State(self.types) st = State(self.types)
@ -1068,7 +1068,7 @@ class Spec(object):
return state return state
def _wrap(f, specList=[], name=None, checkDoc=True, **kw): def _wrap(f, specList=[], name=None, checkDoc=True, **kw):
name = name or f.func_name name = name or f.__name__
assert (not checkDoc) or (hasattr(f, '__doc__') and f.__doc__), \ assert (not checkDoc) or (hasattr(f, '__doc__') and f.__doc__), \
'Command %r has no docstring.' % name 'Command %r has no docstring.' % name
spec = Spec(specList, **kw) spec = Spec(specList, **kw)
@ -1083,7 +1083,7 @@ def _wrap(f, specList=[], name=None, checkDoc=True, **kw):
except TypeError: except TypeError:
self.log.error('Spec: %s', specList) self.log.error('Spec: %s', specList)
self.log.error('Received args: %s', args) self.log.error('Received args: %s', args)
code = f.func_code code = f.__code__
funcArgs = inspect.getargs(code)[0][len(self.commandArgs):] funcArgs = inspect.getargs(code)[0][len(self.commandArgs):]
self.log.error('Extra args: %s', funcArgs) self.log.error('Extra args: %s', funcArgs)
self.log.debug('Make sure you did not wrap a wrapped ' self.log.debug('Make sure you did not wrap a wrapped '

View File

@ -839,7 +839,7 @@ class Databases(registry.SpaceSeparatedListOfStrings):
def __call__(self): def __call__(self):
v = super(Databases, self).__call__() v = super(Databases, self).__call__()
if not v: if not v:
v = ['anydbm', 'cdb', 'flat', 'pickle'] v = ['anydbm', 'dbm', 'cdb', 'flat', 'pickle']
if 'sqlite' in sys.modules: if 'sqlite' in sys.modules:
v.insert(0, 'sqlite') v.insert(0, 'sqlite')
if 'sqlite3' in sys.modules: if 'sqlite3' in sys.modules:

View File

@ -117,7 +117,7 @@ class DirMapping(MappingInterface):
try: try:
fd = open(self._makeFilename(id)) fd = open(self._makeFilename(id))
return fd.read() return fd.read()
except EnvironmentError, e: except EnvironmentError as e:
exn = NoRecordError(id) exn = NoRecordError(id)
exn.realException = e exn.realException = e
raise exn raise exn
@ -141,8 +141,8 @@ class DirMapping(MappingInterface):
def remove(self, id): def remove(self, id):
try: try:
os.remove(self._makeFilename(id)) os.remove(self._makeFilename(id))
except EnvironmentError, e: except EnvironmentError as e:
raise NoRecordError, id raise NoRecordError(id)
class FlatfileMapping(MappingInterface): class FlatfileMapping(MappingInterface):
def __init__(self, filename, maxSize=10**6): def __init__(self, filename, maxSize=10**6):
@ -154,8 +154,8 @@ class FlatfileMapping(MappingInterface):
try: try:
self.currentId = int(strId) self.currentId = int(strId)
except ValueError: except ValueError:
raise Error, 'Invalid file for FlatfileMapping: %s' % filename raise Error('Invalid file for FlatfileMapping: %s' % filename)
except EnvironmentError, e: except EnvironmentError as e:
# File couldn't be opened. # File couldn't be opened.
self.maxSize = int(math.log10(maxSize)) self.maxSize = int(math.log10(maxSize))
self.currentId = 0 self.currentId = 0
@ -209,7 +209,7 @@ class FlatfileMapping(MappingInterface):
(lineId, s) = self._splitLine(line) (lineId, s) = self._splitLine(line)
if lineId == strId: if lineId == strId:
return s return s
raise NoRecordError, id raise NoRecordError(id)
finally: finally:
fd.close() fd.close()
@ -295,7 +295,7 @@ class CdbMapping(MappingInterface):
try: try:
return self.db[str(id)] return self.db[str(id)]
except KeyError: except KeyError:
raise NoRecordError, id raise NoRecordError(id)
# XXX Same as above. # XXX Same as above.
def set(self, id, s): def set(self, id, s):

View File

@ -82,7 +82,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
self.writeCheckTime = None self.writeCheckTime = None
self.nextReconnectTime = None self.nextReconnectTime = None
self.resetDelay() self.resetDelay()
if self.networkGroup.get('ssl').value and not globals().has_key('ssl'): if self.networkGroup.get('ssl').value and 'ssl' not in globals():
drivers.log.error('The Socket driver can not connect to SSL ' drivers.log.error('The Socket driver can not connect to SSL '
'servers for your Python version. Try the ' 'servers for your Python version. Try the '
'Twisted driver instead, or install a Python' 'Twisted driver instead, or install a Python'
@ -131,7 +131,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
while msgs[-1] is not None: while msgs[-1] is not None:
msgs.append(self.irc.takeMsg()) msgs.append(self.irc.takeMsg())
del msgs[-1] del msgs[-1]
self.outbuffer += ''.join(imap(str, msgs)) self.outbuffer += ''.join(map(str, msgs))
if self.outbuffer: if self.outbuffer:
try: try:
if sys.version_info[0] < 3: if sys.version_info[0] < 3:
@ -140,7 +140,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
sent = self.conn.send(self.outbuffer.encode()) sent = self.conn.send(self.outbuffer.encode())
self.outbuffer = self.outbuffer[sent:] self.outbuffer = self.outbuffer[sent:]
self.eagains = 0 self.eagains = 0
except socket.error, e: except socket.error as e:
self._handleSocketError(e) self._handleSocketError(e)
if self.zombie and not self.outbuffer: if self.zombie and not self.outbuffer:
self._reallyDie() self._reallyDie()
@ -233,13 +233,13 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
self.irc.feedMsg(msg) self.irc.feedMsg(msg)
except socket.timeout: except socket.timeout:
pass pass
except SSLError, e: except SSLError as e:
if e.args[0] == 'The read operation timed out': if e.args[0] == 'The read operation timed out':
pass pass
else: else:
self._handleSocketError(e) self._handleSocketError(e)
return return
except socket.error, e: except socket.error as e:
self._handleSocketError(e) self._handleSocketError(e)
return return
if self.irc and not self.irc.zombie: 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) self.conn = utils.net.getSocket(address, socks_proxy)
vhost = conf.supybot.protocols.irc.vhost() vhost = conf.supybot.protocols.irc.vhost()
self.conn.bind((vhost, 0)) self.conn.bind((vhost, 0))
except socket.error, e: except socket.error as e:
drivers.log.connectError(self.currentServer, e) drivers.log.connectError(self.currentServer, e)
self.scheduleReconnect() self.scheduleReconnect()
return return
@ -304,7 +304,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
self.conn.settimeout(max(10, conf.supybot.drivers.poll()*10)) self.conn.settimeout(max(10, conf.supybot.drivers.poll()*10))
try: try:
if getattr(conf.supybot.networks, self.irc.network).ssl(): if getattr(conf.supybot.networks, self.irc.network).ssl():
assert globals().has_key('ssl') assert 'ssl' in globals()
certfile = getattr(conf.supybot.networks, self.irc.network) \ certfile = getattr(conf.supybot.networks, self.irc.network) \
.certfile() .certfile()
if not certfile: if not certfile:
@ -321,7 +321,7 @@ class SocketDriver(drivers.IrcDriver, drivers.ServersMixin):
setTimeout() setTimeout()
self.connected = True self.connected = True
self.resetDelay() self.resetDelay()
except socket.error, e: except socket.error as e:
if e.args[0] == 115: if e.args[0] == 115:
now = time.time() now = time.time()
when = now + 60 when = now + 60

View File

@ -36,7 +36,7 @@ class DynamicScope(object):
if name in f.f_locals: if name in f.f_locals:
return f.f_locals return f.f_locals
f = f.f_back f = f.f_back
raise NameError, name raise NameError(name)
def __getattr__(self, name): def __getattr__(self, name):
try: try:

View File

@ -183,7 +183,7 @@ def parse(translationFile):
i18nSupybot = None i18nSupybot = None
def PluginInternationalization(name='supybot'): def PluginInternationalization(name='supybot'):
# This is a proxy that prevents having several objects for the same plugin # This is a proxy that prevents having several objects for the same plugin
if i18nClasses.has_key(name): if name in i18nClasses:
return i18nClasses[name] return i18nClasses[name]
else: else:
return _PluginInternationalization(name) return _PluginInternationalization(name)
@ -282,8 +282,10 @@ class _PluginInternationalization:
load its functions.""" load its functions."""
if self.name != 'supybot': if self.name != 'supybot':
return return
path = self._getL10nCodePath()
try: try:
execfile(self._getL10nCodePath()) with open(path) as fd:
exec(compile(fd.read(), path, 'exec'))
except IOError: # File doesn't exist except IOError: # File doesn't exist
pass pass
@ -308,7 +310,7 @@ class _PluginInternationalization:
if self.name != 'supybot': if self.name != 'supybot':
return return
if hasattr(self, '_l10nFunctions') and \ if hasattr(self, '_l10nFunctions') and \
self._l10nFunctions.has_key(name): name in self._l10nFunctions:
return self._l10nFunctions[name] return self._l10nFunctions[name]
def internationalizeFunction(self, name): def internationalizeFunction(self, name):
@ -357,7 +359,7 @@ def internationalizeDocstring(obj):
Only useful for commands (commands' docstring is displayed on IRC)""" Only useful for commands (commands' docstring is displayed on IRC)"""
if obj.__doc__ == None: if obj.__doc__ == None:
return obj return obj
if sys.modules[obj.__module__].__dict__.has_key('_'): if '_' in sys.modules[obj.__module__].__dict__:
internationalizedCommands.update({hash(obj): obj}) internationalizedCommands.update({hash(obj): obj})
try: try:
obj.__doc__=sys.modules[obj.__module__]._.__call__(obj.__doc__) obj.__doc__=sys.modules[obj.__module__]._.__call__(obj.__doc__)

View File

@ -80,7 +80,7 @@ def unAntiCapability(capability):
"""Takes an anticapability and returns the non-anti form.""" """Takes an anticapability and returns the non-anti form."""
assert isCapability(capability), 'got %s' % capability assert isCapability(capability), 'got %s' % capability
if not isAntiCapability(capability): if not isAntiCapability(capability):
raise ValueError, '%s is not an anti capability' % capability raise ValueError('%s is not an anti capability' % capability)
if isChannelCapability(capability): if isChannelCapability(capability):
(channel, capability) = fromChannelCapability(capability) (channel, capability) = fromChannelCapability(capability)
return ','.join((channel, capability[1:])) return ','.join((channel, capability[1:]))
@ -150,7 +150,7 @@ class CapabilitySet(set):
def __repr__(self): def __repr__(self):
return '%s([%s])' % (self.__class__.__name__, return '%s([%s])' % (self.__class__.__name__,
', '.join(imap(repr, self))) ', '.join(map(repr, self)))
antiOwner = makeAntiCapability('owner') antiOwner = makeAntiCapability('owner')
class UserCapabilitySet(CapabilitySet): class UserCapabilitySet(CapabilitySet):
@ -290,8 +290,7 @@ class IrcUser(object):
"""Adds a hostmask to the user's hostmasks.""" """Adds a hostmask to the user's hostmasks."""
assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask assert ircutils.isUserHostmask(hostmask), 'got %s' % hostmask
if len(unWildcardHostmask(hostmask)) < 3: if len(unWildcardHostmask(hostmask)) < 3:
raise ValueError, \ raise ValueError('Hostmask must contain at least 3 non-wildcard characters.')
'Hostmask must contain at least 3 non-wildcard characters.'
self.hostmasks.add(hostmask) self.hostmasks.add(hostmask)
def removeHostmask(self, hostmask): def removeHostmask(self, hostmask):
@ -334,10 +333,10 @@ class IrcUser(object):
knownHostmasks.add(mask) knownHostmasks.add(mask)
return True return True
return False return False
uniqued = filter(uniqueHostmask, reversed(self.auth)) uniqued = list(filter(uniqueHostmask, reversed(self.auth)))
self.auth = list(reversed(uniqued)) self.auth = list(reversed(uniqued))
else: else:
raise ValueError, 'secure flag set, unmatched hostmask' raise ValueError('secure flag set, unmatched hostmask')
def clearAuth(self): def clearAuth(self):
"""Unsets a user's authenticated hostmask.""" """Unsets a user's authenticated hostmask."""
@ -492,7 +491,7 @@ class IrcChannel(object):
class Creator(object): class Creator(object):
def badCommand(self, command, rest, lineno): def badCommand(self, command, rest, lineno):
raise ValueError, 'Invalid command on line %s: %s' % (lineno, command) raise ValueError('Invalid command on line %s: %s' % (lineno, command))
class IrcUserCreator(Creator): class IrcUserCreator(Creator):
u = None u = None
@ -503,12 +502,12 @@ class IrcUserCreator(Creator):
def user(self, rest, lineno): def user(self, rest, lineno):
if self.u.id is not None: if self.u.id is not None:
raise ValueError, 'Unexpected user command on line %s.' % lineno raise ValueError('Unexpected user command on line %s.' % lineno)
self.u.id = int(rest) self.u.id = int(rest)
def _checkId(self): def _checkId(self):
if self.u.id is None: if self.u.id is None:
raise ValueError, 'Unexpected user description without user.' raise ValueError('Unexpected user description without user.')
def name(self, rest, lineno): def name(self, rest, lineno):
self._checkId() self._checkId()
@ -571,12 +570,12 @@ class IrcChannelCreator(Creator):
def channel(self, rest, lineno): def channel(self, rest, lineno):
if self.name is not None: if self.name is not None:
raise ValueError, 'Unexpected channel command on line %s' % lineno raise ValueError('Unexpected channel command on line %s' % lineno)
IrcChannelCreator.name = rest IrcChannelCreator.name = rest
def _checkId(self): def _checkId(self):
if self.name is None: if self.name is None:
raise ValueError, 'Unexpected channel description without channel.' raise ValueError('Unexpected channel description without channel.')
def lobotomized(self, rest, lineno): def lobotomized(self, rest, lineno):
self._checkId() self._checkId()
@ -629,10 +628,10 @@ class UsersDictionary(utils.IterableMap):
reader.readFile(filename) reader.readFile(filename)
self.noFlush = False self.noFlush = False
self.flush() self.flush()
except EnvironmentError, e: except EnvironmentError as e:
log.error('Invalid user dictionary file, resetting to empty.') log.error('Invalid user dictionary file, resetting to empty.')
log.error('Exact error: %s', utils.exnToString(e)) log.error('Exact error: %s', utils.exnToString(e))
except Exception, e: except Exception as e:
log.exception('Exact error:') log.exception('Exact error:')
finally: finally:
self.noFlush = False self.noFlush = False
@ -646,7 +645,7 @@ class UsersDictionary(utils.IterableMap):
if self.filename is not None: if self.filename is not None:
try: try:
self.open(self.filename) self.open(self.filename)
except EnvironmentError, e: except EnvironmentError as e:
log.warning('UsersDictionary.reload failed: %s', e) log.warning('UsersDictionary.reload failed: %s', e)
else: else:
log.error('UsersDictionary.reload called with no filename.') log.error('UsersDictionary.reload called with no filename.')
@ -697,14 +696,14 @@ class UsersDictionary(utils.IterableMap):
self._hostmaskCache[id] = set([s]) self._hostmaskCache[id] = set([s])
return id return id
elif len(ids) == 0: elif len(ids) == 0:
raise KeyError, s raise KeyError(s)
else: else:
log.error('Multiple matches found in user database. ' log.error('Multiple matches found in user database. '
'Removing the offending hostmasks.') 'Removing the offending hostmasks.')
for (id, hostmask) in ids.iteritems(): for (id, hostmask) in ids.iteritems():
log.error('Removing %q from user %s.', hostmask, id) log.error('Removing %q from user %s.', hostmask, id)
self.users[id].removeHostmask(hostmask) self.users[id].removeHostmask(hostmask)
raise DuplicateHostmask, 'Ids %r matched.' % ids raise DuplicateHostmask('Ids %r matched.' % ids)
else: # Not a hostmask, must be a name. else: # Not a hostmask, must be a name.
s = s.lower() s = s.lower()
try: try:
@ -716,7 +715,7 @@ class UsersDictionary(utils.IterableMap):
self._nameCache[id] = s self._nameCache[id] = s
return id return id
else: else:
raise KeyError, s raise KeyError(s)
def getUser(self, id): def getUser(self, id):
"""Returns a user given its id, name, or hostmask.""" """Returns a user given its id, name, or hostmask."""
@ -775,7 +774,7 @@ class UsersDictionary(utils.IterableMap):
self.nextId = max(self.nextId, user.id) self.nextId = max(self.nextId, user.id)
try: try:
if self.getUserId(user.name) != user.id: if self.getUserId(user.name) != user.id:
raise DuplicateHostmask, hostmask raise DuplicateHostmask(hostmask)
except KeyError: except KeyError:
pass pass
for hostmask in user.hostmasks: for hostmask in user.hostmasks:
@ -788,10 +787,10 @@ class UsersDictionary(utils.IterableMap):
# raise an exception. So instead, we'll raise an # raise an exception. So instead, we'll raise an
# exception, but be nice and give the offending hostmask # exception, but be nice and give the offending hostmask
# back at the same time. # back at the same time.
raise DuplicateHostmask, hostmask raise DuplicateHostmask(hostmask)
for otherHostmask in u.hostmasks: for otherHostmask in u.hostmasks:
if ircutils.hostmaskPatternEqual(hostmask, otherHostmask): if ircutils.hostmaskPatternEqual(hostmask, otherHostmask):
raise DuplicateHostmask, hostmask raise DuplicateHostmask(hostmask)
self.invalidateCache(user.id) self.invalidateCache(user.id)
self.users[user.id] = user self.users[user.id] = user
if flush: if flush:
@ -835,10 +834,10 @@ class ChannelsDictionary(utils.IterableMap):
reader.readFile(filename) reader.readFile(filename)
self.noFlush = False self.noFlush = False
self.flush() self.flush()
except EnvironmentError, e: except EnvironmentError as e:
log.error('Invalid channel database, resetting to empty.') log.error('Invalid channel database, resetting to empty.')
log.error('Exact error: %s', utils.exnToString(e)) log.error('Exact error: %s', utils.exnToString(e))
except Exception, e: except Exception as e:
log.error('Invalid channel database, resetting to empty.') log.error('Invalid channel database, resetting to empty.')
log.exception('Exact error:') log.exception('Exact error:')
finally: finally:
@ -871,7 +870,7 @@ class ChannelsDictionary(utils.IterableMap):
self.channels.clear() self.channels.clear()
try: try:
self.open(self.filename) self.open(self.filename)
except EnvironmentError, e: except EnvironmentError as e:
log.warning('ChannelsDictionary.reload failed: %s', e) log.warning('ChannelsDictionary.reload failed: %s', e)
else: else:
log.warning('ChannelsDictionary.reload without self.filename.') log.warning('ChannelsDictionary.reload without self.filename.')
@ -914,7 +913,7 @@ class IgnoresDB(object):
else: else:
expiration = 0 expiration = 0
self.add(hostmask, expiration) self.add(hostmask, expiration)
except Exception, e: except Exception as e:
log.error('Invalid line in ignores database: %q', line) log.error('Invalid line in ignores database: %q', line)
fd.close() fd.close()
@ -942,7 +941,7 @@ class IgnoresDB(object):
self.hostmasks.clear() self.hostmasks.clear()
try: try:
self.open(self.filename) self.open(self.filename)
except EnvironmentError, e: except EnvironmentError as e:
log.warning('IgnoresDB.reload failed: %s', e) log.warning('IgnoresDB.reload failed: %s', e)
# Let's be somewhat transactional. # Let's be somewhat transactional.
self.hostmasks.update(oldhostmasks) self.hostmasks.update(oldhostmasks)
@ -972,7 +971,7 @@ try:
userFile = os.path.join(confDir, conf.supybot.databases.users.filename()) userFile = os.path.join(confDir, conf.supybot.databases.users.filename())
users = UsersDictionary() users = UsersDictionary()
users.open(userFile) users.open(userFile)
except EnvironmentError, e: except EnvironmentError as e:
log.warning('Couldn\'t open user database: %s', e) log.warning('Couldn\'t open user database: %s', e)
try: try:
@ -980,7 +979,7 @@ try:
conf.supybot.databases.channels.filename()) conf.supybot.databases.channels.filename())
channels = ChannelsDictionary() channels = ChannelsDictionary()
channels.open(channelFile) channels.open(channelFile)
except EnvironmentError, e: except EnvironmentError as e:
log.warning('Couldn\'t open channel database: %s', e) log.warning('Couldn\'t open channel database: %s', e)
try: try:
@ -988,7 +987,7 @@ try:
conf.supybot.databases.ignores.filename()) conf.supybot.databases.ignores.filename())
ignores = IgnoresDB() ignores = IgnoresDB()
ignores.open(ignoreFile) ignores.open(ignoreFile)
except EnvironmentError, e: except EnvironmentError as e:
log.warning('Couldn\'t open ignore database: %s', e) log.warning('Couldn\'t open ignore database: %s', e)
@ -1084,7 +1083,7 @@ def checkCapability(hostmask, capability, users=users, channels=channels,
# Raised when no hostmasks match. # Raised when no hostmasks match.
return _checkCapabilityForUnknownUser(capability, users=users, return _checkCapabilityForUnknownUser(capability, users=users,
channels=channels) channels=channels)
except ValueError, e: except ValueError as e:
# Raised when multiple hostmasks match. # Raised when multiple hostmasks match.
log.warning('%s: %s', hostmask, e) log.warning('%s: %s', hostmask, e)
return _checkCapabilityForUnknownUser(capability, users=users, return _checkCapabilityForUnknownUser(capability, users=users,
@ -1144,9 +1143,9 @@ class DefaultCapabilities(registry.SpaceSeparatedListOfStrings):
def setValue(self, v, allowDefaultOwner=conf.allowDefaultOwner): def setValue(self, v, allowDefaultOwner=conf.allowDefaultOwner):
registry.SpaceSeparatedListOfStrings.setValue(self, v) registry.SpaceSeparatedListOfStrings.setValue(self, v)
if '-owner' not in self.value and not allowDefaultOwner: if '-owner' not in self.value and not allowDefaultOwner:
print '*** You must run supybot with the --allow-default-owner' print('*** You must run supybot with the --allow-default-owner')
print '*** option in order to allow a default capability of owner.' print('*** option in order to allow a default capability of owner.')
print '*** Don\'t do that, it\'s dumb.' print('*** Don\'t do that, it\'s dumb.')
self.value.add('-owner') self.value.add('-owner')
conf.registerGlobalValue(conf.supybot, 'capabilities', conf.registerGlobalValue(conf.supybot, 'capabilities',

View File

@ -205,8 +205,9 @@ class IrcMsgQueue(object):
msg in self.lowpriority or \ msg in self.lowpriority or \
msg in self.highpriority msg in self.highpriority
def __nonzero__(self): def __bool__(self):
return bool(self.highpriority or self.normal or self.lowpriority) return bool(self.highpriority or self.normal or self.lowpriority)
__nonzero__ = __bool__
def __len__(self): def __len__(self):
return len(self.highpriority)+len(self.lowpriority)+len(self.normal) return len(self.highpriority)+len(self.lowpriority)+len(self.normal)
@ -434,9 +435,9 @@ class IrcState(IrcCommandDispatcher):
assert left[0] == '(', 'Odd PREFIX in 005: %s' % s assert left[0] == '(', 'Odd PREFIX in 005: %s' % s
left = left[1:] left = left[1:]
assert len(left) == len(right), 'Odd PREFIX in 005: %s' % s assert len(left) == len(right), 'Odd PREFIX in 005: %s' % s
return dict(zip(left, right)) return dict(list(zip(left, right)))
else: else:
return dict(zip('ovh', s)) return dict(list(zip('ovh', s)))
_005converters['prefix'] = _prefixParser _005converters['prefix'] = _prefixParser
del _prefixParser del _prefixParser
def _maxlistParser(s): def _maxlistParser(s):
@ -447,7 +448,7 @@ class IrcState(IrcCommandDispatcher):
(mode, limit) = pair.split(':', 1) (mode, limit) = pair.split(':', 1)
modes += mode modes += mode
limits += (int(limit),) * len(mode) limits += (int(limit),) * len(mode)
return dict(zip(modes, limits)) return dict(list(zip(modes, limits)))
_005converters['maxlist'] = _maxlistParser _005converters['maxlist'] = _maxlistParser
del _maxlistParser del _maxlistParser
def _maxbansParser(s): def _maxbansParser(s):
@ -460,7 +461,7 @@ class IrcState(IrcCommandDispatcher):
(mode, limit) = pair.split(':', 1) (mode, limit) = pair.split(':', 1)
modes += mode modes += mode
limits += (int(limit),) * len(mode) limits += (int(limit),) * len(mode)
d = dict(zip(modes, limits)) d = dict(list(zip(modes, limits)))
assert 'b' in d assert 'b' in d
return d['b'] return d['b']
else: else:
@ -474,7 +475,7 @@ class IrcState(IrcCommandDispatcher):
converter = self._005converters.get(name, lambda x: x) converter = self._005converters.get(name, lambda x: x)
try: try:
self.supported[name] = converter(value) self.supported[name] = converter(value)
except Exception, e: except Exception as e:
log.exception('Uncaught exception in 005 converter:') log.exception('Uncaught exception in 005 converter:')
log.error('Name: %s, Converter: %s', name, converter) log.error('Name: %s, Converter: %s', name, converter)
else: else:

View File

@ -85,7 +85,7 @@ class IrcMsg(object):
def __init__(self, s='', command='', args=(), prefix='', msg=None): def __init__(self, s='', command='', args=(), prefix='', msg=None):
assert not (msg and s), 'IrcMsg.__init__ cannot accept both s and msg' assert not (msg and s), 'IrcMsg.__init__ cannot accept both s and msg'
if not s and not command and not msg: if not s and not command and not msg:
raise MalformedIrcMsg, 'IRC messages require a command.' raise MalformedIrcMsg('IRC messages require a command.')
self._str = None self._str = None
self._repr = None self._repr = None
self._hash = None self._hash = None
@ -109,7 +109,7 @@ class IrcMsg(object):
self.args = s.split() self.args = s.split()
self.command = self.args.pop(0) self.command = self.args.pop(0)
except (IndexError, ValueError): except (IndexError, ValueError):
raise MalformedIrcMsg, repr(originalString) raise MalformedIrcMsg(repr(originalString))
else: else:
if msg is not None: if msg is not None:
if prefix: if prefix:

View File

@ -36,6 +36,7 @@ work in an IRC-case-insensitive fashion), and numerous other things.
""" """
from __future__ import division from __future__ import division
from __future__ import print_function
import re import re
import sys import sys
@ -47,11 +48,12 @@ import functools
from cStringIO import StringIO as sio from cStringIO import StringIO as sio
from . import utils from . import utils
from itertools import imap from . import minisix
def debug(s, *args): def debug(s, *args):
"""Prints a debug string. Most likely replaced by our logging debug.""" """Prints a debug string. Most likely replaced by our logging debug."""
print '***', s % args print('***', s % args)
userHostmaskRe = re.compile(r'^\S+!\S+@\S+$') userHostmaskRe = re.compile(r'^\S+!\S+@\S+$')
def isUserHostmask(s): def isUserHostmask(s):
@ -87,17 +89,17 @@ def splitHostmask(hostmask):
assert isUserHostmask(hostmask) assert isUserHostmask(hostmask)
nick, rest = hostmask.split('!', 1) nick, rest = hostmask.split('!', 1)
user, host = rest.split('@', 1) user, host = rest.split('@', 1)
return (intern(nick), intern(user), intern(host)) return (minisix.intern(nick), minisix.intern(user), minisix.intern(host))
def joinHostmask(nick, ident, host): def joinHostmask(nick, ident, host):
"""nick, user, host => hostmask """nick, user, host => hostmask
Joins the nick, ident, host into a user hostmask.""" Joins the nick, ident, host into a user hostmask."""
assert nick and ident and host assert nick and ident and host
return intern('%s!%s@%s' % (nick, ident, host)) return minisix.intern('%s!%s@%s' % (nick, ident, host))
_rfc1459trans = utils.str.MultipleReplacer(dict(zip( _rfc1459trans = utils.str.MultipleReplacer(dict(list(zip(
string.ascii_uppercase + r'\[]~', string.ascii_uppercase + r'\[]~',
string.ascii_lowercase + r'|{}^'))) string.ascii_lowercase + r'|{}^'))))
def toLower(s, casemapping=None): def toLower(s, casemapping=None):
"""s => s """s => s
Returns the string s lowered according to IRC case rules.""" Returns the string s lowered according to IRC case rules."""
@ -106,7 +108,7 @@ def toLower(s, casemapping=None):
elif casemapping == 'ascii': # freenode elif casemapping == 'ascii': # freenode
return s.lower() return s.lower()
else: else:
raise ValueError, 'Invalid casemapping: %r' % casemapping raise ValueError('Invalid casemapping: %r' % casemapping)
def strEqual(nick1, nick2): def strEqual(nick1, nick2):
"""s1, s2 => bool """s1, s2 => bool
@ -160,7 +162,7 @@ def areReceivers(s, strictRfc=True, nicklen=None, chantypes='#&+!',
nick = functools.partial(isNick, strictRfc=strictRfc, nicklen=nicklen) nick = functools.partial(isNick, strictRfc=strictRfc, nicklen=nicklen)
chan = functools.partial(isChannel, chantypes=chantypes, chan = functools.partial(isChannel, chantypes=chantypes,
channellen=channellen) channellen=channellen)
return all(map(lambda x:nick(x) or chan(x), s.split(','))) return all([nick(x) or chan(x) for x in s.split(',')])
_patternCache = utils.structures.CacheDict(1000) _patternCache = utils.structures.CacheDict(1000)
def _hostmaskPatternEqual(pattern, hostmask): def _hostmaskPatternEqual(pattern, hostmask):
@ -523,7 +525,7 @@ def unDccIP(i):
L.append(i % 256) L.append(i % 256)
i //= 256 i //= 256
L.reverse() L.reverse()
return '.'.join(imap(str, L)) return '.'.join(map(str, L))
class IrcString(str): class IrcString(str):
"""This class does case-insensitive comparison and hashing of nicks.""" """This class does case-insensitive comparison and hashing of nicks."""

View File

@ -52,7 +52,8 @@ class Formatter(logging.Formatter):
def formatTime(self, record, datefmt=None): def formatTime(self, record, datefmt=None):
return timestamp(record.created) return timestamp(record.created)
def formatException(self, (E, e, tb)): def formatException(self, exc_info):
(E, e, tb) = exc_info
for exn in deadlyExceptions: for exn in deadlyExceptions:
if issubclass(e.__class__, exn): if issubclass(e.__class__, exn):
raise raise
@ -95,9 +96,9 @@ class StdoutStreamHandler(logging.StreamHandler):
# We check for ERROR there because otherwise, tracebacks (which are # We check for ERROR there because otherwise, tracebacks (which are
# already wrapped by Python itself) wrap oddly. # already wrapped by Python itself) wrap oddly.
if not isinstance(record.levelname, basestring): if not isinstance(record.levelname, basestring):
print record print(record)
print record.levelname print(record.levelname)
print utils.stackTrace() print(utils.stackTrace())
prefixLen = len(record.levelname) + 1 # ' ' prefixLen = len(record.levelname) + 1 # ' '
s = textwrap.fill(s, width=78, subsequent_indent=' '*prefixLen) s = textwrap.fill(s, width=78, subsequent_indent=' '*prefixLen)
s.rstrip('\r\n') s.rstrip('\r\n')
@ -107,13 +108,13 @@ class StdoutStreamHandler(logging.StreamHandler):
if conf.supybot.log.stdout() and not conf.daemonized: if conf.supybot.log.stdout() and not conf.daemonized:
try: try:
logging.StreamHandler.emit(self, record) 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() self.disable()
error('Error logging to stdout. Removing stdout handler.') error('Error logging to stdout. Removing stdout handler.')
exception('Uncaught exception in StdoutStreamHandler:') exception('Uncaught exception in StdoutStreamHandler:')
def disable(self): def disable(self):
self.setLevel(sys.maxint) # Just in case. self.setLevel(sys.maxsize) # Just in case.
_logger.removeHandler(self) _logger.removeHandler(self)
logging._acquireLock() logging._acquireLock()
try: try:
@ -142,7 +143,8 @@ class ColorizedFormatter(Formatter):
# This was necessary because these variables aren't defined until later. # This was necessary because these variables aren't defined until later.
# The staticmethod is necessary because they get treated like methods. # The staticmethod is necessary because they get treated like methods.
_fmtConf = staticmethod(lambda : conf.supybot.log.stdout.format()) _fmtConf = staticmethod(lambda : conf.supybot.log.stdout.format())
def formatException(self, (E, e, tb)): def formatException(self, exc_info):
(E, e, tb) = exc_info
if conf.supybot.log.stdout.colorized(): if conf.supybot.log.stdout.colorized():
return ''.join([ansi.RED, return ''.join([ansi.RED,
Formatter.formatException(self, (E, e, tb)), Formatter.formatException(self, (E, e, tb)),
@ -184,13 +186,12 @@ if not os.path.exists(pluginLogDir):
try: try:
messagesLogFilename = os.path.join(_logDir, 'messages.log') messagesLogFilename = os.path.join(_logDir, 'messages.log')
_handler = BetterFileHandler(messagesLogFilename) _handler = BetterFileHandler(messagesLogFilename)
except EnvironmentError, e: except EnvironmentError as e:
raise SystemExit, \ raise SystemExit('Error opening messages logfile (%s). ' \
'Error opening messages logfile (%s). ' \
'Generally, this is because you are running Supybot in a directory ' \ 'Generally, this is because you are running Supybot in a directory ' \
'you don\'t have permissions to add files in, or you\'re running ' \ 'you don\'t have permissions to add files in, or you\'re running ' \
'Supybot as a different user than you normal do. The original ' \ 'Supybot as a different user than you normal do. The original ' \
'error was: %s' % (messagesLogFilename, utils.gen.exnToString(e)) 'error was: %s' % (messagesLogFilename, utils.gen.exnToString(e)))
# These are public. # These are public.
formatter = Formatter('NEVER SEEN; IF YOU SEE THIS, FILE A BUG!') formatter = Formatter('NEVER SEEN; IF YOU SEE THIS, FILE A BUG!')
@ -345,20 +346,20 @@ def firewall(f, errorHandler=None):
logging_function = self.log.exception logging_function = self.log.exception
else: else:
logging_function = exception logging_function = exception
logging_function('%s in %s.%s:', s, self.__class__.__name__, f.func_name) logging_function('%s in %s.%s:', s, self.__class__.__name__, f.__name__)
def m(self, *args, **kwargs): def m(self, *args, **kwargs):
try: try:
return f(self, *args, **kwargs) return f(self, *args, **kwargs)
except Exception, e: except Exception as e:
if testing: if testing:
raise raise
logException(self) logException(self)
if errorHandler is not None: if errorHandler is not None:
try: try:
return errorHandler(self, *args, **kwargs) return errorHandler(self, *args, **kwargs)
except Exception, e: except Exception as e:
logException(self, 'Uncaught exception in errorHandler') logException(self, 'Uncaught exception in errorHandler')
m = utils.python.changeFunctionName(m, f.func_name, f.__doc__) m = utils.python.changeFunctionName(m, f.__name__, f.__doc__)
return m return m
class MetaFirewall(type): class MetaFirewall(type):

40
src/minisix.py Normal file
View File

@ -0,0 +1,40 @@
###
# Copyright (c) 2014, Valentin Lorentz
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions, and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions, and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
# * Neither the name of the author of this software nor the name of
# contributors to this software may be used to endorse or promote products
# derived from this software without specific prior written consent.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
# POSSIBILITY OF SUCH DAMAGE.
###
"""Restricted equivalent to six."""
import sys
if sys.version_info[0] >= 3:
intern = sys.intern
else:
if isinstance(__builtins__, dict):
intern = __builtins__['intern']
else:
intern = __builtins__.intern

View File

@ -54,12 +54,12 @@ def loadPluginModule(name, ignoreDeprecation=False):
log.warning('Invalid plugin directory: %s; removing.', dir) log.warning('Invalid plugin directory: %s; removing.', dir)
conf.supybot.directories.plugins().remove(dir) conf.supybot.directories.plugins().remove(dir)
if name not in files: if name not in files:
matched_names = filter(lambda x: re.search(r'(?i)^%s$' % (name,), x), search = lambda x: re.search(r'(?i)^%s$' % (name,), x)
files) matched_names = list(filter(search, files))
if len(matched_names) == 1: if len(matched_names) == 1:
name = matched_names[0] name = matched_names[0]
else: else:
raise ImportError, name raise ImportError(name)
moduleInfo = imp.find_module(name, pluginDirs) moduleInfo = imp.find_module(name, pluginDirs)
try: try:
module = imp.load_module(name, *moduleInfo) module = imp.load_module(name, *moduleInfo)
@ -74,8 +74,8 @@ def loadPluginModule(name, ignoreDeprecation=False):
if ignoreDeprecation: if ignoreDeprecation:
log.warning('Deprecated plugin loaded: %s', name) log.warning('Deprecated plugin loaded: %s', name)
else: else:
raise Deprecated, format('Attempted to load deprecated plugin %s', raise Deprecated(format('Attempted to load deprecated plugin %s',
name) name))
if module.__name__ in sys.modules: if module.__name__ in sys.modules:
sys.modules[module.__name__] = module sys.modules[module.__name__] = module
linecache.checkcache() linecache.checkcache()
@ -85,11 +85,10 @@ def loadPluginClass(irc, module, register=None):
"""Loads the plugin Class from the given module into the given Irc.""" """Loads the plugin Class from the given module into the given Irc."""
try: try:
cb = module.Class(irc) cb = module.Class(irc)
except TypeError, e: except TypeError as e:
s = str(e) s = str(e)
if '2 given' in s and '__init__' in s: if '2 given' in s and '__init__' in s:
raise callbacks.Error, \ raise callbacks.Error('In our switch from CVS to Darcs (after 0.80.1), we ' \
'In our switch from CVS to Darcs (after 0.80.1), we ' \
'changed the __init__ for callbacks.Privmsg* to also ' \ 'changed the __init__ for callbacks.Privmsg* to also ' \
'accept an irc argument. This plugin (%s) is overriding ' \ 'accept an irc argument. This plugin (%s) is overriding ' \
'its __init__ method and needs to update its prototype ' \ 'its __init__ method and needs to update its prototype ' \
@ -98,17 +97,16 @@ def loadPluginClass(irc, module, register=None):
'parent\'s __init__. Another possible cause: the code in ' \ 'parent\'s __init__. Another possible cause: the code in ' \
'your __init__ raised a TypeError when calling a function ' \ 'your __init__ raised a TypeError when calling a function ' \
'or creating an object, which doesn\'t take 2 arguments.' %\ 'or creating an object, which doesn\'t take 2 arguments.' %\
module.__name__ module.__name__)
else: else:
raise raise
except AttributeError, e: except AttributeError as e:
if 'Class' in str(e): if 'Class' in str(e):
raise callbacks.Error, \ raise callbacks.Error('This plugin module doesn\'t have a "Class" ' \
'This plugin module doesn\'t have a "Class" ' \
'attribute to specify which plugin should be ' \ 'attribute to specify which plugin should be ' \
'instantiated. If you didn\'t write this ' \ 'instantiated. If you didn\'t write this ' \
'plugin, but received it with Supybot, file ' \ 'plugin, but received it with Supybot, file ' \
'a bug with us about this error.' 'a bug with us about this error.')
else: else:
raise raise
cb.classModule = module cb.classModule = module
@ -129,7 +127,7 @@ def loadPluginClass(irc, module, register=None):
renameCommand(cb, command, newName) renameCommand(cb, command, newName)
else: else:
conf.supybot.commands.renames.unregister(plugin) conf.supybot.commands.renames.unregister(plugin)
except registry.NonExistentRegistryEntry, e: except registry.NonExistentRegistryEntry as e:
pass # The plugin isn't there. pass # The plugin isn't there.
irc.addCallback(cb) irc.addCallback(cb)
return cb return cb

View File

@ -29,7 +29,7 @@
"""Handles interactive questions; useful for wizards and whatnot.""" """Handles interactive questions; useful for wizards and whatnot."""
from __future__ import print_function
import sys import sys
import textwrap import textwrap
@ -44,8 +44,8 @@ useBold = False
def output(s, unformatted=True, fd=sys.stdout): def output(s, unformatted=True, fd=sys.stdout):
if unformatted: if unformatted:
s = textwrap.fill(utils.str.normalizeWhitespace(s), width=65) s = textwrap.fill(utils.str.normalizeWhitespace(s), width=65)
print >>fd, s print(s, file=fd)
print >>fd print('', file=fd)
def expect(prompt, possibilities, recursed=False, default=None, def expect(prompt, possibilities, recursed=False, default=None,
acceptEmpty=False, fd=sys.stdout): acceptEmpty=False, fd=sys.stdout):
@ -75,10 +75,13 @@ def expect(prompt, possibilities, recursed=False, default=None,
prompt = prompt.strip() + ' ' prompt = prompt.strip() + ' '
if useBold: if useBold:
prompt += ansi.RESET prompt += ansi.RESET
print >>fd, ansi.BOLD, print(ansi.BOLD, end=' ', file=fd)
s = raw_input(prompt) if sys.version_info[0] >= 3:
s = input(prompt)
else:
s = raw_input(prompt)
s = s.strip() s = s.strip()
print >>fd print(file=fd)
if possibilities: if possibilities:
if s in possibilities: if s in possibilities:
return s return s
@ -140,7 +143,7 @@ def getpass(prompt=None, secondPrompt=None):
output(_('Passwords don\'t match.')) output(_('Passwords don\'t match.'))
else: else:
break break
print print('')
return password return password

View File

@ -42,11 +42,11 @@ _ = i18n.PluginInternationalization()
def error(s): def error(s):
"""Replace me with something better from another module!""" """Replace me with something better from another module!"""
print '***', s print('***', s)
def exception(s): def exception(s):
"""Ditto!""" """Ditto!"""
print '***', s, 'A bad exception.' print('***', s, 'A bad exception.')
class RegistryException(Exception): class RegistryException(Exception):
pass pass
@ -103,7 +103,7 @@ def open_registry(filename, clear=False):
value = decoder(value)[0] value = decoder(value)[0]
acc = '' acc = ''
except ValueError: except ValueError:
raise InvalidRegistryFile, 'Error unpacking line %r' % acc raise InvalidRegistryFile('Error unpacking line %r' % acc)
_cache[key] = value _cache[key] = value
_lastModified = time.time() _lastModified = time.time()
_fd.close() _fd.close()
@ -127,12 +127,12 @@ def close(registry, filename, private=True):
lines.append('#\n') lines.append('#\n')
try: try:
x = value.__class__(value._default, value._help) x = value.__class__(value._default, value._help)
except Exception, e: except Exception as e:
exception('Exception instantiating default for %s:' % exception('Exception instantiating default for %s:' %
value._name) value._name)
try: try:
lines.append('# Default value: %s\n' % x) lines.append('# Default value: %s\n' % x)
except Exception, e: except Exception as e:
exception('Exception printing default value of %s:' % exception('Exception printing default value of %s:' %
value._name) value._name)
lines.append('###\n') lines.append('###\n')
@ -144,7 +144,7 @@ def close(registry, filename, private=True):
else: else:
s = 'CENSORED' s = 'CENSORED'
fd.write('%s: %s\n' % (name, s)) fd.write('%s: %s\n' % (name, s))
except Exception, e: except Exception as e:
exception('Exception printing value:') exception('Exception printing value:')
fd.close() fd.close()
@ -169,7 +169,7 @@ def unescape(name):
_splitRe = re.compile(r'(?<!\\)\.') _splitRe = re.compile(r'(?<!\\)\.')
def split(name): def split(name):
return map(unescape, _splitRe.split(name)) return list(map(unescape, _splitRe.split(name)))
def join(names): def join(names):
return '.'.join(map(escape, names)) return '.'.join(map(escape, names))
@ -199,11 +199,11 @@ class Group(object):
self.X = X self.X = X
def __call__(self): def __call__(self):
raise ValueError, 'Groups have no value.' raise ValueError('Groups have no value.')
def __nonExistentEntry(self, attr): def __nonExistentEntry(self, attr):
s = '%r is not a valid entry in %r' % (attr, self._name) s = '%r is not a valid entry in %r' % (attr, self._name)
raise NonExistentRegistryEntry, s raise NonExistentRegistryEntry(s)
def __makeChild(self, attr, s): def __makeChild(self, attr, s):
v = self.__class__(self._default, self._help) v = self.__class__(self._default, self._help)
@ -250,7 +250,7 @@ class Group(object):
def register(self, name, node=None): def register(self, name, node=None):
if not isValidRegistryName(name): if not isValidRegistryName(name):
raise InvalidRegistryName, name raise InvalidRegistryName(name)
if node is None: if node is None:
node = Group(private=self._private) node = Group(private=self._private)
else: else:
@ -523,9 +523,9 @@ class OnlySomeStrings(String):
self.__parent = super(OnlySomeStrings, self) self.__parent = super(OnlySomeStrings, self)
self.__parent.__init__(*args, **kwargs) self.__parent.__init__(*args, **kwargs)
self.__doc__ = format(_('Valid values include %L.'), self.__doc__ = format(_('Valid values include %L.'),
map(repr, self.validStrings)) list(map(repr, self.validStrings)))
self.errormsg = format(_('Valid values include %L, not %%r.'), self.errormsg = format(_('Valid values include %L, not %%r.'),
map(repr, self.validStrings)) list(map(repr, self.validStrings)))
def help(self): def help(self):
strings = [s for s in self.validStrings if s] strings = [s for s in self.validStrings if s]
@ -615,7 +615,7 @@ class Regexp(Value):
self.setValue(utils.str.perlReToPythonRe(s), sr=s) self.setValue(utils.str.perlReToPythonRe(s), sr=s)
else: else:
self.setValue(None) self.setValue(None)
except ValueError, e: except ValueError as e:
self.error(e) self.error(e)
def setValue(self, v, sr=None): def setValue(self, v, sr=None):
@ -626,9 +626,8 @@ class Regexp(Value):
self.sr = sr self.sr = sr
self.__parent.setValue(v) self.__parent.setValue(v)
else: else:
raise InvalidRegistryValue, \ raise InvalidRegistryValue('Can\'t setValue a regexp, there would be an inconsistency '\
'Can\'t setValue a regexp, there would be an inconsistency '\ 'between the regexp and the recorded string value.')
'between the regexp and the recorded string value.'
def __str__(self): def __str__(self):
self() # Gotta update if we've been reloaded. self() # Gotta update if we've been reloaded.

View File

@ -140,7 +140,7 @@ class Schedule(drivers.IrcDriver):
del self.events[name] del self.events[name]
try: try:
f(*args, **kwargs) f(*args, **kwargs)
except Exception, e: except Exception as e:
log.exception('Uncaught exception in scheduled function:') log.exception('Uncaught exception in scheduled function:')

View File

@ -31,13 +31,13 @@ class shlex:
self.filestack = [] self.filestack = []
self.source = None self.source = None
if self.debug: if self.debug:
print 'shlex: reading from %s, line %d' \ print('shlex: reading from %s, line %d' \
% (self.instream, self.lineno) % (self.instream, self.lineno))
def push_token(self, tok): def push_token(self, tok):
"Push a token onto the stack popped by the get_token method" "Push a token onto the stack popped by the get_token method"
if self.debug >= 1: if self.debug >= 1:
print "shlex: pushing token " + `tok` print("shlex: pushing token " + repr(tok))
self.pushback = [tok] + self.pushback self.pushback = [tok] + self.pushback
def push_source(self, newstream, newfile=None): def push_source(self, newstream, newfile=None):
@ -48,9 +48,9 @@ class shlex:
self.lineno = 1 self.lineno = 1
if self.debug: if self.debug:
if newfile is not None: if newfile is not None:
print 'shlex: pushing to file %s' % (self.infile,) print('shlex: pushing to file %s' % (self.infile,))
else: else:
print 'shlex: pushing to stream %s' % (self.instream,) print('shlex: pushing to stream %s' % (self.instream,))
def pop_source(self): def pop_source(self):
"Pop the input source stack." "Pop the input source stack."
@ -58,8 +58,8 @@ class shlex:
(self.infile, self.instream, self.lineno) = self.filestack[0] (self.infile, self.instream, self.lineno) = self.filestack[0]
self.filestack = self.filestack[1:] self.filestack = self.filestack[1:]
if self.debug: if self.debug:
print 'shlex: popping to %s, line %d' \ print('shlex: popping to %s, line %d' \
% (self.instream, self.lineno) % (self.instream, self.lineno))
self.state = ' ' self.state = ' '
def get_token(self): def get_token(self):
@ -68,7 +68,7 @@ class shlex:
tok = self.pushback[0] tok = self.pushback[0]
self.pushback = self.pushback[1:] self.pushback = self.pushback[1:]
if self.debug >= 1: if self.debug >= 1:
print "shlex: popping token " + `tok` print("shlex: popping token " + repr(tok))
return tok return tok
# No pushback. Get a token. # No pushback. Get a token.
raw = self.read_token() raw = self.read_token()
@ -89,20 +89,20 @@ class shlex:
# Neither inclusion nor EOF # Neither inclusion nor EOF
if self.debug >= 1: if self.debug >= 1:
if raw: if raw:
print "shlex: token=" + `raw` print("shlex: token=" + repr(raw))
else: else:
print "shlex: token=EOF" print("shlex: token=EOF")
return raw return raw
def read_token(self): def read_token(self):
"Read a token from the input stream (no pushback or inclusions)" "Read a token from the input stream (no pushback or inclusions)"
while 1: while True:
nextchar = self.instream.read(1) nextchar = self.instream.read(1)
if nextchar == '\n': if nextchar == '\n':
self.lineno = self.lineno + 1 self.lineno = self.lineno + 1
if self.debug >= 3: if self.debug >= 3:
print "shlex: in state", repr(self.state), \ print("shlex: in state", repr(self.state), \
"I see character:", repr(nextchar) "I see character:", repr(nextchar))
if self.state is None: if self.state is None:
self.token = '' # past end of file self.token = '' # past end of file
break break
@ -112,7 +112,7 @@ class shlex:
break break
elif nextchar in self.whitespace: elif nextchar in self.whitespace:
if self.debug >= 2: if self.debug >= 2:
print "shlex: I see whitespace in whitespace state" print("shlex: I see whitespace in whitespace state")
if self.token: if self.token:
break # emit current token break # emit current token
else: else:
@ -147,16 +147,16 @@ class shlex:
self.backslash = False self.backslash = False
elif not nextchar: # end of file elif not nextchar: # end of file
if self.debug >= 2: if self.debug >= 2:
print "shlex: I see EOF in quotes state" print("shlex: I see EOF in quotes state")
# XXX what error should be raised here? # XXX what error should be raised here?
raise ValueError, "No closing quotation" raise ValueError("No closing quotation")
elif self.state == 'a': elif self.state == 'a':
if not nextchar: if not nextchar:
self.state = None # end of file self.state = None # end of file
break break
elif nextchar in self.whitespace: elif nextchar in self.whitespace:
if self.debug >= 2: if self.debug >= 2:
print "shlex: I see whitespace in word state" print("shlex: I see whitespace in word state")
self.state = ' ' self.state = ' '
if self.token: if self.token:
break # emit current token break # emit current token
@ -170,7 +170,7 @@ class shlex:
else: else:
self.pushback = [nextchar] + self.pushback self.pushback = [nextchar] + self.pushback
if self.debug >= 2: if self.debug >= 2:
print "shlex: I see punctuation in word state" print("shlex: I see punctuation in word state")
self.state = ' ' self.state = ' '
if self.token: if self.token:
break # emit current token break # emit current token
@ -180,9 +180,9 @@ class shlex:
self.token = '' self.token = ''
if self.debug > 1: if self.debug > 1:
if result: if result:
print "shlex: raw token=" + `result` print("shlex: raw token=" + repr(result))
else: else:
print "shlex: raw token=EOF" print("shlex: raw token=EOF")
return result return result
def sourcehook(self, newfile): def sourcehook(self, newfile):
@ -190,7 +190,7 @@ class shlex:
if newfile[0] == '"': if newfile[0] == '"':
newfile = newfile[1:-1] newfile = newfile[1:-1]
# This implements cpp-like semantics for relative-path inclusion. # This implements cpp-like semantics for relative-path inclusion.
if type(self.infile) == type("") and not os.path.isabs(newfile): if isinstance(self.infile, basestring) and not os.path.isabs(newfile):
newfile = os.path.join(os.path.dirname(self.infile), newfile) newfile = os.path.join(os.path.dirname(self.infile), newfile)
return (newfile, open(newfile, "r")) return (newfile, open(newfile, "r"))
@ -210,9 +210,9 @@ if __name__ == '__main__':
file = sys.argv[1] file = sys.argv[1]
with open(file) as fd: with open(file) as fd:
lexer = shlex(fd, file) lexer = shlex(fd, file)
while 1: while True:
tt = lexer.get_token() tt = lexer.get_token()
if tt: if tt:
print "Token: " + repr(tt) print("Token: " + repr(tt))
else: else:
break break

View File

@ -81,7 +81,7 @@ class TestPlugin(callbacks.Plugin):
irc.reply(repr(eval(' '.join(args)))) irc.reply(repr(eval(' '.join(args))))
except callbacks.ArgumentError: except callbacks.ArgumentError:
raise raise
except Exception, e: except Exception as e:
irc.reply(utils.exnToString(e)) irc.reply(utils.exnToString(e))
# Since we know we don't now need the Irc object, we just give None. This # 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. # might break if callbacks.Privmsg ever *requires* the Irc object.
@ -147,8 +147,8 @@ class PluginTestCase(SupyTestCase):
for cb in self.irc.callbacks: for cb in self.irc.callbacks:
cbModule = sys.modules[cb.__class__.__module__] cbModule = sys.modules[cb.__class__.__module__]
if hasattr(cbModule, 'deprecated') and cbModule.deprecated: if hasattr(cbModule, 'deprecated') and cbModule.deprecated:
print print('')
print 'Ignored, %s is deprecated.' % cb.name() print('Ignored, %s is deprecated.' % cb.name())
run = False run = False
if run: if run:
originalRunTest() originalRunTest()
@ -187,7 +187,7 @@ class PluginTestCase(SupyTestCase):
ircdb.ignores.reload() ircdb.ignores.reload()
ircdb.channels.reload() ircdb.channels.reload()
if self.plugins is None: if self.plugins is None:
raise ValueError, 'PluginTestCase must have a "plugins" attribute.' raise ValueError('PluginTestCase must have a "plugins" attribute.')
self.nick = nick self.nick = nick
self.prefix = ircutils.joinHostmask(nick, 'user', 'host.domain.tld') self.prefix = ircutils.joinHostmask(nick, 'user', 'host.domain.tld')
self.irc = getTestIrc() self.irc = getTestIrc()
@ -238,7 +238,7 @@ class PluginTestCase(SupyTestCase):
if timeout is None: if timeout is None:
timeout = self.timeout timeout = self.timeout
if self.myVerbose: if self.myVerbose:
print # Extra newline, so it's pretty. print('') # Extra newline, so it's pretty.
prefixChars = conf.supybot.reply.whenAddressedBy.chars() prefixChars = conf.supybot.reply.whenAddressedBy.chars()
if not usePrefixChar and query[0] in prefixChars: if not usePrefixChar and query[0] in prefixChars:
query = query[1:] query = query[1:]
@ -246,7 +246,7 @@ class PluginTestCase(SupyTestCase):
query = query.encode('utf8') # unicode->str query = query.encode('utf8') # unicode->str
msg = ircmsgs.privmsg(to, query, prefix=frm) msg = ircmsgs.privmsg(to, query, prefix=frm)
if self.myVerbose: if self.myVerbose:
print 'Feeding: %r' % msg print('Feeding: %r' % msg)
self.irc.feedMsg(msg) self.irc.feedMsg(msg)
fed = time.time() fed = time.time()
response = self.irc.takeMsg() response = self.irc.takeMsg()
@ -255,7 +255,7 @@ class PluginTestCase(SupyTestCase):
drivers.run() drivers.run()
response = self.irc.takeMsg() response = self.irc.takeMsg()
if self.myVerbose: if self.myVerbose:
print 'Response: %r' % response print('Response: %r' % response)
return response return response
def getMsg(self, query, **kwargs): def getMsg(self, query, **kwargs):
@ -276,7 +276,7 @@ class PluginTestCase(SupyTestCase):
def assertError(self, query, **kwargs): def assertError(self, query, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError(query)
if lastGetHelp not in m.args[1]: if lastGetHelp not in m.args[1]:
self.failUnless(m.args[1].startswith('Error:'), self.failUnless(m.args[1].startswith('Error:'),
'%r did not error: %s' % (query, m.args[1])) '%r did not error: %s' % (query, m.args[1]))
@ -288,7 +288,7 @@ class PluginTestCase(SupyTestCase):
def assertNotError(self, query, **kwargs): def assertNotError(self, query, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError(query)
self.failIf(m.args[1].startswith('Error:'), self.failIf(m.args[1].startswith('Error:'),
'%r errored: %s' % (query, m.args[1])) '%r errored: %s' % (query, m.args[1]))
self.failIf(lastGetHelp in m.args[1], self.failIf(lastGetHelp in m.args[1],
@ -301,7 +301,7 @@ class PluginTestCase(SupyTestCase):
def assertHelp(self, query, **kwargs): def assertHelp(self, query, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError(query)
msg = m.args[1] msg = m.args[1]
if 'more message' in msg: if 'more message' in msg:
msg = msg[0:-27] # Strip (XXX more messages) msg = msg[0:-27] # Strip (XXX more messages)
@ -321,7 +321,7 @@ class PluginTestCase(SupyTestCase):
def assertResponse(self, query, expectedResponse, **kwargs): def assertResponse(self, query, expectedResponse, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError(query)
self.assertEqual(m.args[1], expectedResponse, self.assertEqual(m.args[1], expectedResponse,
'%r != %r' % (expectedResponse, m.args[1])) '%r != %r' % (expectedResponse, m.args[1]))
return m return m
@ -333,7 +333,7 @@ class PluginTestCase(SupyTestCase):
def assertRegexp(self, query, regexp, flags=re.I, **kwargs): def assertRegexp(self, query, regexp, flags=re.I, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError(query)
self.failUnless(re.search(regexp, m.args[1], flags), self.failUnless(re.search(regexp, m.args[1], flags),
'%r does not match %r' % (m.args[1], regexp)) '%r does not match %r' % (m.args[1], regexp))
return m return m
@ -345,7 +345,7 @@ class PluginTestCase(SupyTestCase):
def assertNotRegexp(self, query, regexp, flags=re.I, **kwargs): def assertNotRegexp(self, query, regexp, flags=re.I, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError(query)
self.failUnless(re.search(regexp, m.args[1], flags) is None, self.failUnless(re.search(regexp, m.args[1], flags) is None,
'%r matched %r' % (m.args[1], regexp)) '%r matched %r' % (m.args[1], regexp))
return m return m
@ -357,7 +357,7 @@ class PluginTestCase(SupyTestCase):
def assertAction(self, query, expectedResponse=None, **kwargs): def assertAction(self, query, expectedResponse=None, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError(query)
self.failUnless(ircmsgs.isAction(m), '%r is not an action.' % m) self.failUnless(ircmsgs.isAction(m), '%r is not an action.' % m)
if expectedResponse is not None: if expectedResponse is not None:
s = ircmsgs.unAction(m) s = ircmsgs.unAction(m)
@ -372,7 +372,7 @@ class PluginTestCase(SupyTestCase):
def assertActionRegexp(self, query, regexp, flags=re.I, **kwargs): def assertActionRegexp(self, query, regexp, flags=re.I, **kwargs):
m = self._feedMsg(query, **kwargs) m = self._feedMsg(query, **kwargs)
if m is None: if m is None:
raise TimeoutError, query raise TimeoutError(query)
self.failUnless(ircmsgs.isAction(m)) self.failUnless(ircmsgs.isAction(m))
s = ircmsgs.unAction(m) s = ircmsgs.unAction(m)
self.failUnless(re.search(regexp, s, flags), self.failUnless(re.search(regexp, s, flags),
@ -433,7 +433,7 @@ class ChannelPluginTestCase(PluginTestCase):
if timeout is None: if timeout is None:
timeout = self.timeout timeout = self.timeout
if self.myVerbose: if self.myVerbose:
print # Newline, just like PluginTestCase. print('') # Newline, just like PluginTestCase.
prefixChars = conf.supybot.reply.whenAddressedBy.chars() prefixChars = conf.supybot.reply.whenAddressedBy.chars()
if query[0] not in prefixChars and usePrefixChar: if query[0] not in prefixChars and usePrefixChar:
query = prefixChars[0] + query query = prefixChars[0] + query
@ -441,7 +441,7 @@ class ChannelPluginTestCase(PluginTestCase):
query = query.encode('utf8') # unicode->str query = query.encode('utf8') # unicode->str
msg = ircmsgs.privmsg(to, query, prefix=frm) msg = ircmsgs.privmsg(to, query, prefix=frm)
if self.myVerbose: if self.myVerbose:
print 'Feeding: %r' % msg print('Feeding: %r' % msg)
self.irc.feedMsg(msg) self.irc.feedMsg(msg)
fed = time.time() fed = time.time()
response = self.irc.takeMsg() response = self.irc.takeMsg()
@ -466,7 +466,7 @@ class ChannelPluginTestCase(PluginTestCase):
else: else:
ret = None ret = None
if self.myVerbose: if self.myVerbose:
print 'Returning: %r' % ret print('Returning: %r' % ret)
return ret return ret
def feedMsg(self, query, to=None, frm=None, private=False): def feedMsg(self, query, to=None, frm=None, private=False):
@ -537,7 +537,7 @@ def open_http(url, data=None):
host = realhost host = realhost
#print "proxy via http:", host, selector #print "proxy via http:", host, selector
if not host: raise IOError, ('http error', 'no host given') if not host: raise IOError('http error', 'no host given')
if proxy_passwd: if proxy_passwd:
import base64 import base64

View File

@ -44,7 +44,7 @@ def join(L):
def split(s): def split(s):
fd = StringIO.StringIO(s) fd = StringIO.StringIO(s)
reader = csv.reader(fd) reader = csv.reader(fd)
return reader.next() return next(reader)
csv.join = join csv.join = join
csv.split = split csv.split = split

View File

@ -50,7 +50,7 @@ def open_mkdir(filename, mode='wb', *args, **kwargs):
baz in it. baz in it.
""" """
if mode not in ('w', 'wb'): if mode not in ('w', 'wb'):
raise ValueError, 'utils.file.open expects to write.' raise ValueError('utils.file.open expects to write.')
(dirname, basename) = os.path.split(filename) (dirname, basename) = os.path.split(filename)
os.makedirs(dirname) os.makedirs(dirname)
return open(filename, mode, *args, **kwargs) return open(filename, mode, *args, **kwargs)
@ -105,7 +105,7 @@ def nonCommentLines(fd):
yield line yield line
def nonEmptyLines(fd): def nonEmptyLines(fd):
return ifilter(str.strip, fd) return filter(str.strip, fd)
def nonCommentNonEmptyLines(fd): def nonCommentNonEmptyLines(fd):
return nonEmptyLines(nonCommentLines(fd)) return nonEmptyLines(nonCommentLines(fd))
@ -137,7 +137,7 @@ class AtomicFile(object):
if allowEmptyOverwrite is None: if allowEmptyOverwrite is None:
allowEmptyOverwrite = force(self.default.allowEmptyOverwrite) allowEmptyOverwrite = force(self.default.allowEmptyOverwrite)
if mode not in ('w', 'wb'): if mode not in ('w', 'wb'):
raise ValueError, format('Invalid mode: %q', mode) raise ValueError(format('Invalid mode: %q', mode))
self.rolledback = False self.rolledback = False
self.allowEmptyOverwrite = allowEmptyOverwrite self.allowEmptyOverwrite = allowEmptyOverwrite
self.makeBackupIfSmaller = makeBackupIfSmaller self.makeBackupIfSmaller = makeBackupIfSmaller
@ -219,7 +219,7 @@ class AtomicFile(object):
shutil.move(self.tempFilename, self.filename) shutil.move(self.tempFilename, self.filename)
else: else:
raise ValueError, 'AtomicFile.close called after rollback.' raise ValueError('AtomicFile.close called after rollback.')
def __del__(self): def __del__(self):
# We rollback because if we're deleted without being explicitly closed, # We rollback because if we're deleted without being explicitly closed,

View File

@ -28,6 +28,8 @@
# POSSIBILITY OF SUCH DAMAGE. # POSSIBILITY OF SUCH DAMAGE.
### ###
from __future__ import print_function
import os import os
import sys import sys
import ast import ast
@ -36,7 +38,7 @@ import types
import textwrap import textwrap
import traceback import traceback
import collections import collections
from itertools import imap
from . import crypt from . import crypt
from .str import format from .str import format
@ -115,7 +117,7 @@ def timeElapsed(elapsed, short=False, leadingZeroes=False, years=True,
leadingZeroes = True leadingZeroes = True
Format(_('second'), secs) Format(_('second'), secs)
if not ret: if not ret:
raise ValueError, 'Time difference not great enough to be noted.' raise ValueError('Time difference not great enough to be noted.')
result = '' result = ''
if short: if short:
result = ' '.join(ret) result = ' '.join(ret)
@ -158,14 +160,14 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}):
without unsafely using eval().""" without unsafely using eval()."""
try: try:
node = ast.parse(s) node = ast.parse(s)
except SyntaxError, e: except SyntaxError as e:
raise ValueError, 'Invalid string: %s.' % e raise ValueError('Invalid string: %s.' % e)
nodes = ast.parse(s).body nodes = ast.parse(s).body
if not nodes: if not nodes:
if node.__class__ is ast.Module: if node.__class__ is ast.Module:
return node.doc return node.doc
else: else:
raise ValueError, format('Unsafe string: %q', s) raise ValueError(format('Unsafe string: %q', s))
node = nodes[0] node = nodes[0]
def checkNode(node): def checkNode(node):
if node.__class__ is ast.Expr: if node.__class__ is ast.Expr:
@ -190,7 +192,7 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}):
if checkNode(node): if checkNode(node):
return eval(s, namespace, namespace) return eval(s, namespace, namespace)
else: else:
raise ValueError, format('Unsafe string: %q', s) raise ValueError(format('Unsafe string: %q', s))
def exnToString(e): def exnToString(e):
"""Turns a simple exception instance into a string (better than str(e))""" """Turns a simple exception instance into a string (better than str(e))"""
@ -239,10 +241,11 @@ class IterableMap(object):
ret += 1 ret += 1
return ret return ret
def __nonzero__(self): def __bool__(self):
for _ in self.iteritems(): for _ in self.iteritems():
return True return True
return False return False
__nonzero__ = __bool__
class InsensitivePreservingDict(collections.MutableMapping): class InsensitivePreservingDict(collections.MutableMapping):
@ -299,7 +302,7 @@ class InsensitivePreservingDict(collections.MutableMapping):
class NormalizingSet(set): class NormalizingSet(set):
def __init__(self, iterable=()): def __init__(self, iterable=()):
iterable = imap(self.normalize, iterable) iterable = list(map(self.normalize, iterable))
super(NormalizingSet, self).__init__(iterable) super(NormalizingSet, self).__init__(iterable)
def normalize(self, x): def normalize(self, x):
@ -344,7 +347,7 @@ def callTracer(fd=None, basename=True):
filename = code.co_filename filename = code.co_filename
if basename: if basename:
filename = os.path.basename(filename) filename = os.path.basename(filename)
print >>fd, '%s: %s(%s)' % (filename, funcname, lineno) print('%s: %s(%s)' % (filename, funcname, lineno), file=fd)
return tracer return tracer
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -36,8 +36,9 @@ from itertools import *
# For old plugins # For old plugins
ifilter = filter ifilter = filter
def ifilterfalse(p, L): def filterfalse(p, L):
return ifilter(lambda x:not p(x), L) return filter(lambda x:not p(x), L)
ifilterfalse = filterfalse
imap = map imap = map
def len(iterable): def len(iterable):
@ -48,7 +49,7 @@ def len(iterable):
return i return i
def trueCycle(iterable): def trueCycle(iterable):
while 1: while True:
yielded = False yielded = False
for x in iterable: for x in iterable:
yield x yield x
@ -70,14 +71,14 @@ def partition(p, iterable):
def any(p, iterable): def any(p, iterable):
"""Returns true if any element in iterable satisfies predicate p.""" """Returns true if any element in iterable satisfies predicate p."""
for elt in ifilter(p, iterable): for elt in filter(p, iterable):
return True return True
else: else:
return False return False
def all(p, iterable): def all(p, iterable):
"""Returns true if all elements in iterable satisfy predicate p.""" """Returns true if all elements in iterable satisfy predicate p."""
for elt in ifilterfalse(p, iterable): for elt in filterfalse(p, iterable):
return False return False
else: else:
return True return True
@ -141,7 +142,7 @@ def startswith(long_, short):
shortI = iter(short) shortI = iter(short)
try: try:
while True: while True:
if shortI.next() != longI.next(): if next(shortI) != next(longI):
return False return False
except StopIteration: except StopIteration:
return True return True
@ -151,10 +152,10 @@ def limited(iterable, limit):
iterable = iter(iterable) iterable = iter(iterable)
try: try:
while i: while i:
yield iterable.next() yield next(iterable)
i -= 1 i -= 1
except StopIteration: except StopIteration:
raise ValueError, 'Expected %s elements in iterable (%r), got %s.' % \ raise ValueError('Expected %s elements in iterable (%r), got %s.' % \
(limit, iterable, limit-i) (limit, iterable, limit-i))
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -67,7 +67,7 @@ def getSocket(host, socks_proxy=None):
elif isIPV6(host): elif isIPV6(host):
return socket.socket(socket.AF_INET6, socket.SOCK_STREAM) return socket.socket(socket.AF_INET6, socket.SOCK_STREAM)
else: else:
raise socket.error, 'Something wonky happened.' raise socket.error('Something wonky happened.')
def isIP(s): def isIP(s):
"""Returns whether or not a given string is an IP address. """Returns whether or not a given string is an IP address.

View File

@ -53,13 +53,18 @@ def universalImport(*names):
ret = getattr(ret, parts[0]) ret = getattr(ret, parts[0])
del parts[0] del parts[0]
return ret return ret
raise ImportError, ','.join(names) raise ImportError(','.join(names))
def changeFunctionName(f, name, doc=None): def changeFunctionName(f, name, doc=None):
if doc is None: if doc is None:
doc = f.__doc__ doc = f.__doc__
newf = types.FunctionType(f.func_code, f.func_globals, name, if hasattr(f, '__closure__'):
f.func_defaults, f.func_closure) closure = f.__closure__
else:
# Pypy
closure = f.func_closure
newf = types.FunctionType(f.__code__, f.__globals__, name,
f.__defaults__, closure)
newf.__doc__ = doc newf.__doc__ = doc
return newf return newf
@ -86,7 +91,7 @@ class Synchronized(type):
f(self, *args, **kwargs) f(self, *args, **kwargs)
finally: finally:
lock.release() lock.release()
return changeFunctionName(g, f.func_name, f.__doc__) return changeFunctionName(g, f.__name__, f.__doc__)
for attr in sync: for attr in sync:
if attr in dict: if attr in dict:
dict[attr] = synchronized(dict[attr]) dict[attr] = synchronized(dict[attr])

View File

@ -33,7 +33,7 @@ def window(L, size):
Returns a sliding 'window' through the list L of size size.""" Returns a sliding 'window' through the list L of size size."""
assert not isinstance(L, int), 'Argument order swapped: window(L, size)' assert not isinstance(L, int), 'Argument order swapped: window(L, size)'
if size < 1: if size < 1:
raise ValueError, 'size <= 0 disallowed.' raise ValueError('size <= 0 disallowed.')
for i in xrange(len(L) - (size-1)): for i in xrange(len(L) - (size-1)):
yield L[i:i+size] yield L[i:i+size]

View File

@ -114,8 +114,8 @@ class MultipleRemover:
def __call__(self, s): def __call__(self, s):
return self._matcher.sub(lambda m: '', s) return self._matcher.sub(lambda m: '', s)
_soundextrans = MultipleReplacer(dict(zip(string.ascii_uppercase, _soundextrans = MultipleReplacer(dict(list(zip(string.ascii_uppercase,
'01230120022455012623010202'))) '01230120022455012623010202'))))
def soundex(s, length=4): def soundex(s, length=4):
"""Returns the soundex hash of a given string. """Returns the soundex hash of a given string.
@ -124,7 +124,7 @@ def soundex(s, length=4):
s = s.upper() # Make everything uppercase. s = s.upper() # Make everything uppercase.
s = ''.join([x for x in s if x in string.ascii_uppercase]) s = ''.join([x for x in s if x in string.ascii_uppercase])
if not s: if not s:
raise ValueError, 'Invalid string for soundex: %s' raise ValueError('Invalid string for soundex: %s')
firstChar = s[0] # Save the first character. firstChar = s[0] # Save the first character.
s = _soundextrans(s) # Convert to soundex numbers. s = _soundextrans(s) # Convert to soundex numbers.
s = s.lstrip(s[0]) # Remove all repeated first characters. s = s.lstrip(s[0]) # Remove all repeated first characters.
@ -155,7 +155,7 @@ _openers = '{[(<'
_closers = '}])>' _closers = '}])>'
def _getSep(s, allowBraces=False): def _getSep(s, allowBraces=False):
if len(s) < 2: if len(s) < 2:
raise ValueError, 'string given to _getSep is too short: %r' % s raise ValueError('string given to _getSep is too short: %r' % s)
if allowBraces: if allowBraces:
braces = _closers braces = _closers
else: else:
@ -165,9 +165,8 @@ def _getSep(s, allowBraces=False):
else: else:
separator = s[0] separator = s[0]
if separator.isalnum() or separator in braces: if separator.isalnum() or separator in braces:
raise ValueError, \ raise ValueError('Invalid separator: separator must not be alphanumeric or in ' \
'Invalid separator: separator must not be alphanumeric or in ' \ '"%s"' % braces)
'"%s"' % braces
return separator return separator
def perlReToPythonRe(s): def perlReToPythonRe(s):
@ -183,7 +182,7 @@ def perlReToPythonRe(s):
try: try:
(regexp, flags) = matcher.match(s).groups() (regexp, flags) = matcher.match(s).groups()
except AttributeError: # Unpack list of wrong size. except AttributeError: # Unpack list of wrong size.
raise ValueError, 'Must be of the form m/.../ or /.../' raise ValueError('Must be of the form m/.../ or /.../')
regexp = regexp.replace('\\'+opener, opener) regexp = regexp.replace('\\'+opener, opener)
if opener != closer: if opener != closer:
regexp = regexp.replace('\\'+closer, closer) regexp = regexp.replace('\\'+closer, closer)
@ -192,11 +191,11 @@ def perlReToPythonRe(s):
for c in flags.upper(): for c in flags.upper():
flag |= getattr(re, c) flag |= getattr(re, c)
except AttributeError: except AttributeError:
raise ValueError, 'Invalid flag: %s' % c raise ValueError('Invalid flag: %s' % c)
try: try:
return re.compile(regexp, flag) return re.compile(regexp, flag)
except re.error, e: except re.error as e:
raise ValueError, str(e) raise ValueError(str(e))
def perlReToReplacer(s): def perlReToReplacer(s):
"""Converts a string representation of a Perl regular expression (i.e., """Converts a string representation of a Perl regular expression (i.e.,
@ -210,7 +209,7 @@ def perlReToReplacer(s):
try: try:
(regexp, replace, flags) = matcher.match(s).groups() (regexp, replace, flags) = matcher.match(s).groups()
except AttributeError: # Unpack list of wrong size. except AttributeError: # Unpack list of wrong size.
raise ValueError, 'Must be of the form s/.../.../' raise ValueError('Must be of the form s/.../.../')
regexp = regexp.replace('\x08', r'\b') regexp = regexp.replace('\x08', r'\b')
replace = replace.replace('\\'+sep, sep) replace = replace.replace('\\'+sep, sep)
for i in xrange(10): for i in xrange(10):
@ -218,7 +217,7 @@ def perlReToReplacer(s):
g = False g = False
if 'g' in flags: if 'g' in flags:
g = True g = True
flags = filter('g'.__ne__, flags) flags = list(filter('g'.__ne__, flags))
if isinstance(flags, list): if isinstance(flags, list):
flags = ''.join(flags) flags = ''.join(flags)
r = perlReToPythonRe(sep.join(('', regexp, flags))) r = perlReToPythonRe(sep.join(('', regexp, flags)))
@ -414,7 +413,7 @@ def toBool(s):
elif s in ('false', 'off', 'disable', 'disabled', '0'): elif s in ('false', 'off', 'disable', 'disabled', '0'):
return False return False
else: else:
raise ValueError, 'Invalid string for toBool: %s' % quoted(s) raise ValueError('Invalid string for toBool: %s' % quoted(s))
# When used with Supybot, this is overriden when supybot.conf is loaded # When used with Supybot, this is overriden when supybot.conf is loaded
def timestamp(t): def timestamp(t):
@ -476,14 +475,12 @@ def format(s, *args, **kwargs):
return commaAndify(t) return commaAndify(t)
elif isinstance(t, tuple) and len(t) == 2: elif isinstance(t, tuple) and len(t) == 2:
if not isinstance(t[0], list): if not isinstance(t[0], list):
raise ValueError, \ raise ValueError('Invalid list for %%L in format: %s' % t)
'Invalid list for %%L in format: %s' % t
if not isinstance(t[1], basestring): if not isinstance(t[1], basestring):
raise ValueError, \ raise ValueError('Invalid string for %%L in format: %s' % t)
'Invalid string for %%L in format: %s' % t
return commaAndify(t[0], And=t[1]) return commaAndify(t[0], And=t[1])
else: else:
raise ValueError, 'Invalid value for %%L in format: %s' % t raise ValueError('Invalid value for %%L in format: %s' % t)
elif char == 'p': elif char == 'p':
return pluralize(args.pop()) return pluralize(args.pop())
elif char == 'q': elif char == 'q':
@ -493,17 +490,17 @@ def format(s, *args, **kwargs):
elif char == 'n': elif char == 'n':
t = args.pop() t = args.pop()
if not isinstance(t, (tuple, list)): if not isinstance(t, (tuple, list)):
raise ValueError, 'Invalid value for %%n in format: %s' % t raise ValueError('Invalid value for %%n in format: %s' % t)
if len(t) == 2: if len(t) == 2:
return nItems(*t) return nItems(*t)
elif len(t) == 3: elif len(t) == 3:
return nItems(t[0], t[2], between=t[1]) return nItems(t[0], t[2], between=t[1])
else: else:
raise ValueError, 'Invalid value for %%n in format: %s' % t raise ValueError('Invalid value for %%n in format: %s' % t)
elif char == 'S': elif char == 'S':
t = args.pop() t = args.pop()
if not isinstance(t, (int, long)): if not isinstance(t, (int, long)):
raise ValueError, 'Invalid value for %%S in format: %s' % t raise ValueError('Invalid value for %%S in format: %s' % t)
for suffix in ['B','KB','MB','GB','TB']: for suffix in ['B','KB','MB','GB','TB']:
if t < 1024: if t < 1024:
return "%i%s" % (t, suffix) return "%i%s" % (t, suffix)
@ -527,10 +524,10 @@ def format(s, *args, **kwargs):
elif char == '%': elif char == '%':
return '%' return '%'
else: else:
raise ValueError, 'Invalid char in sub (in format).' raise ValueError('Invalid char in sub (in format).')
try: try:
return _formatRe.sub(sub, s) return _formatRe.sub(sub, s)
except IndexError: except IndexError:
raise ValueError, 'Extra format chars in format spec: %r' % s raise ValueError('Extra format chars in format spec: %r' % s)
# vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79: # vim:set shiftwidth=4 softtabstop=4 expandtab textwidth=79:

View File

@ -34,14 +34,14 @@ Data structures for Python.
import time import time
import types import types
import collections import collections
from itertools import imap
class RingBuffer(object): class RingBuffer(object):
"""Class to represent a fixed-size ring buffer.""" """Class to represent a fixed-size ring buffer."""
__slots__ = ('L', 'i', 'full', 'maxSize') __slots__ = ('L', 'i', 'full', 'maxSize')
def __init__(self, maxSize, seq=()): def __init__(self, maxSize, seq=()):
if maxSize <= 0: if maxSize <= 0:
raise ValueError, 'maxSize must be > 0.' raise ValueError('maxSize must be > 0.')
self.maxSize = maxSize self.maxSize = maxSize
self.reset() self.reset()
for elt in seq: for elt in seq:
@ -70,14 +70,15 @@ class RingBuffer(object):
self.maxSize == other.maxSize and len(self) == len(other): self.maxSize == other.maxSize and len(self) == len(other):
iterator = iter(other) iterator = iter(other)
for elt in self: for elt in self:
otherelt = iterator.next() otherelt = next(iterator)
if not elt == otherelt: if not elt == otherelt:
return False return False
return True return True
return False return False
def __nonzero__(self): def __bool__(self):
return len(self) > 0 return len(self) > 0
__nonzero__ = __bool__
def __contains__(self, elt): def __contains__(self, elt):
return elt in self.L return elt in self.L
@ -100,7 +101,7 @@ class RingBuffer(object):
def __getitem__(self, idx): def __getitem__(self, idx):
if self.full: if self.full:
oidx = idx oidx = idx
if type(oidx) == types.SliceType: if isinstance(oidx, types.SliceType):
L = [] L = []
for i in xrange(*slice.indices(oidx, len(self))): for i in xrange(*slice.indices(oidx, len(self))):
L.append(self[i]) L.append(self[i])
@ -108,11 +109,11 @@ class RingBuffer(object):
else: else:
(m, idx) = divmod(oidx, len(self.L)) (m, idx) = divmod(oidx, len(self.L))
if m and m != -1: if m and m != -1:
raise IndexError, oidx raise IndexError(oidx)
idx = (idx + self.i) % len(self.L) idx = (idx + self.i) % len(self.L)
return self.L[idx] return self.L[idx]
else: else:
if type(idx) == types.SliceType: if isinstance(idx, types.SliceType):
L = [] L = []
for i in xrange(*slice.indices(idx, len(self))): for i in xrange(*slice.indices(idx, len(self))):
L.append(self[i]) L.append(self[i])
@ -123,24 +124,24 @@ class RingBuffer(object):
def __setitem__(self, idx, elt): def __setitem__(self, idx, elt):
if self.full: if self.full:
oidx = idx oidx = idx
if type(oidx) == types.SliceType: if isinstance(oidx, types.SliceType):
range_ = xrange(*slice.indices(oidx, len(self))) range_ = xrange(*slice.indices(oidx, len(self)))
if len(range_) != len(elt): if len(range_) != len(elt):
raise ValueError, 'seq must be the same length as slice.' raise ValueError('seq must be the same length as slice.')
else: else:
for (i, x) in zip(range_, elt): for (i, x) in zip(range_, elt):
self[i] = x self[i] = x
else: else:
(m, idx) = divmod(oidx, len(self.L)) (m, idx) = divmod(oidx, len(self.L))
if m and m != -1: if m and m != -1:
raise IndexError, oidx raise IndexError(oidx)
idx = (idx + self.i) % len(self.L) idx = (idx + self.i) % len(self.L)
self.L[idx] = elt self.L[idx] = elt
else: else:
if type(idx) == types.SliceType: if isinstance(idx, types.SliceType):
range_ = xrange(*slice.indices(idx, len(self))) range_ = xrange(*slice.indices(idx, len(self)))
if len(range_) != len(elt): if len(range_) != len(elt):
raise ValueError, 'seq must be the same length as slice.' raise ValueError('seq must be the same length as slice.')
else: else:
for (i, x) in zip(range_, elt): for (i, x) in zip(range_, elt):
self[i] = x self[i] = x
@ -153,7 +154,8 @@ class RingBuffer(object):
def __getstate__(self): def __getstate__(self):
return (self.maxSize, self.full, self.i, self.L) return (self.maxSize, self.full, self.i, self.L)
def __setstate__(self, (maxSize, full, i, L)): def __setstate__(self, state):
(maxSize, full, i, L) = state
self.maxSize = maxSize self.maxSize = maxSize
self.full = full self.full = full
self.i = i self.i = i
@ -196,8 +198,9 @@ class queue(object):
def __len__(self): def __len__(self):
return len(self.front) + len(self.back) return len(self.front) + len(self.back)
def __nonzero__(self): def __bool__(self):
return bool(self.back or self.front) return bool(self.back or self.front)
__nonzero__ = __bool__
def __contains__(self, elt): def __contains__(self, elt):
return elt in self.front or elt in self.back return elt in self.front or elt in self.back
@ -212,7 +215,7 @@ class queue(object):
if len(self) == len(other): if len(self) == len(other):
otheriter = iter(other) otheriter = iter(other)
for elt in self: for elt in self:
otherelt = otheriter.next() otherelt = next(otheriter)
if not (elt == otherelt): if not (elt == otherelt):
return False return False
return True return True
@ -220,12 +223,12 @@ class queue(object):
return False return False
def __repr__(self): def __repr__(self):
return 'queue([%s])' % ', '.join(imap(repr, self)) return 'queue([%s])' % ', '.join(map(repr, self))
def __getitem__(self, oidx): def __getitem__(self, oidx):
if len(self) == 0: if len(self) == 0:
raise IndexError, 'queue index out of range' raise IndexError('queue index out of range')
if type(oidx) == types.SliceType: if isinstance(oidx, types.SliceType):
L = [] L = []
for i in xrange(*slice.indices(oidx, len(self))): for i in xrange(*slice.indices(oidx, len(self))):
L.append(self[i]) L.append(self[i])
@ -233,7 +236,7 @@ class queue(object):
else: else:
(m, idx) = divmod(oidx, len(self)) (m, idx) = divmod(oidx, len(self))
if m and m != -1: if m and m != -1:
raise IndexError, oidx raise IndexError(oidx)
if len(self.front) > idx: if len(self.front) > idx:
return self.front[-(idx+1)] return self.front[-(idx+1)]
else: else:
@ -241,36 +244,36 @@ class queue(object):
def __setitem__(self, oidx, value): def __setitem__(self, oidx, value):
if len(self) == 0: if len(self) == 0:
raise IndexError, 'queue index out of range' raise IndexError('queue index out of range')
if type(oidx) == types.SliceType: if isinstance(oidx, types.SliceType):
range_ = xrange(*slice.indices(oidx, len(self))) range_ = xrange(*slice.indices(oidx, len(self)))
if len(range_) != len(value): if len(range_) != len(value):
raise ValueError, 'seq must be the same length as slice.' raise ValueError('seq must be the same length as slice.')
else: else:
for i in range_: for i in range_:
(m, idx) = divmod(oidx, len(self)) (m, idx) = divmod(oidx, len(self))
if m and m != -1: if m and m != -1:
raise IndexError, oidx raise IndexError(oidx)
for (i, x) in zip(range_, value): for (i, x) in zip(range_, value):
self[i] = x self[i] = x
else: else:
(m, idx) = divmod(oidx, len(self)) (m, idx) = divmod(oidx, len(self))
if m and m != -1: if m and m != -1:
raise IndexError, oidx raise IndexError(oidx)
if len(self.front) > idx: if len(self.front) > idx:
self.front[-(idx+1)] = value self.front[-(idx+1)] = value
else: else:
self.back[idx-len(self.front)] = value self.back[idx-len(self.front)] = value
def __delitem__(self, oidx): def __delitem__(self, oidx):
if type(oidx) == types.SliceType: if isinstance(oidx, types.SliceType):
range_ = xrange(*slice.indices(oidx, len(self))) range_ = xrange(*slice.indices(oidx, len(self)))
for i in range_: for i in range_:
del self[i] del self[i]
else: else:
(m, idx) = divmod(oidx, len(self)) (m, idx) = divmod(oidx, len(self))
if m and m != -1: if m and m != -1:
raise IndexError, oidx raise IndexError(oidx)
if len(self.front) > idx: if len(self.front) > idx:
del self.front[-(idx+1)] del self.front[-(idx+1)]
else: else:
@ -279,7 +282,8 @@ class queue(object):
def __getstate__(self): def __getstate__(self):
return (list(self),) return (list(self),)
def __setstate__(self, (L,)): def __setstate__(self, state):
(L,) = state
L.reverse() L.reverse()
self.front = L self.front = L
self.back = [] self.back = []
@ -296,7 +300,7 @@ class smallqueue(list):
return self[0] return self[0]
def __repr__(self): def __repr__(self):
return 'smallqueue([%s])' % ', '.join(imap(repr, self)) return 'smallqueue([%s])' % ', '.join(map(repr, self))
def reset(self): def reset(self):
self[:] = [] self[:] = []
@ -363,7 +367,8 @@ class MaxLengthQueue(queue):
def __getstate__(self): def __getstate__(self):
return (self.length, queue.__getstate__(self)) return (self.length, queue.__getstate__(self))
def __setstate__(self, (length, q)): def __setstate__(self, state):
(length, q) = state
self.length = length self.length = length
queue.__setstate__(self, q) queue.__setstate__(self, q)

View File

@ -107,7 +107,7 @@ class Transaction(TransactionMixin):
raise FailedAcquisition(self.txnDir) raise FailedAcquisition(self.txnDir)
try: try:
os.rename(self.txnDir, self.dir) os.rename(self.txnDir, self.dir)
except EnvironmentError, e: except EnvironmentError as e:
raise FailedAcquisition(self.txnDir, e) raise FailedAcquisition(self.txnDir, e)
os.mkdir(self.dirize(self.ORIGINALS)) os.mkdir(self.dirize(self.ORIGINALS))
os.mkdir(self.dirize(self.REPLACEMENTS)) os.mkdir(self.dirize(self.REPLACEMENTS))

View File

@ -125,19 +125,19 @@ def getUrlFd(url, headers=None, data=None, timeout=None):
request.set_proxy(httpProxy, 'http') request.set_proxy(httpProxy, 'http')
fd = urllib2.urlopen(request, timeout=timeout) fd = urllib2.urlopen(request, timeout=timeout)
return fd return fd
except socket.timeout, e: except socket.timeout as e:
raise Error, TIMED_OUT raise Error(TIMED_OUT)
except sockerrors, e: except sockerrors as e:
raise Error, strError(e) raise Error(strError(e))
except httplib.InvalidURL, e: except httplib.InvalidURL as e:
raise Error, 'Invalid URL: %s' % e raise Error('Invalid URL: %s' % e)
except urllib2.HTTPError, e: except urllib2.HTTPError as e:
raise Error, strError(e) raise Error(strError(e))
except urllib2.URLError, e: except urllib2.URLError as e:
raise Error, strError(e.reason) raise Error(strError(e.reason))
# Raised when urllib doesn't recognize the url type # Raised when urllib doesn't recognize the url type
except ValueError, e: except ValueError as e:
raise Error, strError(e) raise Error(strError(e))
def getUrl(url, size=None, headers=None, data=None): def getUrl(url, size=None, headers=None, data=None):
"""getUrl(url, size=None, headers=None, data=None) """getUrl(url, size=None, headers=None, data=None)
@ -151,8 +151,8 @@ def getUrl(url, size=None, headers=None, data=None):
text = fd.read() text = fd.read()
else: else:
text = fd.read(size) text = fd.read(size)
except socket.timeout, e: except socket.timeout as e:
raise Error, TIMED_OUT raise Error(TIMED_OUT)
fd.close() fd.close()
return text return text

View File

@ -118,7 +118,7 @@ def flush():
for (i, f) in enumerate(flushers): for (i, f) in enumerate(flushers):
try: try:
f() f()
except Exception, e: except Exception as e:
log.exception('Uncaught exception in flusher #%s (%s):', i, f) log.exception('Uncaught exception in flusher #%s (%s):', i, f)
def debugFlush(s=''): def debugFlush(s=''):

View File

@ -138,7 +138,7 @@ class FunctionsTestCase(SupyTestCase):
':ACTION beats ang senseless with a 50lb Unix manual (#2)', ':ACTION beats ang senseless with a 50lb Unix manual (#2)',
':supybot!~supybot@underthemain.net PRIVMSG #sourcereview ' ':supybot!~supybot@underthemain.net PRIVMSG #sourcereview '
':ACTION resizes angryman\'s terminal to 40x24 (#16)'] ':ACTION resizes angryman\'s terminal to 40x24 (#16)']
msgs = map(ircmsgs.IrcMsg, L) msgs = list(map(ircmsgs.IrcMsg, L))
for msg in msgs: for msg in msgs:
self.failUnless(ircmsgs.isAction(msg)) self.failUnless(ircmsgs.isAction(msg))

View File

@ -479,7 +479,7 @@ class IterTest(SupyTestCase):
self.assertEqual(lflatten(range(10)), list(range(10))) self.assertEqual(lflatten(range(10)), list(range(10)))
twoRanges = list(range(10))*2 twoRanges = list(range(10))*2
twoRanges.sort() twoRanges.sort()
self.assertEqual(lflatten(zip(range(10), range(10))), twoRanges) self.assertEqual(lflatten(list(zip(range(10), range(10)))), twoRanges)
self.assertEqual(lflatten([1, [2, 3], 4]), [1, 2, 3, 4]) self.assertEqual(lflatten([1, [2, 3], 4]), [1, 2, 3, 4])
self.assertEqual(lflatten([[[[[[[[[[]]]]]]]]]]), []) self.assertEqual(lflatten([[[[[[[[[[]]]]]]]]]]), [])
self.assertEqual(lflatten([1, [2, [3, 4], 5], 6]), [1, 2, 3, 4, 5, 6]) self.assertEqual(lflatten([1, [2, [3, 4], 5], 6]), [1, 2, 3, 4, 5, 6])