From 0248858e9cb6e42a80528a067b2282382295b678 Mon Sep 17 00:00:00 2001 From: Guido Günther Date: Fri, 23 Oct 2015 18:19:07 +0200 Subject: Open changelogs as utf-8 They must be utf-8 encoded accoding to policy: https://www.debian.org/doc/debian-policy/ch-source.html#s-dpkgchangelog This helps python3 compatibility if the system encoding isn't utf-8. --- gbp/deb/changelog.py | 6 +++--- gbp/scripts/dch.py | 4 ++-- tests/11_test_dch_main.py | 2 +- tests/test_Changelog.py | 4 ++-- tests/testutils/__init__.py | 2 +- 5 files changed, 9 insertions(+), 9 deletions(-) diff --git a/gbp/deb/changelog.py b/gbp/deb/changelog.py index b30a68a..0fcfab9 100644 --- a/gbp/deb/changelog.py +++ b/gbp/deb/changelog.py @@ -117,7 +117,7 @@ class ChangeLog(object): self._cp = cp def _read(self): - with open(self.filename) as f: + with open(self.filename, encoding='utf-8') as f: self._contents = f.read() def __getitem__(self, item): @@ -264,8 +264,8 @@ class ChangeLog(object): dch = Command('debchange', args, extra_env=env) dch.call([]) if msg: - old_cl = open("debian/changelog", "r") - new_cl = open("debian/changelog.bak", "w") + old_cl = open("debian/changelog", "r", encoding='utf-8') + new_cl = open("debian/changelog.bak", "w", encoding='utf-8') for line in old_cl: if line == " * [[[insert-git-dch-commit-message-here]]]\n": print(" * " + msg[0], file=new_cl) diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py index 230d908..32aac04 100644 --- a/gbp/scripts/dch.py +++ b/gbp/scripts/dch.py @@ -139,8 +139,8 @@ def mangle_changelog(changelog, cp, snapshot=''): """ try: tmpfile = '%s.%s' % (changelog, snapshot) - cw = open(tmpfile, 'w') - cr = open(changelog, 'r') + cw = open(tmpfile, 'w', encoding='utf-8') + cr = open(changelog, 'r', encoding='utf-8') print("%(Source)s (%(MangledVersion)s) " "%(Distribution)s; urgency=%(urgency)s\n" % cp, file=cw) diff --git a/tests/11_test_dch_main.py b/tests/11_test_dch_main.py index 7e2a197..8e6ad08 100644 --- a/tests/11_test_dch_main.py +++ b/tests/11_test_dch_main.py @@ -82,7 +82,7 @@ class TestScriptDch(DebianGitTestRepo): options.extend(dch_options) ret = dch.main(options) self.assertEqual(ret, 0) - return open("debian/changelog").readlines() + return open("debian/changelog", encoding='utf-8').readlines() def test_dch_main_new_upstream_version(self): diff --git a/tests/test_Changelog.py b/tests/test_Changelog.py index e66b42f..dd18bcd 100644 --- a/tests/test_Changelog.py +++ b/tests/test_Changelog.py @@ -236,7 +236,7 @@ def test_add_section(): >>> testdebdir = os.path.join(testdir, 'debian') >>> testclname = os.path.join(testdebdir, "changelog") >>> os.mkdir(testdebdir) - >>> clh = open(os.path.join(testdebdir, "changelog"), "w") + >>> clh = open(os.path.join(testdebdir, "changelog"), "w", encoding='utf-8') >>> ret = clh.write(cl_debian) >>> clh.close() >>> os.chdir(testdir) @@ -282,7 +282,7 @@ def test_add_entry(): >>> testdebdir = os.path.join(testdir, 'debian') >>> testclname = os.path.join(testdebdir, "changelog") >>> os.mkdir(testdebdir) - >>> clh = open(os.path.join(testdebdir, "changelog"), "w") + >>> clh = open(os.path.join(testdebdir, "changelog"), "w", encoding='utf-8') >>> ret = clh.write(cl_debian) >>> clh.close() >>> os.chdir(testdir) diff --git a/tests/testutils/__init__.py b/tests/testutils/__init__.py index 60765af..0ba0912 100644 --- a/tests/testutils/__init__.py +++ b/tests/testutils/__init__.py @@ -80,7 +80,7 @@ def get_dch_default_urgency(): pass else: if ret == 0: - with open(tmp_dch_name) as dchfile: + with open(tmp_dch_name, encoding='utf-8') as dchfile: header = dchfile.readline().strip() urgency = header.split()[-1].replace('urgency=', '') finally: -- cgit v1.2.3