← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-addOrUpdateEntry-bytes into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-addOrUpdateEntry-bytes into launchpad:master.

Commit message:
Pass bytes to TranslationImportQueue.addOrUpdateEntry

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/397894
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-addOrUpdateEntry-bytes into launchpad:master.
diff --git a/lib/lp/registry/doc/private-team-roles.txt b/lib/lp/registry/doc/private-team-roles.txt
index 6289052..e4862ce 100644
--- a/lib/lp/registry/doc/private-team-roles.txt
+++ b/lib/lp/registry/doc/private-team-roles.txt
@@ -286,7 +286,7 @@ translation import queue entries.
     ...     ITranslationImportQueue)
     >>> import_queue = getUtility(ITranslationImportQueue)
     >>> entry = import_queue.addOrUpdateEntry(
-    ...     u'po/sr.po', 'foo', True, public_team,
+    ...     u'po/sr.po', b'foo', True, public_team,
     ...      productseries=product_series)
     >>> product.owner = public_team
     >>> product.owner = priv_team
diff --git a/lib/lp/translations/utilities/doc/gettext_po_parser_context.txt b/lib/lp/translations/utilities/doc/gettext_po_parser_context.txt
index 22bc930..09e061d 100644
--- a/lib/lp/translations/utilities/doc/gettext_po_parser_context.txt
+++ b/lib/lp/translations/utilities/doc/gettext_po_parser_context.txt
@@ -52,7 +52,7 @@ present on both messages (note that two messages with the same msgid,
 where one contains a plural form and the other doesn't, are treated as
 the same message in gettext, and we have to use msgctxt on one of them).
 
-    >>> potemplate_contents = r'''
+    >>> potemplate_contents = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -80,7 +80,7 @@ the same message in gettext, and we have to use msgctxt on one of them).
     ... msgid_plural "%%d files"
     ... msgstr[0] ""
     ... msgstr[1] ""
-    ... ''' % datetime.datetime.now(UTC).isoformat()
+    ... ''' % datetime.datetime.now(UTC).isoformat()).encode('UTF-8')
 
 This file can now be correctly imported:
 
@@ -133,7 +133,7 @@ It also works for plural form messages.
 Importing a PO template with two messages with identical strings, but no
 context differences fails.
 
-    >>> potemplate_contents = r'''
+    >>> potemplate_contents = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -148,7 +148,7 @@ context differences fails.
     ... msgctxt "context"
     ... msgid "bar"
     ... msgstr ""
-    ... ''' % datetime.datetime.now(UTC).isoformat()
+    ... ''' % datetime.datetime.now(UTC).isoformat()).encode('UTF-8')
 
 Importing this file fails because of conflicting messages.
 
@@ -165,7 +165,7 @@ We can also import POFile with context messages.
 
     >>> pofile = potemplate.newPOFile('sr')
     >>> pofile.path='sr.po'
-    >>> pofile_contents = r'''
+    >>> pofile_contents = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -193,7 +193,7 @@ We can also import POFile with context messages.
     ... msgstr[0] "%%d translation"
     ... msgstr[1] "%%d translationes"
     ... msgstr[2] "%%d translations"
-    ... ''' % datetime.datetime.now(UTC).isoformat()
+    ... ''' % datetime.datetime.now(UTC).isoformat()).encode('UTF-8')
 
 Importing this file succeeds.
 
@@ -338,7 +338,7 @@ It's different from the imported file only in a few headers.
 Messages without msgctxt keyword and with empty value for msgctxt are
 not same.
 
-    >>> potemplate_contents = r'''
+    >>> potemplate_contents = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -352,7 +352,7 @@ not same.
     ... msgctxt ""
     ... msgid "bar"
     ... msgstr ""
-    ... ''' % datetime.datetime.now(UTC).isoformat()
+    ... ''' % datetime.datetime.now(UTC).isoformat()).encode('UTF-8')
 
 This file can now be correctly imported:
 
diff --git a/lib/lp/translations/utilities/doc/kde-po-file-format.txt b/lib/lp/translations/utilities/doc/kde-po-file-format.txt
index c80ecec..d7311b7 100644
--- a/lib/lp/translations/utilities/doc/kde-po-file-format.txt
+++ b/lib/lp/translations/utilities/doc/kde-po-file-format.txt
@@ -48,7 +48,7 @@ Our KDE PO support is built on top of existing gettext support.  As
 such, it has precedence in handling any PO files, but it correctly
 sets the format to regular PO if it's not a KDE style file.
 
-    >>> non_kde_template = r'''
+    >>> non_kde_template = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -58,7 +58,7 @@ sets the format to regular PO if it's not a KDE style file.
     ...
     ... msgid "foo"
     ... msgstr ""
-    ... ''' % ISO_FORMATTED_DATE
+    ... ''' % ISO_FORMATTED_DATE).encode('UTF-8')
 
 Importing this file works, but the format is set to Gettext PO.
 
@@ -78,7 +78,7 @@ Plural forms are supported by using a specially formatted msgid where
 English singular and plural are split with a newline, and the entire
 message is preceded with '_n: ' (space at the end of the string is important).
 
-    >>> plural_forms_template = r'''
+    >>> plural_forms_template = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -111,7 +111,7 @@ message is preceded with '_n: ' (space at the end of the string is important).
     ...
     ... msgid "_n: entry\nentries"
     ... msgstr ""
-    ... ''' % ISO_FORMATTED_DATE
+    ... ''' % ISO_FORMATTED_DATE).encode('UTF-8')
 
 And strangely, importing this file actually works, and format is changed
 to KDE PO format.
