Continue accelerating the 2to3 step (remove fix_ws_comma, fix_xreadlines, and fix_zip).

This commit is contained in:
Valentin Lorentz 2014-01-21 10:40:18 +01:00
parent ca419f6485
commit 35a62b4e77
15 changed files with 31 additions and 32 deletions

View File

@ -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:

View File

@ -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):
"""<text>

View File

@ -102,7 +102,7 @@ class Format(callbacks.Plugin):
if len(bad) != len(good):
irc.error(_('<chars to translate> must be the same length as '
'<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'])
@internationalizeDocstring

View File

@ -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

View File

@ -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] != '\\':

View File

@ -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:

View File

@ -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)

View File

@ -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:

View File

@ -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 '

View File

@ -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:

View File

@ -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."""

View File

@ -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):

View File

@ -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])

View File

@ -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.

View File

@ -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])