Continue accelerating the 2to3 step (remove fix_idioms, fix_imports2, fix_input, fix_intern, fix_isinstance, fix_ne, fix_next, and fix_raw_input).

This commit is contained in:
Valentin Lorentz 2014-01-20 15:13:01 +01:00
parent 4652c9ce51
commit d1649a44ac
14 changed files with 35 additions and 33 deletions

View File

@ -73,7 +73,7 @@ class Connection:
"""Used when expecting multiple lines of text -- gets the block
part only. Does not get any codes or anything! Returns a string."""
data = []
while 1:
while True:
line = self.rfile.readline().decode('utf8').strip()
if line == '.':
break
@ -194,7 +194,7 @@ class Connection:
if code != 150:
raise Exception, "Unknown code %d" % code
while 1:
while True:
code, text = self.getresultcode()
if code != 151 or code is None:
break

View File

@ -416,7 +416,7 @@ class Filter(callbacks.Plugin):
if sys.version_info[0] < 3:
text = text.decode('utf-8')
colors = utils.iter.cycle(['04', '07', '08', '03', '02', '12', '06'])
L = [self._color(c, fg=colors.next()) for c in text]
L = [self._color(c, fg=next(colors)) for c in text]
if sys.version_info[0] < 3:
L = [c.encode('utf-8') for c in L]
irc.reply(''.join(L) + '\x03')

View File

@ -450,7 +450,7 @@ class Misc(callbacks.Plugin):
if skipfirst:
# Drop the first message only if our current channel is the same as
# the channel we've been instructed to look at.
iterable.next()
next(iterable)
predicates = list(utils.iter.flatten(predicates.itervalues()))
# Make sure the user can't get messages from channels they aren't in
def userInChannel(m):

View File

@ -145,7 +145,7 @@ class Nickometer(callbacks.Plugin):
'%s consecutive non-alphas ' % len(match))
# Remove balanced brackets ...
while 1:
while True:
nickInitial = nick
nick=re.sub('^([^()]*)(\()(.*)(\))([^()]*)$', '\1\3\5', nick, 1)
nick=re.sub('^([^{}]*)(\{)(.*)(\})([^{}]*)$', '\1\3\5', nick, 1)

View File

