changeset 8177:e26c0616e003

py3: use global next() function instead of .next() method From 2to3 -f next.
author Mads Kiilerich <mads@kiilerich.com>
date Mon, 16 Dec 2019 02:37:05 +0100
parents d2904a0c5d41
children 1886705c4a8c
files kallithea/lib/diffs.py kallithea/lib/helpers.py kallithea/lib/indexers/__init__.py kallithea/lib/middleware/wrapper.py kallithea/lib/vcs/subprocessio.py kallithea/tests/other/test_vcs_operations.py kallithea/tests/scripts/manual_test_concurrency.py
diffstat 7 files changed, 21 insertions(+), 21 deletions(-) [+]
line wrap: on
line diff
--- a/kallithea/lib/diffs.py	Sat Nov 23 21:28:37 2019 +0100
+++ b/kallithea/lib/diffs.py	Mon Dec 16 02:37:05 2019 +0100
@@ -418,22 +418,22 @@
             for chunk in diff_data['chunks']:
                 lineiter = iter(chunk)
                 try:
-                    peekline = lineiter.next()
+                    peekline = next(lineiter)
                     while True:
                         # find a first del line
                         while peekline['action'] != 'del':
-                            peekline = lineiter.next()
+                            peekline = next(lineiter)
                         delline = peekline
-                        peekline = lineiter.next()
+                        peekline = next(lineiter)
                         # if not followed by add, eat all following del lines
                         if peekline['action'] != 'add':
                             while peekline['action'] == 'del':
-                                peekline = lineiter.next()
+                                peekline = next(lineiter)
                             continue
                         # found an add - make sure it is the only one
                         addline = peekline
                         try:
-                            peekline = lineiter.next()
+                            peekline = next(lineiter)
                         except StopIteration:
                             # add was last line - ok
                             _highlight_inline_diff(delline, addline)
@@ -560,7 +560,7 @@
 
     chunks = []
     try:
-        line = diff_lines.next()
+        line = next(diff_lines)
 
         while True:
             lines = []
@@ -591,7 +591,7 @@
                         'line':       line,
                     })
 
-            line = diff_lines.next()
+            line = next(diff_lines)
 
             while old_line < old_end or new_line < new_end:
                 if not line:
@@ -624,7 +624,7 @@
                         'line':         line[1:],
                     })
 
-                line = diff_lines.next()
+                line = next(diff_lines)
 
                 if _newline_marker.match(line):
                     # we need to append to lines, since this is not
@@ -635,7 +635,7 @@
                         'action':       'context',
                         'line':         line,
                     })
-                    line = diff_lines.next()
+                    line = next(diff_lines)
             if old_line > old_end:
                 raise Exception('error parsing diff - more than %s "-" lines at -%s+%s' % (old_end, old_line, new_line))
             if new_line > new_end:
--- a/kallithea/lib/helpers.py	Sat Nov 23 21:28:37 2019 +0100
+++ b/kallithea/lib/helpers.py	Mon Dec 16 02:37:05 2019 +0100
@@ -387,7 +387,7 @@
         if cs in color_dict:
             col = color_dict[cs]
         else:
-            col = color_dict[cs] = cgenerator.next()
+            col = color_dict[cs] = next(cgenerator)
         return "color: rgb(%s)! important;" % (', '.join(col))
 
     def url_func(changeset):
--- a/kallithea/lib/indexers/__init__.py	Sat Nov 23 21:28:37 2019 +0100
+++ b/kallithea/lib/indexers/__init__.py	Mon Dec 16 02:37:05 2019 +0100
@@ -146,7 +146,7 @@
             docnum = self.matcher.id()
             chunks = [offsets for offsets in self.get_chunks()]
             docs_id.append([docnum, chunks])
-            self.matcher.next()
+            self.matcher.next()  # this looks like a py2 iterator ... but it isn't
         return docs_id
 
     def __str__(self):
