File python-django-waliki-sh2-compat.patch of Package python-django-waliki

From 9088c4fb44eab32e523f395736198516c08a2bc0 Mon Sep 17 00:00:00 2001
From: Oleg Girko <ol@infoserver.lv>
Date: Tue, 17 Oct 2023 22:30:03 +0100
Subject: [PATCH] Compatibility fixes for sh 2.0.

Since sh 2.0, commands return str instead of sh.RunningCommand.
Using explicit conversion to str allows to extract stdout of running commands
in the way compatible with older and newer versions of sh.

Signed-off-by: Oleg Girko <ol@infoserver.lv>
---
 tests/test_git.py                              | 14 +++++++-------
 waliki/git/models.py                           | 18 +++++++++---------
 .../commands/moin_migration_cleanup.py         |  6 +++---
 3 files changed, 19 insertions(+), 19 deletions(-)

diff --git a/tests/test_git.py b/tests/test_git.py
index cb24fad..dd17a6f 100644
--- a/tests/test_git.py
+++ b/tests/test_git.py
@@ -14,7 +14,7 @@ from waliki.git.models import Git
 from waliki.settings import WALIKI_DATA_DIR, WALIKI_COMMITTER_EMAIL, WALIKI_COMMITTER_NAME
 from .factories import PageFactory
 
-git = git.bake("--no-pager", _tty_out=False)
+git = git.bake("--no-pager", _tty_out=False, _encoding='UTF-8')
 
 class TestGit(TestCase):
 
@@ -27,8 +27,8 @@ class TestGit(TestCase):
         shutil.rmtree(git_dir)
         Git()
         self.assertTrue(os.path.isdir(git_dir))
-        self.assertEqual(git.config('user.name').stdout.decode('utf8')[:-1], WALIKI_COMMITTER_NAME)
-        self.assertEqual(git.config('user.email').stdout.decode('utf8')[:-1], WALIKI_COMMITTER_EMAIL)
+        self.assertEqual(str(git.config('user.name'))[:-1], WALIKI_COMMITTER_NAME)
+        self.assertEqual(str(git.config('user.email'))[:-1], WALIKI_COMMITTER_EMAIL)
 
     def test_commit_existent_page_with_no_previous_commits(self):
         response = self.client.get(self.edit_url)
@@ -109,8 +109,8 @@ class TestGit(TestCase):
         r = self.client.post(self.edit_url, data2)
         self.assertRedirects(r, self.edit_url)
 
-        self.assertEqual('', git.status('--porcelain', self.page.path).stdout.decode('utf8'))
-        self.assertIn('Merged with conflict', git.log("--no-color", "--pretty=format:%s", "-n 1", self.page.path).stdout.decode('utf8'))
+        self.assertEqual('', str(git.status('--porcelain', self.page.path)))
+        self.assertIn('Merged with conflict', str(git.log("--no-color", "--pretty=format:%s", "-n 1", self.page.path)))
         self.assertRegexpMatches(self.page.raw,'<<<<<<< HEAD\n- item2\n=======\n- item0\n>>>>>>> [0-9a-f]{7}\n')
 
         # can edit in conflict
@@ -150,8 +150,8 @@ class TestGit(TestCase):
         self.assertRedirects(response, url)
 
         # file committed with conflict
-        self.assertEqual('', git.status('--porcelain', page.path).stdout.decode('utf8'))
-        self.assertIn('Merged with conflict', git.log("--pretty=format:%s", "-n 1", page.path).stdout.decode('utf8'))
+        self.assertEqual('', str(git.status('--porcelain', page.path)))
+        self.assertIn('Merged with conflict', str(git.log("--pretty=format:%s", "-n 1", page.path)))
 
         self.assertRegexpMatches(page.raw, r"""<<<<<<< HEAD\n- item2
 =======\n- item0\n>>>>>>> [0-9a-f]{7}\n""")
diff --git a/waliki/git/models.py b/waliki/git/models.py
index 3f3e45f..3c72e09 100644
--- a/waliki/git/models.py
+++ b/waliki/git/models.py
@@ -15,7 +15,7 @@ from waliki.models import Page
 from waliki.utils import is_authenticated
 
 
