From d1649a44acbd2cfbf3ef20c07ffcd3b6098d182d Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Mon, 20 Jan 2014 15:13:01 +0100 Subject: [PATCH] Continue accelerating the 2to3 step (remove fix_idioms, fix_imports2, fix_input, fix_intern, fix_isinstance, fix_ne, fix_next, and fix_raw_input). --- plugins/Dict/local/dictclient.py | 4 ++-- plugins/Filter/plugin.py | 2 +- plugins/Misc/plugin.py | 2 +- plugins/Nickometer/plugin.py | 2 +- plugins/String/plugin.py | 2 +- setup.py | 9 ++++----- src/cdb.py | 4 ++-- src/conf.py | 2 +- src/ircutils.py | 4 ++-- src/questions.py | 5 ++++- src/shlex.py | 6 +++--- src/utils/__init__.py | 2 +- src/utils/iter.py | 6 +++--- src/utils/structures.py | 18 +++++++++--------- 14 files changed, 35 insertions(+), 33 deletions(-) diff --git a/plugins/Dict/local/dictclient.py b/plugins/Dict/local/dictclient.py index fa11a7008..8c54f7407 100644 --- a/plugins/Dict/local/dictclient.py +++ b/plugins/Dict/local/dictclient.py @@ -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 diff --git a/plugins/Filter/plugin.py b/plugins/Filter/plugin.py index 0dc8732c6..31921d28d 100644 --- a/plugins/Filter/plugin.py +++ b/plugins/Filter/plugin.py @@ -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') diff --git a/plugins/Misc/plugin.py b/plugins/Misc/plugin.py index 8cea01705..781098d59 100644 --- a/plugins/Misc/plugin.py +++ b/plugins/Misc/plugin.py @@ -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): diff --git a/plugins/Nickometer/plugin.py b/plugins/Nickometer/plugin.py index c7370a4bc..fd7d596a9 100644 --- a/plugins/Nickometer/plugin.py +++ b/plugins/Nickometer/plugin.py @@ -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) diff --git a/plugins/String/plugin.py b/plugins/String/plugin.py index 8f001340c..212c12cab 100644 --- a/plugins/String/plugin.py +++ b/plugins/String/plugin.py @@ -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']) diff --git a/setup.py b/setup.py index 070c43c0d..656300e75 100644 --- a/setup.py +++ b/setup.py @@ -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', diff --git a/src/cdb.py b/src/cdb.py index 150860239..17eecf27a 100644 --- a/src/cdb.py +++ b/src/cdb.py @@ -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 diff --git a/src/conf.py b/src/conf.py index 9b3b0441f..5e1214295 100644 --- a/src/conf.py +++ b/src/conf.py @@ -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: diff --git a/src/ircutils.py b/src/ircutils.py index 428db6269..241cd3450 100644 --- a/src/ircutils.py +++ b/src/ircutils.py @@ -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'\[]~', diff --git a/src/questions.py b/src/questions.py index 998a9b3e0..9a9d8d172 100644 --- a/src/questions.py +++ b/src/questions.py @@ -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: diff --git a/src/shlex.py b/src/shlex.py index dcfbbe658..fa2f7e11e 100644 --- a/src/shlex.py +++ b/src/shlex.py @@ -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) diff --git a/src/utils/__init__.py b/src/utils/__init__.py index 4e26f8d60..6d1de1002 100644 --- a/src/utils/__init__.py +++ b/src/utils/__init__.py @@ -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 diff --git a/src/utils/iter.py b/src/utils/iter.py index f4039341e..1416859b5 100644 --- a/src/utils/iter.py +++ b/src/utils/iter.py @@ -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.' % \ diff --git a/src/utils/structures.py b/src/utils/structures.py index 3b2910397..25c4ceff1 100644 --- a/src/utils/structures.py +++ b/src/utils/structures.py @@ -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]