← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~cjwatson/launchpad:py3-translations-raw-strings into launchpad:master

 

Colin Watson has proposed merging ~cjwatson/launchpad:py3-translations-raw-strings into launchpad:master.

Commit message:
Correct spelling of \-escapes in lp.translations

Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

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

Use raw strings or double-\, depending on whether it's more convenient for '\n' to mean a newline character or the two characters '\' 'n'.  This fixes a number of DeprecationWarnings with Python >= 3.6.
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-translations-raw-strings into launchpad:master.
diff --git a/lib/lp/translations/browser/pofile.py b/lib/lp/translations/browser/pofile.py
index e14555c..e7c80a2 100644
--- a/lib/lp/translations/browser/pofile.py
+++ b/lib/lp/translations/browser/pofile.py
@@ -627,7 +627,7 @@ class POFileTranslateView(BaseTranslationView, POFileMetadataViewMixin):
     def _submitTranslations(self):
         """See BaseTranslationView._submitTranslations."""
         for key in self.request.form:
-            match = re.match('msgset_(\d+)$', key)
+            match = re.match(r'msgset_(\d+)$', key)
             if not match:
                 continue
 
diff --git a/lib/lp/translations/browser/translationmessage.py b/lib/lp/translations/browser/translationmessage.py
index 60bcff2..aa57491 100644
--- a/lib/lp/translations/browser/translationmessage.py
+++ b/lib/lp/translations/browser/translationmessage.py
@@ -231,7 +231,7 @@ def _getSuggestionFromFormId(form_id):
     The ID is in the format generated by `POSubmission.makeHTMLID`.
     """
     expr_match = re.search(
-        'msgset_(\d+)_(\S+)_suggestion_(\d+)_(\d+)', form_id)
+        r'msgset_(\d+)_(\S+)_suggestion_(\d+)_(\d+)', form_id)
     if expr_match is None:
         raise UnexpectedFormData(
             'The given form ID (%s) is not valid' % form_id)
diff --git a/lib/lp/translations/model/translationimportqueue.py b/lib/lp/translations/model/translationimportqueue.py
index 8856aee..21e6112 100644
--- a/lib/lp/translations/model/translationimportqueue.py
+++ b/lib/lp/translations/model/translationimportqueue.py
@@ -737,7 +737,7 @@ class TranslationImportQueueEntry(StormBase):
             # This package has the language information included as part of a
             # directory: koffice-i18n-LANG_CODE-VERSION
             # Extract the language information.
-            match = re.match('koffice-i18n-(\S+)-(\S+)', self.path)
+            match = re.match(r'koffice-i18n-(\S+)-(\S+)', self.path)
             if match is None:
                 # No idea what to do with this.
                 return None
diff --git a/lib/lp/translations/scripts/tests/test_packaging_translations.py b/lib/lp/translations/scripts/tests/test_packaging_translations.py
index 4f95a21..77673b8 100644
--- a/lib/lp/translations/scripts/tests/test_packaging_translations.py
+++ b/lib/lp/translations/scripts/tests/test_packaging_translations.py
@@ -33,7 +33,7 @@ class TestMergeTranslations(TestCaseWithFactory):
         matcher = MatchesRegex(dedent("""\
             INFO    Creating lockfile: /var/lock/launchpad-process-job-source-ITranslationPackagingJobSource.lock
             INFO    Running synchronously.
-            INFO    Running <.*?TranslationMergeJob.*?> \(ID .*\) in status Waiting
+            INFO    Running <.*?TranslationMergeJob.*?> \\(ID .*\\) in status Waiting
             INFO    Merging .* and .* in Ubuntu Distroseries.*
             INFO    Deleted POTMsgSets: 1.  TranslationMessages: 1.
             INFO    Merging template 1/2.
