Remove fix_xrange.

This commit is contained in:
Valentin Lorentz 2015-08-10 19:36:07 +02:00
parent 23ddfbc7e3
commit 2c380a4c3a
13 changed files with 28 additions and 28 deletions

View File

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

View File

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

View File

@ -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+)$')

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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