From ca419f6485dcc7a11ac336f90328c69e55ea2e1c Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 20 Jan 2014 16:04:53 +0100 Subject: [PATCH] Continue accelerating the 2to3 step (remove fix_reduce, fix_renames, fix_repr, fix_set_literal, fix_standarderror, fix_sys_exc, fix_throw, and fix_tuple_params). --- plugins/Admin/plugin.py | 2 +- plugins/Channel/plugin.py | 2 +- plugins/Nickometer/plugin.py | 4 ++-- plugins/User/plugin.py | 2 +- plugins/__init__.py | 9 ++++++--- setup.py | 4 +--- src/ircdb.py | 2 +- src/irclib.py | 4 ++-- src/log.py | 8 +++++--- src/shlex.py | 8 ++++---- src/utils/structures.py | 9 ++++++--- 11 files changed, 30 insertions(+), 24 deletions(-) diff --git a/plugins/Admin/plugin.py b/plugins/Admin/plugin.py index d5057475d..c71afcdf5 100644 --- a/plugins/Admin/plugin.py +++ b/plugins/Admin/plugin.py @@ -151,7 +151,7 @@ class Admin(callbacks.Plugin): networkGroup.channels().add(channel) if 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: irc.error(_('I\'m already too close to maximum number of ' 'channels for this network.'), Raise=True) diff --git a/plugins/Channel/plugin.py b/plugins/Channel/plugin.py index bdbc5e191..9a32d8b4f 100644 --- a/plugins/Channel/plugin.py +++ b/plugins/Channel/plugin.py @@ -279,7 +279,7 @@ class Channel(callbacks.Plugin): irc.error(_('I cowardly refuse to kick myself.'), Raise=True) if not reason: reason = msg.nick - kicklen = irc.state.supported.get('kicklen', sys.maxint) + kicklen = irc.state.supported.get('kicklen', sys.maxsize) if len(reason) > kicklen: irc.error(_('The reason you gave is longer than the allowed ' 'length for a KICK reason on this server.'), diff --git a/plugins/Nickometer/plugin.py b/plugins/Nickometer/plugin.py index fd7d596a9..e282eb7ec 100644 --- a/plugins/Nickometer/plugin.py +++ b/plugins/Nickometer/plugin.py @@ -163,7 +163,7 @@ class Nickometer(callbacks.Plugin): # Punish k3wlt0k k3wlt0k_weights = (5, 5, 2, 5, 2, 3, 1, 2, 2, 2) for i in range(len(k3wlt0k_weights)): - hits=re.findall(`i`, nick) + hits=re.findall(repr(i), nick) if (hits and len(hits)>0): score += self.punish(k3wlt0k_weights[i] * len(hits) * 30, '%s occurrences of %s ' % (len(hits), i)) @@ -225,7 +225,7 @@ class Nickometer(callbacks.Plugin): (1 - 1 / (1 + score / 5.0)) // 2 # 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%%.') % (originalNick, score_string)) diff --git a/plugins/User/plugin.py b/plugins/User/plugin.py index b35da1434..fa4b17721 100644 --- a/plugins/User/plugin.py +++ b/plugins/User/plugin.py @@ -415,7 +415,7 @@ class User(callbacks.Plugin): def _expire_tokens(self): 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())) @internationalizeDocstring diff --git a/plugins/__init__.py b/plugins/__init__.py index bde416a26..57edd67a1 100644 --- a/plugins/__init__.py +++ b/plugins/__init__.py @@ -191,15 +191,18 @@ class ChannelUserDictionary(collections.MutableMapping): def __init__(self): self.channels = ircutils.IrcDict() - def __getitem__(self, (channel, id)): + def __getitem__(self, key): + (channel, id) = key 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: self.channels[channel] = self.IdDict() self.channels[channel][id] = v - def __delitem__(self, (channel, id)): + def __delitem__(self, key): + (channel, id) = key del self.channels[channel][id] def __iter__(self): diff --git a/setup.py b/setup.py index 60c9c08fc..5e8c8adf3 100644 --- a/setup.py +++ b/setup.py @@ -155,9 +155,7 @@ try: 'fix_itertools', 'fix_itertools_imports', 'fix_long', 'fix_map', 'fix_metaclass', 'fix_methodattrs', 'fix_numliterals', - 'fix_reduce', 'fix_renames', 'fix_repr', - 'fix_set_literal', 'fix_standarderror', 'fix_sys_exc', - 'fix_throw', 'fix_tuple_params', 'fix_types', + 'fix_types', 'fix_unicode', 'fix_urllib', 'fix_ws_comma', 'fix_xrange', 'fix_xreadlines', 'fix_zip'] fixers = list(map(lambda x:'lib2to3.fixes.'+x, fixer_names)) diff --git a/src/ircdb.py b/src/ircdb.py index a888b3fb4..25ae3168a 100644 --- a/src/ircdb.py +++ b/src/ircdb.py @@ -693,7 +693,7 @@ class UsersDictionary(utils.IterableMap): try: self._hostmaskCache[id].add(s) except KeyError: - self._hostmaskCache[id] = set([s]) + self._hostmaskCache[id] = {s} return id elif len(ids) == 0: raise KeyError(s) diff --git a/src/irclib.py b/src/irclib.py index fd599b6cd..0772fbea9 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -628,9 +628,9 @@ class Irc(IrcCommandDispatcher): __firewalled__ = {'die': None, 'feedMsg': None, 'takeMsg': None,} - _nickSetters = set(['001', '002', '003', '004', '250', '251', '252', + _nickSetters = {'001', '002', '003', '004', '250', '251', '252', '254', '255', '265', '266', '372', '375', '376', - '333', '353', '332', '366', '005']) + '333', '353', '332', '366', '005'} # We specifically want these callbacks to be common between all Ircs, # that's why we don't do the normal None default with a check. def __init__(self, network, callbacks=_callbacks): diff --git a/src/log.py b/src/log.py index 3922f6963..eaf85e120 100644 --- a/src/log.py +++ b/src/log.py @@ -52,7 +52,8 @@ class Formatter(logging.Formatter): def formatTime(self, record, datefmt=None): return timestamp(record.created) - def formatException(self, (E, e, tb)): + def formatException(self, exc_info): + (E, e, tb) = exc_info for exn in deadlyExceptions: if issubclass(e.__class__, exn): raise @@ -113,7 +114,7 @@ class StdoutStreamHandler(logging.StreamHandler): exception('Uncaught exception in StdoutStreamHandler:') def disable(self): - self.setLevel(sys.maxint) # Just in case. + self.setLevel(sys.maxsize) # Just in case. _logger.removeHandler(self) logging._acquireLock() try: @@ -142,7 +143,8 @@ class ColorizedFormatter(Formatter): # This was necessary because these variables aren't defined until later. # The staticmethod is necessary because they get treated like methods. _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(): return ''.join([ansi.RED, Formatter.formatException(self, (E, e, tb)), diff --git a/src/shlex.py b/src/shlex.py index d2e364342..3d48235b9 100644 --- a/src/shlex.py +++ b/src/shlex.py @@ -37,7 +37,7 @@ class shlex: def push_token(self, tok): "Push a token onto the stack popped by the get_token method" if self.debug >= 1: - print("shlex: pushing token " + `tok`) + print("shlex: pushing token " + repr(tok)) self.pushback = [tok] + self.pushback def push_source(self, newstream, newfile=None): @@ -68,7 +68,7 @@ class shlex: tok = self.pushback[0] self.pushback = self.pushback[1:] if self.debug >= 1: - print("shlex: popping token " + `tok`) + print("shlex: popping token " + repr(tok)) return tok # No pushback. Get a token. raw = self.read_token() @@ -89,7 +89,7 @@ class shlex: # Neither inclusion nor EOF if self.debug >= 1: if raw: - print("shlex: token=" + `raw`) + print("shlex: token=" + repr(raw)) else: print("shlex: token=EOF") return raw @@ -180,7 +180,7 @@ class shlex: self.token = '' if self.debug > 1: if result: - print("shlex: raw token=" + `result`) + print("shlex: raw token=" + repr(result)) else: print("shlex: raw token=EOF") return result diff --git a/src/utils/structures.py b/src/utils/structures.py index 865ddd155..6e8e5e371 100644 --- a/src/utils/structures.py +++ b/src/utils/structures.py @@ -154,7 +154,8 @@ class RingBuffer(object): def __getstate__(self): 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.full = full self.i = i @@ -281,7 +282,8 @@ class queue(object): def __getstate__(self): return (list(self),) - def __setstate__(self, (L,)): + def __setstate__(self, state): + (L,) = state L.reverse() self.front = L self.back = [] @@ -365,7 +367,8 @@ class MaxLengthQueue(queue): def __getstate__(self): return (self.length, queue.__getstate__(self)) - def __setstate__(self, (length, q)): + def __setstate__(self, state): + (length, q) = state self.length = length queue.__setstate__(self, q)