@@ -53,7 +53,7 @@ class TestMergeTranslations(TestCaseWithFactory):
         matcher = MatchesRegex(dedent("""\
             INFO    Creating lockfile: /var/lock/launchpad-process-job-source-ITranslationPackagingJobSource.lock
             INFO    Running synchronously.
-            INFO    Running <.*?TranslationSplitJob.*?> \(ID .*\) in status Waiting
+            INFO    Running <.*?TranslationSplitJob.*?> \\(ID .*\\) in status Waiting
             INFO    Splitting .* and .* in Ubuntu Distroseries.*
             INFO    1 entries split.
             INFO    Ran 1 TranslationSplitJob jobs.
diff --git a/lib/lp/translations/scripts/tests/test_reupload_translations.py b/lib/lp/translations/scripts/tests/test_reupload_translations.py
index 2ec0cee..ea3898a 100644
--- a/lib/lp/translations/scripts/tests/test_reupload_translations.py
+++ b/lib/lp/translations/scripts/tests/test_reupload_translations.py
@@ -199,12 +199,12 @@ class TestReuploadScript(TestCaseWithFactory):
         self.assertEqual('', stdout)
 
         expected_output = (
-            "INFO\s*Dry run.  Not really uploading anything.\n"
-            "INFO\s*Processing [^\s]+ in .*\n"
-            "WARNING\s*Found no translations upload for .*\n"
-            "INFO\s*Processing [^\s]+ in .*\n"
-            "WARNING\s*Found no translations upload for .*\n"
-            "INFO\s*Done.\n")
+            r"INFO\s*Dry run.  Not really uploading anything.\n"
+            r"INFO\s*Processing [^\s]+ in .*\n"
+            r"WARNING\s*Found no translations upload for .*\n"
+            r"INFO\s*Processing [^\s]+ in .*\n"
+            r"WARNING\s*Found no translations upload for .*\n"
+            r"INFO\s*Done.\n")
         self.assertTrue(
             re.match(expected_output, stderr),
             'expected %s, got %s' % (expected_output, stderr))
diff --git a/lib/lp/translations/scripts/tests/test_translations_import.py b/lib/lp/translations/scripts/tests/test_translations_import.py
index 2fe67ae..75f1239 100644
--- a/lib/lp/translations/scripts/tests/test_translations_import.py
+++ b/lib/lp/translations/scripts/tests/test_translations_import.py
@@ -72,7 +72,7 @@ class TestTranslationsImport(TestCaseWithFactory):
         productseries = self._makeProductSeries()
         entry = self._makeEntry('foo.po', productseries=productseries)
         description = self.script._describeEntry(entry)
-        pattern = "'foo.po' \(id [0-9]+\) in [A-Za-z0-9_-]+ trunk series$"
+        pattern = r"'foo.po' \(id [0-9]+\) in [A-Za-z0-9_-]+ trunk series$"
         self.assertNotEqual(None, re.match(pattern, description))
 
     def test_describeEntry_for_pofile(self):
@@ -83,7 +83,7 @@ class TestTranslationsImport(TestCaseWithFactory):
             'foo.po', productseries=productseries, potemplate=template,
             pofile=pofile)
         description = self.script._describeEntry(entry)
-        pattern = "Dutch \(nl\) translation of .* in .* trunk \(id [0-9]+\)$"
+        pattern = r"Dutch \(nl\) translation of .* in .* trunk \(id [0-9]+\)$"
         self.assertNotEqual(None, re.match(pattern, description))
 
     def test_describeEntry_for_template(self):
@@ -92,7 +92,7 @@ class TestTranslationsImport(TestCaseWithFactory):
         entry = self._makeEntry(
             'foo.pot', productseries=productseries, potemplate=template)
         description = self.script._describeEntry(entry)
-        pattern = 'Template "[^"]+" in [A-Za-z0-9_-]+ trunk \(id [0-9]+\)$'
+        pattern = r'Template "[^"]+" in [A-Za-z0-9_-]+ trunk \(id [0-9]+\)$'
         self.assertNotEqual(None, re.match(pattern, description))
 
     def test_checkEntry(self):
diff --git a/lib/lp/translations/scripts/tests/test_translations_to_branch.py b/lib/lp/translations/scripts/tests/test_translations_to_branch.py
index 0cd058a..9095b74 100644
--- a/lib/lp/translations/scripts/tests/test_translations_to_branch.py
+++ b/lib/lp/translations/scripts/tests/test_translations_to_branch.py
@@ -144,7 +144,7 @@ class TestExportTranslationsToBranch(TestCaseWithFactory):
             "Processed 1 item(s); 0 failure(s), 0 unpushed branch(es).",
             stderr)
         self.assertEqual(
-            None, re.search("INFO\s+Committed [0-9]+ file", stderr))
+            None, re.search(r"INFO\s+Committed [0-9]+ file", stderr))
 
     def test_exportToStaleBranch(self):
         # Attempting to export to a stale branch marks it for scanning.