← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad-buildd:py3-pottery into launchpad-buildd:master

 

Colin Watson has proposed merging ~cjwatson/launchpad-buildd:py3-pottery into launchpad-buildd:master.

Commit message:
Treat intltool-related files as binary files

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad-buildd/+git/launchpad-buildd/+merge/383349

These are parsed as text, but could contain arbitrary binary data, so decode them defensively.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad-buildd:py3-pottery into launchpad-buildd:master.
diff --git a/debian/changelog b/debian/changelog
index ee93dfa..3451cc6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -9,6 +9,7 @@ launchpad-buildd (190) UNRELEASED; urgency=medium
   * Ensure that regex patterns with \-escapes are raw strings.
   * Adjust X-LXD-mode header construction for Python 3.
   * Treat build logs as binary files.
+  * Treat intltool-related files as binary files.
 
  -- Colin Watson <cjwatson@xxxxxxxxxx>  Tue, 28 Apr 2020 10:19:27 +0100
 
diff --git a/lpbuildd/pottery/intltool.py b/lpbuildd/pottery/intltool.py
index 50030e0..1755cab 100644
--- a/lpbuildd/pottery/intltool.py
+++ b/lpbuildd/pottery/intltool.py
@@ -225,10 +225,13 @@ class ConfigFile:
 
     def __init__(self, file_or_name):
         if isinstance(file_or_name, str):
-            with open(file_or_name) as conf_file:
-                self.content = conf_file.read()
+            with open(file_or_name, "rb") as conf_file:
+                content = conf_file.read()
         else:
-            self.content = file_or_name.read()
+            content = file_or_name.read()
+        if isinstance(content, bytes):
+            content = content.decode("UTF-8", "replace")
+        self.content = content
 
     def _stripQuotes(self, identifier):
         """Strip surrounding quotes from `identifier`, if present.
diff --git a/lpbuildd/pottery/tests/test_intltool.py b/lpbuildd/pottery/tests/test_intltool.py
index 3585d9a..dd1d47d 100644
--- a/lpbuildd/pottery/tests/test_intltool.py
+++ b/lpbuildd/pottery/tests/test_intltool.py
@@ -5,11 +5,11 @@ __metaclass__ = type
 
 import errno
 import os
-from StringIO import StringIO
 import tarfile
 from textwrap import dedent
 
 from fixtures import TempDir
+from six import StringIO
 from testtools import TestCase
 from testtools.matchers import (
     Equals,
diff --git a/lpbuildd/target/tests/test_generate_translation_templates.py b/lpbuildd/target/tests/test_generate_translation_templates.py
index da7f196..16f6848 100644
--- a/lpbuildd/target/tests/test_generate_translation_templates.py
+++ b/lpbuildd/target/tests/test_generate_translation_templates.py
@@ -111,7 +111,7 @@ class TestGenerateTranslationTemplates(TestCase):
         self.useFixture(EnvironmentVariable('BZR_EMAIL'))
         self.useFixture(EnvironmentVariable('EMAIL'))
 
-        marker_text = "Ceci n'est pas cet branch."
+        marker_text = b"Ceci n'est pas cet branch."
         branch_url = self._createBranch({'marker.txt': marker_text})
 
         args = [
@@ -123,7 +123,7 @@ class TestGenerateTranslationTemplates(TestCase):
         generator._getBranch()
 
         marker_path = os.path.join(generator.branch_dir, 'marker.txt')
-        with open(marker_path) as marker_file:
+        with open(marker_path, "rb") as marker_file:
             self.assertEqual(marker_text, marker_file.read())
 
     def test_templates_tarball(self):
@@ -163,9 +163,9 @@ class TestGenerateTranslationTemplates(TestCase):
             branch_url, self.result_name,
             ]
         generator = parse_args(args=args).operation
-        generator.backend.add_file(os.path.join(po_dir, "POTFILES.in"), "")
+        generator.backend.add_file(os.path.join(po_dir, "POTFILES.in"), b"")
         generator.backend.add_file(
-            os.path.join(po_dir, "Makevars"), "DOMAIN = test\n")
+            os.path.join(po_dir, "Makevars"), b"DOMAIN = test\n")
         generator.run()
         self.assertThat(generator.backend.run.calls, MatchesListwise([
             MatchesCall(["apt-get", "-y", "install", "bzr", "intltool"]),