-git = git.bake("--no-pager", _tty_out=False)
+git = git.bake("--no-pager", _tty_out=False, _encoding='UTF-8')
 Commit = namedtuple('Commit', ['hash', 'author_name', 'author_email', 'subject', 'date', 'date_relative', 'paths', 'diff'])
 
 
@@ -47,7 +47,7 @@ class Git(object):
 
         try:
             there_were_changes = parent and parent != self.last_version(page)
-            status = git.status('--porcelain', path).stdout.decode('utf8')[:2]
+            status = str(git.status('--porcelain', path))[:2]
             if parent and status != "UU":
                 git.stash()
                 git.checkout('--detach', parent)
@@ -103,7 +103,7 @@ class Git(object):
 
     def version(self, page, version):
         try:
-            return git.show('%s:%s' % (version, page.path)).stdout.decode('utf8')
+            return str(git.show('%s:%s' % (version, page.path)))
         except:
             return ''
 
@@ -120,7 +120,7 @@ class Git(object):
         args = ["--pretty=format:%s" % GIT_LOG_FORMAT, '--skip=%d' % skip]
         if max_count:
             args.append('--max-count=%d' % max_count)
-        raw_log = git.whatchanged(*args).stdout.decode('utf8')
+        raw_log = str(git.whatchanged(*args))
         logs = re.findall(r'((.*)\x1f(.*)\x1f(.*)\x1f(.*)\x1f(.*))?\n:.*\t(.*)', raw_log, flags=re.MULTILINE | re.UNICODE)
 
         for log in logs:
@@ -135,7 +135,7 @@ class Git(object):
             args = ['--no-color', '-p', '--format="%x1f"', '--skip=%d' % skip]
             if max_count:
                 args.append('--max-count=%d' % max_count)
-            diffs = git.log(*args).stdout.decode('utf8').split('\x1f')[1:]
+            diffs = str(git.log(*args)).split('\x1f')[1:]
             return zip(pages, diffs)
         return pages
 
@@ -143,20 +143,20 @@ class Git(object):
         return self.whatchanged(max_count=20, include_diff=True)
 
     def pull(self, remote):
-        log = git.pull('-s', 'recursive', '-X', 'ours', remote, 'HEAD').stdout.decode('utf8')
+        log = str(git.pull('-s', 'recursive', '-X', 'ours', remote, 'HEAD'))
         return log
 
     def diff(self, page, new, old):
-        return git.diff('--no-color', new, old, '--', page.path).stdout.decode('utf8')
+        return str(git.diff('--no-color', new, old, '--', page.path))
 
     def total_commits(self, to='HEAD', page=None):
         args = ['rev-list', to, '--count']
         if page:
             args += ['--', page.path]
-        return git(*args).stdout.decode('utf8')[:-1]
+        return str(git(*args))[:-1]
 
     def mv(self, sender, page, old_path, author, message, commit=True):
-        status = git.status('--porcelain', old_path).stdout.decode('utf8')[1:2]
+        status = str(git.status('--porcelain', old_path))[1:2]
         extra_path = ''
         if status in ('D', 'M'):
             git.rm(old_path)
diff --git a/waliki/management/commands/moin_migration_cleanup.py b/waliki/management/commands/moin_migration_cleanup.py
index 3bdf90a..0d2d994 100644
--- a/waliki/management/commands/moin_migration_cleanup.py
+++ b/waliki/management/commands/moin_migration_cleanup.py
@@ -12,8 +12,8 @@ except ImportError:
 
 try:
     from sh import pandoc, echo
-    pandoc = pandoc.bake(_tty_out=False)
-    echo = echo.bake(_tty_out=False)
+    pandoc = pandoc.bake(_tty_out=False, _encoding='UTF-8')
+    echo = echo.bake(_tty_out=False, _encoding='UTF-8')
 except ImportError:
     pandoc = None
 
@@ -109,7 +109,7 @@ def code(rst_content):
         source = match.groups()[0]
         source = '\n'.join(l.strip() for l in source.split('\n'))
         source = "<pre>%s</pre>" % source
-        rst_source = pandoc(echo(source), f='html', t='rst').stdout.decode('utf8')
+        rst_source = str(pandoc(echo(source), f='html', t='rst'))
         # rst_source = rst_source.strip().replace('\n', '\n   ') + '\n'
         return rst_source
     result = re.sub(pattern, convert, rst_content, flags=re.DOTALL | re.MULTILINE)
-- 
2.41.0