From 2c380a4c3a89aedf15048a8a66022821e6da9dff Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 10 Aug 2015 19:36:07 +0200 Subject: [PATCH] Remove fix_xrange. --- plugins/Aka/plugin.py | 2 +- plugins/Filter/plugin.py | 2 +- plugins/Games/plugin.py | 2 +- plugins/Games/test.py | 2 +- plugins/Misc/plugin.py | 2 +- plugins/ShrinkUrl/plugin.py | 2 +- plugins/Topic/plugin.py | 2 +- setup.py | 2 +- src/cdb.py | 4 ++-- src/utils/gen.py | 2 +- src/utils/seq.py | 10 +++++----- src/utils/str.py | 10 +++++----- src/utils/structures.py | 14 +++++++------- 13 files changed, 28 insertions(+), 28 deletions(-) diff --git a/plugins/Aka/plugin.py b/plugins/Aka/plugin.py index 8d5ec8ba8..0529c6363 100644 --- a/plugins/Aka/plugin.py +++ b/plugins/Aka/plugin.py @@ -414,7 +414,7 @@ class Aka(callbacks.Plugin): if ret: return [first] + ret max_length = self.registryValue('maximumWordsInName') - for i in xrange(1, min(len(args)+1, max_length)): + for i in range(1, min(len(args)+1, max_length)): if self.isCommandMethod(callbacks.formatCommand(args[0:i])): return args[0:i] return [] diff --git a/plugins/Filter/plugin.py b/plugins/Filter/plugin.py index ad90f72d2..c9d614106 100644 --- a/plugins/Filter/plugin.py +++ b/plugins/Filter/plugin.py @@ -183,7 +183,7 @@ class Filter(callbacks.Plugin): Assumes ASCII, 8 digits per character. """ try: - L = [chr(int(text[i:(i+8)], 2)) for i in xrange(0, len(text), 8)] + L = [chr(int(text[i:(i+8)], 2)) for i in range(0, len(text), 8)] irc.reply(''.join(L)) except ValueError: irc.errorInvalid('binary string', text) diff --git a/plugins/Games/plugin.py b/plugins/Games/plugin.py index d6b5ad5ed..fa96aa9d0 100644 --- a/plugins/Games/plugin.py +++ b/plugins/Games/plugin.py @@ -73,7 +73,7 @@ class Games(callbacks.Plugin): irc.error(_('Dice can\'t have fewer than 3 sides.')) else: L = [0] * dice - for i in xrange(dice): + for i in range(dice): L[i] = random.randrange(1, sides+1) irc.reply(format('%L', [str(x) for x in L])) _dicere = re.compile(r'^(\d+)d(\d+)$') diff --git a/plugins/Games/test.py b/plugins/Games/test.py index 1ed0563c8..aa971b033 100644 --- a/plugins/Games/test.py +++ b/plugins/Games/test.py @@ -35,7 +35,7 @@ class GamesTestCase(ChannelPluginTestCase): def testRoulette(self): self.irc.feedMsg(ircmsgs.op(self.channel, self.irc.nick)) sawKick = False - for i in xrange(100): + for i in range(100): m = self.getMsg('roulette', frm='someoneElse') if m.command == 'PRIVMSG': self.failUnless(self._nonKickRe.search(m.args[1]), diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index 8c575e113..00fd32eb9 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -386,7 +386,7 @@ class Misc(callbacks.Plugin): try: L = irc._mores[userHostmask] number = self.registryValue('mores', msg.args[0]) - chunks = [L.pop() for x in xrange(0, number)] + chunks = [L.pop() for x in range(0, number)] if L: if len(L) < 2: more = _('1 more message') diff --git a/plugins/ShrinkUrl/plugin.py b/plugins/ShrinkUrl/plugin.py index a854d14c3..899b0e1ef 100644 --- a/plugins/ShrinkUrl/plugin.py +++ b/plugins/ShrinkUrl/plugin.py @@ -76,7 +76,7 @@ class ShrinkError(Exception): def retry(f): def newf(*args, **kwargs): - for x in xrange(0, 3): + for x in range(0, 3): try: return f(*args, **kwargs) except Exception: diff --git a/plugins/Topic/plugin.py b/plugins/Topic/plugin.py index 970dba90b..402b268f4 100644 --- a/plugins/Topic/plugin.py +++ b/plugins/Topic/plugin.py @@ -378,7 +378,7 @@ class Topic(callbacks.Plugin): irc.error(_('I cannot reorder 1 or fewer topics.'), Raise=True) if len(numbers) != num: irc.error(_('All topic numbers must be specified.'), Raise=True) - if sorted(numbers) != range(num): + if sorted(numbers) != list(range(num)): irc.error(_('Duplicate topic numbers cannot be specified.')) return newtopics = [topics[i] for i in numbers] diff --git a/setup.py b/setup.py index fa542b786..a29faa046 100644 --- a/setup.py +++ b/setup.py @@ -160,7 +160,7 @@ try: fixer_names = ['fix_basestring', 'fix_metaclass', 'fix_numliterals', - '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/cdb.py b/src/cdb.py index 546545b50..a96a43861 100644 --- a/src/cdb.py +++ b/src/cdb.py @@ -136,7 +136,7 @@ class Maker(object): self.hashPointers = [(0, 0)] * 256 #self.hashes = [[]] * 256 # Can't use this, [] stays the same... self.hashes = [] - for _ in xrange(256): + for _ in range(256): self.hashes.append([]) def add(self, key, data): @@ -154,7 +154,7 @@ class Maker(object): Writes the remainder of the database to disk. """ - for i in xrange(256): + for i in range(256): hash = self.hashes[i] self.hashPointers[i] = (self.fd.tell(), self._serializeHash(hash)) self._serializeHashPointers() diff --git a/src/utils/gen.py b/src/utils/gen.py index 8d95ac520..3dad5e08f 100644 --- a/src/utils/gen.py +++ b/src/utils/gen.py @@ -66,7 +66,7 @@ def warn_non_constant_time(f): def abbrev(strings, d=None): """Returns a dictionary mapping unambiguous abbreviations to full forms.""" def eachSubstring(s): - for i in xrange(1, len(s)+1): + for i in range(1, len(s)+1): yield s[:i] if len(strings) != len(set(strings)): raise ValueError( diff --git a/src/utils/seq.py b/src/utils/seq.py index 0fa37e492..18de963c7 100644 --- a/src/utils/seq.py +++ b/src/utils/seq.py @@ -34,7 +34,7 @@ def window(L, size): assert not isinstance(L, int), 'Argument order swapped: window(L, size)' if size < 1: raise ValueError('size <= 0 disallowed.') - for i in xrange(len(L) - (size-1)): + for i in range(len(L) - (size-1)): yield L[i:i+size] def mapinto(f, L): @@ -42,7 +42,7 @@ def mapinto(f, L): L[i] = f(x) def renumerate(L): - for i in xrange(len(L)-1, -1, -1): + for i in range(len(L)-1, -1, -1): yield (i, L[i]) def dameraulevenshtein(seq1, seq2): @@ -74,13 +74,13 @@ def dameraulevenshtein(seq1, seq2): # so we only store those. # Sourced from http://mwh.geek.nz/2009/04/26/python-damerau-levenshtein-distance/ oneago = None - thisrow = range(1, len(seq2) + 1) + [0] - for x in xrange(len(seq1)): + thisrow = list(range(1, len(seq2) + 1)) + [0] + for x in range(len(seq1)): # Python lists wrap around for negative indices, so put the # leftmost column at the *end* of the list. This matches with # the zero-indexed strings and saves extra calculation. twoago, oneago, thisrow = oneago, thisrow, [0] * len(seq2) + [x + 1] - for y in xrange(len(seq2)): + for y in range(len(seq2)): delcost = oneago[y] + 1 addcost = thisrow[y - 1] + 1 subcost = oneago[y - 1] + (seq1[x] != seq2[y]) diff --git a/src/utils/str.py b/src/utils/str.py index 44898af0e..40fac75b5 100644 --- a/src/utils/str.py +++ b/src/utils/str.py @@ -114,15 +114,15 @@ def distance(s, t): elif m == 0: return n d = [] - for i in xrange(n+1): + for i in range(n+1): d.append([]) - for j in xrange(m+1): + for j in range(m+1): d[i].append(0) d[0][j] = j d[i][0] = i - for i in xrange(1, n+1): + for i in range(1, n+1): cs = s[i-1] - for j in xrange(1, m+1): + for j in range(1, m+1): ct = t[j-1] cost = int(cs != ct) d[i][j] = min(d[i-1][j]+1, d[i][j-1]+1, d[i-1][j-1]+cost) @@ -271,7 +271,7 @@ def perlReToReplacer(s): raise ValueError('Must be of the form s/.../.../') regexp = regexp.replace('\x08', r'\b') replace = replace.replace('\\'+sep, sep) - for i in xrange(10): + for i in range(10): replace = replace.replace(chr(i), r'\%s' % i) g = False if 'g' in flags: diff --git a/src/utils/structures.py b/src/utils/structures.py index e4951fe48..0631e46cb 100644 --- a/src/utils/structures.py +++ b/src/utils/structures.py @@ -103,7 +103,7 @@ class RingBuffer(object): oidx = idx if isinstance(oidx, slice): L = [] - for i in xrange(*slice.indices(oidx, len(self))): + for i in range(*slice.indices(oidx, len(self))): L.append(self[i]) return L else: @@ -115,7 +115,7 @@ class RingBuffer(object): else: if isinstance(idx, slice): L = [] - for i in xrange(*slice.indices(idx, len(self))): + for i in range(*slice.indices(idx, len(self))): L.append(self[i]) return L else: @@ -125,7 +125,7 @@ class RingBuffer(object): if self.full: oidx = idx if isinstance(oidx, slice): - range_ = xrange(*slice.indices(oidx, len(self))) + range_ = range(*slice.indices(oidx, len(self))) if len(range_) != len(elt): raise ValueError('seq must be the same length as slice.') else: @@ -139,7 +139,7 @@ class RingBuffer(object): self.L[idx] = elt else: if isinstance(idx, slice): - range_ = xrange(*slice.indices(idx, len(self))) + range_ = range(*slice.indices(idx, len(self))) if len(range_) != len(elt): raise ValueError('seq must be the same length as slice.') else: @@ -230,7 +230,7 @@ class queue(object): raise IndexError('queue index out of range') if isinstance(oidx, slice): L = [] - for i in xrange(*slice.indices(oidx, len(self))): + for i in range(*slice.indices(oidx, len(self))): L.append(self[i]) return L else: @@ -246,7 +246,7 @@ class queue(object): if len(self) == 0: raise IndexError('queue index out of range') if isinstance(oidx, slice): - range_ = xrange(*slice.indices(oidx, len(self))) + range_ = range(*slice.indices(oidx, len(self))) if len(range_) != len(value): raise ValueError('seq must be the same length as slice.') else: @@ -267,7 +267,7 @@ class queue(object): def __delitem__(self, oidx): if isinstance(oidx, slice): - range_ = xrange(*slice.indices(oidx, len(self))) + range_ = range(*slice.indices(oidx, len(self))) for i in range_: del self[i] else: