From 3cbca4b7348b60eb6cfe3f423983d53dada67862 Mon Sep 17 00:00:00 2001 From: xmo-odoo Date: Tue, 25 Apr 2017 13:04:54 +0200 Subject: [PATCH] [FIX] iterator definition & stepping * in P3, the iterator stepping method has become a dunder method (next -> __next__), the protocol has not changed, add a __next__ alias to the iterator-next definition (nota: ir.config also has a next method but it's not part of an iterator, so don't alias it and don't convert calls to it) * since ~2.6, a builtin (next()) has been added to step an iterator & allow for a default (in case of iterator end), convert all manual stepping to the builtin Fixers: libfuturize.fixes.fix_next_call #8530 --- addons/l10n_lu/scripts/tax2csv.py | 8 ++++---- odoo/tools/convert.py | 2 +- odoo/tools/misc.py | 3 ++- odoo/tools/translate.py | 7 ++++--- odoo/tools/which.py | 12 ++++-------- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/addons/l10n_lu/scripts/tax2csv.py b/addons/l10n_lu/scripts/tax2csv.py index c6a5bed6e44..710ebea9d88 100644 --- a/addons/l10n_lu/scripts/tax2csv.py +++ b/addons/l10n_lu/scripts/tax2csv.py @@ -59,7 +59,7 @@ class LuxTaxGenerator: writer = csv.writer(open('account.tax.code.template-%s.csv' % self.suffix, 'wb')) tax_codes_iterator = self.iter_tax_codes() - keys = tax_codes_iterator.next() + keys = next(tax_codes_iterator) writer.writerow(keys) # write structure tax codes @@ -87,7 +87,7 @@ class LuxTaxGenerator: new_tax_codes[tax_code_id] = (new_name, new_parent_code) taxes_iterator = self.iter_taxes() - keys = taxes_iterator.next() + next(taxes_iterator) for row in taxes_iterator: if not _is_true(row['active']): continue @@ -157,7 +157,7 @@ class LuxTaxGenerator: writer = csv.writer(open('account.tax.template-%s.csv' % self.suffix, 'wb')) taxes_iterator = self.iter_taxes() - keys = taxes_iterator.next() + keys = next(taxes_iterator) writer.writerow(keys[3:] + ['sequence']) seq = 100 for row in sorted(taxes_iterator, key=lambda r: r['description']): @@ -175,7 +175,7 @@ class LuxTaxGenerator: 'position.tax.template-%s.csv' % self.suffix, 'wb')) fiscal_pos_map_iterator = self.iter_fiscal_pos_map() - keys = fiscal_pos_map_iterator.next() + keys = next(fiscal_pos_map_iterator) writer.writerow(keys) for row in fiscal_pos_map_iterator: writer.writerow(map(_e, row.values())) diff --git a/odoo/tools/convert.py b/odoo/tools/convert.py index c7faab244d3..3410b929bc6 100644 --- a/odoo/tools/convert.py +++ b/odoo/tools/convert.py @@ -850,7 +850,7 @@ def convert_csv_import(cr, module, fname, csvcontent, idref=None, mode='init', input = cStringIO.StringIO(csvcontent) #FIXME reader = csv.reader(input, quotechar='"', delimiter=',') - fields = reader.next() + fields = next(reader) if not (mode == 'init' or 'id' in fields): _logger.error("Import specification does not contain 'id' and we are in init mode, Cannot continue.") diff --git a/odoo/tools/misc.py b/odoo/tools/misc.py index ebeb65c3523..f080d3067ca 100644 --- a/odoo/tools/misc.py +++ b/odoo/tools/misc.py @@ -376,7 +376,7 @@ def scan_languages(): result = [] with open(csvpath) as csvfile: reader = csv.reader(csvfile, delimiter=',', quotechar='"') - fields = reader.next() + fields = next(reader) code_index = fields.index("code") name_index = fields.index("name") for row in reader: @@ -833,6 +833,7 @@ class CountingStream(object): self.stopped = True raise StopIteration() return val + __next__ = next def stripped_sys_argv(*strip_args): """Return sys.argv with some arguments stripped, suitable for reexecution or subprocesses""" diff --git a/odoo/tools/translate.py b/odoo/tools/translate.py index 850e911d608..16a7bd9015e 100644 --- a/odoo/tools/translate.py +++ b/odoo/tools/translate.py @@ -533,7 +533,7 @@ class PoFile(object): raise StopIteration() line = self.lines.pop(0) # This has been a deprecated entry, don't return anything - return self.next() + return next(self) if not line.startswith('msgid'): raise Exception("malformed file: bad line: %s" % line) @@ -547,7 +547,7 @@ class PoFile(object): self.extra_lines = [] while line: line = self.lines.pop(0).strip() - return self.next() + return next(self) while not line.startswith('msgstr'): if not line: @@ -574,8 +574,9 @@ class PoFile(object): if not fuzzy: _logger.warning('Missing "#:" formated comment at line %d for the following source:\n\t%s', self.cur_line(), source[:30]) - return self.next() + return next(self) return trans_type, name, res_id, source, trad, '\n'.join(comments) + __next__ = next def write_infos(self, modules): import odoo.release as release diff --git a/odoo/tools/which.py b/odoo/tools/which.py index 548b836247c..7c37c5fb674 100755 --- a/odoo/tools/which.py +++ b/odoo/tools/which.py @@ -44,6 +44,7 @@ __all__ = 'which which_files pathsep defpath defpathext F_OK R_OK W_OK X_OK'.spl import sys from os import access, defpath, pathsep, environ, F_OK, R_OK, W_OK, X_OK from os.path import exists, dirname, split, join +ENOENT = 2 windows = sys.platform.startswith('win') @@ -138,15 +139,10 @@ def which(file, mode=F_OK | X_OK, path=None, pathext=None): >>> # for doctest see which_files() """ - try: - return iter(which_files(file, mode, path, pathext)).next() - except StopIteration: - try: - from errno import ENOENT - except ImportError: - ENOENT = 2 + path = next(which_files(file, mode, path, pathext), None) + if path is None: raise IOError(ENOENT, '%s not found' % (mode & X_OK and 'command' or 'file'), file) - + return path if __name__ == '__main__': import doctest