From 35a62b4e77a3f273f6055f737fa0aecdb78372ff Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Tue, 21 Jan 2014 10:40:18 +0100 Subject: [PATCH] Continue accelerating the 2to3 step (remove fix_ws_comma, fix_xreadlines, and fix_zip). --- plugins/Factoids/plugin.py | 4 ++-- plugins/Filter/plugin.py | 6 +++--- plugins/Format/plugin.py | 2 +- plugins/Karma/plugin.py | 2 +- plugins/Nickometer/plugin.py | 4 ++-- plugins/Web/plugin.py | 2 +- setup.py | 3 +-- src/callbacks.py | 4 ++-- src/commands.py | 8 ++++---- src/irclib.py | 8 ++++---- src/ircutils.py | 4 ++-- src/log.py | 4 ++-- src/utils/python.py | 6 +++--- src/utils/str.py | 4 ++-- test/test_utils.py | 2 +- 15 files changed, 31 insertions(+), 32 deletions(-) diff --git a/plugins/Factoids/plugin.py b/plugins/Factoids/plugin.py index 34d3e2f58..9b5e604b0 100644 --- a/plugins/Factoids/plugin.py +++ b/plugins/Factoids/plugin.py @@ -244,7 +244,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): def getCommandHelp(self, command, simpleSyntax=None): method = self.getCommandMethod(command) - if method.im_func.func_name == 'learn': + if method.im_func.__name__ == 'learn': chan = None if dynamic.msg is not None: chan = dynamic.msg.args[0] @@ -352,7 +352,7 @@ class Factoids(callbacks.Plugin, plugins.ChannelDBHandler): return [] flkeys = [line[0] for line 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: return [key for key,item in dict_metrics.iteritems() if item <= 2] if min(dl_metrics) <= 3: diff --git a/plugins/Filter/plugin.py b/plugins/Filter/plugin.py index 31921d28d..c34b012a7 100644 --- a/plugins/Filter/plugin.py +++ b/plugins/Filter/plugin.py @@ -241,8 +241,8 @@ class Filter(callbacks.Plugin): irc.reply(text) lithp = wrap(lithp, ['text']) - _leettrans = utils.str.MultipleReplacer(dict(zip('oOaAeElBTiIts', - '004433187!1+5'))) + _leettrans = utils.str.MultipleReplacer(dict(list(zip('oOaAeElBTiIts', + '004433187!1+5')))) _leetres = [(re.compile(r'\b(?:(?:[yY][o0O][oO0uU])|u)\b'), 'j00'), (re.compile(r'fear'), 'ph33r'), (re.compile(r'[aA][tT][eE]'), '8'), @@ -662,7 +662,7 @@ class Filter(callbacks.Plugin): irc.reply(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 def azn(self, irc, msg, args, text): """ diff --git a/plugins/Format/plugin.py b/plugins/Format/plugin.py index 72b5ceecf..4417b2a17 100644 --- a/plugins/Format/plugin.py +++ b/plugins/Format/plugin.py @@ -102,7 +102,7 @@ class Format(callbacks.Plugin): if len(bad) != len(good): irc.error(_(' must be the same length as ' '.'), 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']) @internationalizeDocstring diff --git a/plugins/Karma/plugin.py b/plugins/Karma/plugin.py index 713a3f128..3d1a46d94 100644 --- a/plugins/Karma/plugin.py +++ b/plugins/Karma/plugin.py @@ -93,7 +93,7 @@ class SqliteKarmaDB(object): def gets(self, channel, things): db = self._getDb(channel) cursor = db.cursor() - normalizedThings = dict(zip(map(lambda s: s.lower(), things), things)) + normalizedThings = dict(list(zip(map(lambda s: s.lower(), things), things))) criteria = ' OR '.join(['normalized=?'] * len(normalizedThings)) sql = """SELECT name, added-subtracted FROM karma WHERE %s ORDER BY added-subtracted DESC""" % criteria diff --git a/plugins/Nickometer/plugin.py b/plugins/Nickometer/plugin.py index e282eb7ec..cf9da917d 100644 --- a/plugins/Nickometer/plugin.py +++ b/plugins/Nickometer/plugin.py @@ -119,8 +119,8 @@ class Nickometer(callbacks.Plugin): ('\\[rkx]0', 1000), ('\\0[rkx]', 1000)] - letterNumberTranslator = utils.str.MultipleReplacer(dict(zip( - '023457+8', 'ozeasttb'))) + letterNumberTranslator = utils.str.MultipleReplacer(dict(list(zip( + '023457+8', 'ozeasttb')))) for special in specialCost: tempNick = nick if special[0][0] != '\\': diff --git a/plugins/Web/plugin.py b/plugins/Web/plugin.py index d9ec16893..20bb233b8 100644 --- a/plugins/Web/plugin.py +++ b/plugins/Web/plugin.py @@ -93,7 +93,7 @@ def fetch_sandbox(f): try: replies = commands.process(process, self, irc, *args, timeout=5, heap_size=1024*1024, - pn=self.name(), cn=f.func_name) + pn=self.name(), cn=f.__name__) except commands.ProcessTimeoutError: raise utils.web.Error(_('Page is too big.')) else: diff --git a/setup.py b/setup.py index 5e8c8adf3..cdf29a3e6 100644 --- a/setup.py +++ b/setup.py @@ -156,8 +156,7 @@ try: 'fix_map', 'fix_metaclass', 'fix_methodattrs', 'fix_numliterals', 'fix_types', - 'fix_unicode', 'fix_urllib', 'fix_ws_comma', 'fix_xrange', - 'fix_xreadlines', 'fix_zip'] + '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) diff --git a/src/callbacks.py b/src/callbacks.py index 3ac8b6538..f3300f3d7 100644 --- a/src/callbacks.py +++ b/src/callbacks.py @@ -1170,7 +1170,7 @@ class Commands(BasePlugin): if hasattr(self, name): method = getattr(self, name) if inspect.ismethod(method): - code = method.im_func.func_code + code = method.im_func.__code__ return inspect.getargs(code)[0] == self.commandArgs else: return False @@ -1217,7 +1217,7 @@ class Commands(BasePlugin): else: method = getattr(self, command[0]) if inspect.ismethod(method): - code = method.im_func.func_code + code = method.im_func.__code__ if inspect.getargs(code)[0] == self.commandArgs: return method else: diff --git a/src/commands.py b/src/commands.py index 981664fe7..0c56226d7 100644 --- a/src/commands.py +++ b/src/commands.py @@ -67,7 +67,7 @@ def thread(f): t.start() else: 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): """Gets raised when a process is killed due to timeout.""" @@ -219,7 +219,7 @@ def urlSnarfer(f): L = list(L) t = UrlSnarfThread(target=doSnarf, url=url) t.start() - newf = utils.python.changeFunctionName(newf, f.func_name, f.__doc__) + newf = utils.python.changeFunctionName(newf, f.__name__, f.__doc__) return newf @@ -1068,7 +1068,7 @@ class Spec(object): return state 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__), \ 'Command %r has no docstring.' % name f = internationalizeDocstring(f) @@ -1084,7 +1084,7 @@ def _wrap(f, specList=[], name=None, checkDoc=True, **kw): except TypeError: self.log.error('Spec: %s', specList) self.log.error('Received args: %s', args) - code = f.func_code + code = f.__code__ funcArgs = inspect.getargs(code)[0][len(self.commandArgs):] self.log.error('Extra args: %s', funcArgs) self.log.debug('Make sure you did not wrap a wrapped ' diff --git a/src/irclib.py b/src/irclib.py index 0772fbea9..51aea419d 100644 --- a/src/irclib.py +++ b/src/irclib.py @@ -435,9 +435,9 @@ class IrcState(IrcCommandDispatcher): assert left[0] == '(', 'Odd PREFIX in 005: %s' % s left = left[1:] assert len(left) == len(right), 'Odd PREFIX in 005: %s' % s - return dict(zip(left, right)) + return dict(list(zip(left, right))) else: - return dict(zip('ovh', s)) + return dict(list(zip('ovh', s))) _005converters['prefix'] = _prefixParser del _prefixParser def _maxlistParser(s): @@ -448,7 +448,7 @@ class IrcState(IrcCommandDispatcher): (mode, limit) = pair.split(':', 1) modes += mode limits += (int(limit),) * len(mode) - return dict(zip(modes, limits)) + return dict(list(zip(modes, limits))) _005converters['maxlist'] = _maxlistParser del _maxlistParser def _maxbansParser(s): @@ -461,7 +461,7 @@ class IrcState(IrcCommandDispatcher): (mode, limit) = pair.split(':', 1) modes += mode limits += (int(limit),) * len(mode) - d = dict(zip(modes, limits)) + d = dict(list(zip(modes, limits))) assert 'b' in d return d['b'] else: diff --git a/src/ircutils.py b/src/ircutils.py index c032799c3..33974fcc8 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -97,9 +97,9 @@ def joinHostmask(nick, ident, host): assert nick and ident and 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_lowercase + r'|{}^'))) + string.ascii_lowercase + r'|{}^')))) def toLower(s, casemapping=None): """s => s Returns the string s lowered according to IRC case rules.""" diff --git a/src/log.py b/src/log.py index eaf85e120..b5425e4e9 100644 --- a/src/log.py +++ b/src/log.py @@ -346,7 +346,7 @@ def firewall(f, errorHandler=None): logging_function = self.log.exception else: 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): try: return f(self, *args, **kwargs) @@ -359,7 +359,7 @@ def firewall(f, errorHandler=None): return errorHandler(self, *args, **kwargs) except Exception as e: 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 class MetaFirewall(type): diff --git a/src/utils/python.py b/src/utils/python.py index ca704e71a..4b9008204 100644 --- a/src/utils/python.py +++ b/src/utils/python.py @@ -58,8 +58,8 @@ def universalImport(*names): def changeFunctionName(f, name, doc=None): if doc is None: doc = f.__doc__ - newf = types.FunctionType(f.func_code, f.func_globals, name, - f.func_defaults, f.func_closure) + newf = types.FunctionType(f.__code__, f.__globals__, name, + f.__defaults__, f.__closure__) newf.__doc__ = doc return newf @@ -86,7 +86,7 @@ class Synchronized(type): f(self, *args, **kwargs) finally: lock.release() - return changeFunctionName(g, f.func_name, f.__doc__) + return changeFunctionName(g, f.__name__, f.__doc__) for attr in sync: if attr in dict: dict[attr] = synchronized(dict[attr]) diff --git a/src/utils/str.py b/src/utils/str.py index a5e49597a..61387c970 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -114,8 +114,8 @@ class MultipleRemover: def __call__(self, s): return self._matcher.sub(lambda m: '', s) -_soundextrans = MultipleReplacer(dict(zip(string.ascii_uppercase, - '01230120022455012623010202'))) +_soundextrans = MultipleReplacer(dict(list(zip(string.ascii_uppercase, + '01230120022455012623010202')))) def soundex(s, length=4): """Returns the soundex hash of a given string. diff --git a/test/test_utils.py b/test/test_utils.py index 1919c1e09..bffb0d0b0 100644 --- a/test/test_utils.py +++ b/test/test_utils.py @@ -479,7 +479,7 @@ class IterTest(SupyTestCase): self.assertEqual(lflatten(range(10)), list(range(10))) twoRanges = list(range(10))*2 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([[[[[[[[[[]]]]]]]]]]), []) self.assertEqual(lflatten([1, [2, [3, 4], 5], 6]), [1, 2, 3, 4, 5, 6])