--- a/kallithea/lib/middleware/wrapper.py	Sat Nov 23 21:28:37 2019 +0100
+++ b/kallithea/lib/middleware/wrapper.py	Mon Dec 16 02:37:05 2019 +0100
@@ -63,14 +63,14 @@
 
     def __init__(self, result, meter, description):
         self._result_close = getattr(result, 'close', None) or (lambda: None)
-        self._next = iter(result).next
+        self._next = iter(result).__next__
         self._meter = meter
         self._description = description
 
     def __iter__(self):
         return self
 
-    def next(self):
+    def __next__(self):
         chunk = self._next()
         self._meter.measure(chunk)
         return chunk
--- a/kallithea/lib/vcs/subprocessio.py	Sat Nov 23 21:28:37 2019 +0100
+++ b/kallithea/lib/vcs/subprocessio.py	Mon Dec 16 02:37:05 2019 +0100
@@ -178,7 +178,7 @@
     def __iter__(self):
         return self
 
-    def next(self):
+    def __next__(self):
         while not len(self.data) and not self.worker.EOF.is_set():
             self.worker.data_added.clear()
             self.worker.data_added.wait(0.2)
@@ -389,7 +389,7 @@
     def __iter__(self):
         return self
 
-    def next(self):
+    def __next__(self):
         if self.process:
             returncode = self.process.poll()
             if (returncode is not None # process has terminated
@@ -399,7 +399,7 @@
                 self.error.stop()
                 err = ''.join(self.error)
                 raise EnvironmentError("Subprocess exited due to an error:\n" + err)
-        return self.output.next()
+        return next(self.output)
 
     def throw(self, type, value=None, traceback=None):
         if self.output.length or not self.output.done_reading:
--- a/kallithea/tests/other/test_vcs_operations.py	Sat Nov 23 21:28:37 2019 +0100
+++ b/kallithea/tests/other/test_vcs_operations.py	Mon Dec 16 02:37:05 2019 +0100
@@ -178,7 +178,7 @@
     :param vcs:
     :param dest_dir:
     """
-    added_file = '%ssetup.py' % _RandomNameSequence().next()
+    added_file = '%ssetup.py' % next(_RandomNameSequence())
     open(os.path.join(dest_dir, added_file), 'a').close()
     Command(dest_dir).execute(vcs, 'add', added_file)
 
@@ -263,9 +263,9 @@
     @pytest.fixture(scope="module")
     def testfork(self):
         # create fork so the repo stays untouched
-        git_fork_name = u'%s_fork%s' % (base.GIT_REPO, _RandomNameSequence().next())
+        git_fork_name = u'%s_fork%s' % (base.GIT_REPO, next(_RandomNameSequence()))
         fixture.create_fork(base.GIT_REPO, git_fork_name)
-        hg_fork_name = u'%s_fork%s' % (base.HG_REPO, _RandomNameSequence().next())
+        hg_fork_name = u'%s_fork%s' % (base.HG_REPO, next(_RandomNameSequence()))
         fixture.create_fork(base.HG_REPO, hg_fork_name)
         return {'git': git_fork_name, 'hg': hg_fork_name}
 
@@ -319,7 +319,7 @@
         Session().commit()
 
         # Create an empty server repo using the API
-        repo_name = u'new_%s_%s' % (vt.repo_type, _RandomNameSequence().next())
+        repo_name = u'new_%s_%s' % (vt.repo_type, next(_RandomNameSequence()))
         usr = User.get_by_username(base.TEST_USER_ADMIN_LOGIN)
         params = {
             "id": 7,
--- a/kallithea/tests/scripts/manual_test_concurrency.py	Sat Nov 23 21:28:37 2019 +0100
+++ b/kallithea/tests/scripts/manual_test_concurrency.py	Mon Dec 16 02:37:05 2019 +0100
@@ -202,7 +202,7 @@
             backend = 'hg'
 
         if METHOD == 'pull':
-            seq = tempfile._RandomNameSequence().next()
+            seq = next(tempfile._RandomNameSequence())
             test_clone_with_credentials(repo=sys.argv[1], method='clone',
                                         backend=backend)
         s = time.time()