@ -216,7 +216,7 @@ class String(callbacks.Plugin):
encryption.
"""
chars = utils.iter.cycle(password)
ret = [chr(ord(c) ^ ord(chars.next())) for c in text]
ret = [chr(ord(c) ^ ord(next(chars))) for c in text]
irc.reply(''.join(ret))
xor = wrap(xor, ['something', 'text'])

View File

@ -151,13 +151,12 @@ try:
fixer_names = ['fix_basestring',
'fix_dict', 'fix_except',
'fix_funcattrs',
'fix_idioms', 'fix_imports', 'fix_imports2',
'fix_input', 'fix_intern', 'fix_isinstance',
'fix_imports',
'fix_itertools', 'fix_itertools_imports', 'fix_long',
'fix_map', 'fix_metaclass', 'fix_methodattrs', 'fix_ne',
'fix_next', 'fix_nonzero', 'fix_numliterals',
'fix_map', 'fix_metaclass', 'fix_methodattrs',
'fix_nonzero', 'fix_numliterals',
'fix_operator', 'fix_paren', 'fix_print', 'fix_raise',
'fix_raw_input', 'fix_reduce', 'fix_renames', 'fix_repr',
'fix_reduce', 'fix_renames', 'fix_repr',
'fix_set_literal', 'fix_standarderror', 'fix_sys_exc',
'fix_throw', 'fix_tuple_params', 'fix_types',
'fix_unicode', 'fix_urllib', 'fix_ws_comma', 'fix_xrange',

View File

@ -118,7 +118,7 @@ def make(dbFilename, readFilename=None):
else:
readfd = open(readFilename, 'rb')
maker = Maker(dbFilename)
while 1:
while True:
(initchar, key, value) = _readKeyValue(readfd)
if initchar is None:
break
@ -318,7 +318,7 @@ class ReaderWriter(utils.IterableMap):
adds = {}
try:
fd = open(self.journalName, 'r')
while 1:
while True:
(initchar, key, value) = _readKeyValue(fd)
if initchar is None:
break

View File

@ -839,7 +839,7 @@ class Databases(registry.SpaceSeparatedListOfStrings):
def __call__(self):
v = super(Databases, self).__call__()
if not v:
v = ['anydbm', 'cdb', 'flat', 'pickle']
v = ['anydbm', 'dbm', 'cdb', 'flat', 'pickle']
if 'sqlite' in sys.modules:
v.insert(0, 'sqlite')
if 'sqlite3' in sys.modules:

View File

@ -87,13 +87,13 @@ def splitHostmask(hostmask):
assert isUserHostmask(hostmask)
nick, rest = hostmask.split('!', 1)
user, host = rest.split('@', 1)
return (intern(nick), intern(user), intern(host))
return (sys.intern(nick), sys.intern(user), sys.intern(host))
def joinHostmask(nick, ident, host):
"""nick, user, host => hostmask
Joins the nick, ident, host into a user hostmask."""
assert nick and ident and host
return intern('%s!%s@%s' % (nick, ident, host))
return sys.intern('%s!%s@%s' % (nick, ident, host))
_rfc1459trans = utils.str.MultipleReplacer(dict(zip(
string.ascii_uppercase + r'\[]~',

View File

@ -76,7 +76,10 @@ def expect(prompt, possibilities, recursed=False, default=None,
if useBold:
prompt += ansi.RESET
print >>fd, ansi.BOLD,
s = raw_input(prompt)
if sys.version_info[0] >= 3:
s = input(prompt)
else:
s = raw_input(prompt)
s = s.strip()
print >>fd
if possibilities:

View File

@ -96,7 +96,7 @@ class shlex:
def read_token(self):
"Read a token from the input stream (no pushback or inclusions)"
while 1:
while True:
nextchar = self.instream.read(1)
if nextchar == '\n':
self.lineno = self.lineno + 1
@ -190,7 +190,7 @@ class shlex:
if newfile[0] == '"':
newfile = newfile[1:-1]
# This implements cpp-like semantics for relative-path inclusion.
if type(self.infile) == type("") and not os.path.isabs(newfile):
if isinstance(self.infile, basestring) and not os.path.isabs(newfile):
newfile = os.path.join(os.path.dirname(self.infile), newfile)
return (newfile, open(newfile, "r"))
@ -210,7 +210,7 @@ if __name__ == '__main__':
file = sys.argv[1]
with open(file) as fd:
lexer = shlex(fd, file)
while 1:
while True:
tt = lexer.get_token()
if tt:
print "Token: " + repr(tt)

View File

@ -44,7 +44,7 @@ def join(L):
def split(s):
fd = StringIO.StringIO(s)
reader = csv.reader(fd)
return reader.next()
return next(reader)
csv.join = join
csv.split = split

View File

@ -48,7 +48,7 @@ def len(iterable):
return i
def trueCycle(iterable):
while 1:
while True:
yielded = False
for x in iterable:
yield x
@ -141,7 +141,7 @@ def startswith(long_, short):
shortI = iter(short)
try:
while True:
if shortI.next() != longI.next():
if next(shortI) != next(longI):
return False
except StopIteration:
return True
@ -151,7 +151,7 @@ def limited(iterable, limit):
iterable = iter(iterable)
try:
while i:
yield iterable.next()
yield next(iterable)
i -= 1
except StopIteration:
raise ValueError, 'Expected %s elements in iterable (%r), got %s.' % \

View File

@ -70,7 +70,7 @@ class RingBuffer(object):
self.maxSize == other.maxSize and len(self) == len(other):
iterator = iter(other)
for elt in self:
otherelt = iterator.next()
otherelt = next(iterator)
if not elt == otherelt:
return False
return True
@ -100,7 +100,7 @@ class RingBuffer(object):
def __getitem__(self, idx):
if self.full:
oidx = idx
if type(oidx) == types.SliceType:
if isinstance(oidx, types.SliceType):
L = []
for i in xrange(*slice.indices(oidx, len(self))):
L.append(self[i])
@ -112,7 +112,7 @@ class RingBuffer(object):
idx = (idx + self.i) % len(self.L)
return self.L[idx]
else:
if type(idx) == types.SliceType:
if isinstance(idx, types.SliceType):
L = []
for i in xrange(*slice.indices(idx, len(self))):
L.append(self[i])
@ -123,7 +123,7 @@ class RingBuffer(object):
def __setitem__(self, idx, elt):
if self.full:
oidx = idx
if type(oidx) == types.SliceType:
if isinstance(oidx, types.SliceType):
range_ = xrange(*slice.indices(oidx, len(self)))
if len(range_) != len(elt):
raise ValueError, 'seq must be the same length as slice.'
@ -137,7 +137,7 @@ class RingBuffer(object):
idx = (idx + self.i) % len(self.L)
self.L[idx] = elt
else:
if type(idx) == types.SliceType:
if isinstance(idx, types.SliceType):
range_ = xrange(*slice.indices(idx, len(self)))
if len(range_) != len(elt):
raise ValueError, 'seq must be the same length as slice.'
@ -212,7 +212,7 @@ class queue(object):
if len(self) == len(other):
otheriter = iter(other)
for elt in self:
otherelt = otheriter.next()
otherelt = next(otheriter)
if not (elt == otherelt):
return False
return True
@ -225,7 +225,7 @@ class queue(object):
def __getitem__(self, oidx):
if len(self) == 0:
raise IndexError, 'queue index out of range'
if type(oidx) == types.SliceType:
if isinstance(oidx, types.SliceType):
L = []
for i in xrange(*slice.indices(oidx, len(self))):
L.append(self[i])
@ -242,7 +242,7 @@ class queue(object):
def __setitem__(self, oidx, value):
if len(self) == 0:
raise IndexError, 'queue index out of range'
if type(oidx) == types.SliceType:
if isinstance(oidx, types.SliceType):
range_ = xrange(*slice.indices(oidx, len(self)))
if len(range_) != len(value):
raise ValueError, 'seq must be the same length as slice.'
@ -263,7 +263,7 @@ class queue(object):
self.back[idx-len(self.front)] = value
def __delitem__(self, oidx):
if type(oidx) == types.SliceType:
if isinstance(oidx, types.SliceType):
range_ = xrange(*slice.indices(oidx, len(self)))
for i in range_:
del self[i]