@@ -160,7 +160,7 @@ forms. They are simply newline-separated strings.
 
     >>> firefox_serbian_pofile = firefox_potemplate.newPOFile('sr')
     >>> firefox_serbian_pofile.path='sr.po'
-    >>> firefox_serbian_pofile_contents = r'''
+    >>> firefox_serbian_pofile_contents = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -192,7 +192,7 @@ forms. They are simply newline-separated strings.
     ... msgid "_n: entry\nentries"
     ... msgstr "singular entry\n\nplural entries"
     ...
-    ... ''' % ISO_FORMATTED_DATE
+    ... ''' % ISO_FORMATTED_DATE).encode('UTF-8')
 
 Importing this file succeeds, even if the number of %d printf specifications
 doesn't match: this is because this is now specially handled with KDE PO
@@ -406,7 +406,7 @@ a new line from the rest of the message.
 
 We can have a template with a message with context.
 
-    >>> kde_context_template = r'''
+    >>> kde_context_template = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -418,7 +418,7 @@ We can have a template with a message with context.
     ...
     ... msgid "_: Different Context\nMessage"
     ... msgstr ""
-    ... ''' % ISO_FORMATTED_DATE
+    ... ''' % ISO_FORMATTED_DATE).encode('UTF-8')
 
 Importing this template works and the format is recognized as a KDE PO format.
 
@@ -448,7 +448,7 @@ If we ask for a message without specifying context, we get no results:
 
 We can also import a translated file with message contexts:
 
-    >>> kde_context_translation = r'''
+    >>> kde_context_translation = (r'''
     ... msgid ""
     ... msgstr ""
     ... "POT-Creation-Date: 2004-07-11 16:16+0900\n"
@@ -460,7 +460,7 @@ We can also import a translated file with message contexts:
     ...
     ... msgid "_: Different Context\nMessage"
     ... msgstr "Second translation"
-    ... ''' % ISO_FORMATTED_DATE
+    ... ''' % ISO_FORMATTED_DATE).encode('UTF-8')
     >>> entry = import_pofile_or_potemplate(kde_context_translation, carlos,
     ...                                     pofile=firefox_serbian_pofile)
     >>> print entry.status.name
diff --git a/lib/lp/translations/utilities/tests/helpers.py b/lib/lp/translations/utilities/tests/helpers.py
index 9a40746..e7829d2 100644
--- a/lib/lp/translations/utilities/tests/helpers.py
+++ b/lib/lp/translations/utilities/tests/helpers.py
@@ -25,8 +25,8 @@ def import_pofile_or_potemplate(file_contents, person,
     pofile=None, potemplate=None, by_maintainer=True):
     """Import a `POFile` or `POTemplate` from the given string.
 
-    :param file_contents: text of "file" to import, or a seekable file
-        object containing the text.
+    :param file_contents: contents of "file" to import as a byte string, or
+        a seekable file object open in binary mode.
     :param person: party requesting the import.
     :param pofile: if uploading a `POFile`, file to import to; None otherwise.
     :param potemplate: if uploading a `POTemplate`, file to import to; None
diff --git a/lib/lp/translations/utilities/tests/test_file_importer.py b/lib/lp/translations/utilities/tests/test_file_importer.py
index 18aa370..300a653 100644
--- a/lib/lp/translations/utilities/tests/test_file_importer.py
+++ b/lib/lp/translations/utilities/tests/test_file_importer.py
@@ -131,7 +131,7 @@ class FileImporterTestCase(TestCaseWithFactory):
         Create an importer from the entry."""
         potemplate = self.factory.makePOTemplate()
         template_entry = self.translation_import_queue.addOrUpdateEntry(
-            potemplate.path, pot_content,
+            potemplate.path, six.ensure_binary(pot_content),
             by_maintainer, self.importer_person,
             productseries=potemplate.productseries,
             potemplate=potemplate)
@@ -151,7 +151,7 @@ class FileImporterTestCase(TestCaseWithFactory):
             pofile = existing_pofile
         person = person or self.importer_person
         translation_entry = self.translation_import_queue.addOrUpdateEntry(
-            pofile.path, po_content, by_maintainer, person,
+            pofile.path, six.ensure_binary(po_content), by_maintainer, person,
             productseries=potemplate.productseries, pofile=pofile)
         self.fake_librarian.pretendCommit()
         return POFileImporter(translation_entry, GettextPOImporter(), None)
@@ -174,7 +174,7 @@ class FileImporterTestCase(TestCaseWithFactory):
         These tests don't care about Imported or Upstream."""
         potemplate = self.factory.makePOTemplate()
         template_entry = self.translation_import_queue.addOrUpdateEntry(
-            potemplate.path, TEST_TEMPLATE_EXPORTED,
+            potemplate.path, six.ensure_binary(TEST_TEMPLATE_EXPORTED),
             False, self.importer_person,
             productseries=potemplate.productseries,
             potemplate=potemplate)
@@ -538,7 +538,8 @@ class CreateFileImporterTestCase(TestCaseWithFactory):
                          "Content-Type: text/plain; charset=UTF-8\n")
         po_content = TEST_TRANSLATION_FILE % ("", "foo", "bar")
         queue_entry = self.translation_import_queue.addOrUpdateEntry(
-            pofile.path, po_content, by_maintainer, self.importer_person,
+            pofile.path, six.ensure_binary(po_content), by_maintainer,
+            self.importer_person,
             productseries=pofile.potemplate.productseries, pofile=pofile)
         self.fake_librarian.pretendCommit()
         return queue_entry