launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #30004
[Merge] ~cjwatson/launchpad:unsixify-translations into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:unsixify-translations into launchpad:master.
Commit message:
Remove six from lp.translations
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/442910
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:unsixify-translations into launchpad:master.
diff --git a/lib/lp/translations/browser/pofile.py b/lib/lp/translations/browser/pofile.py
index fa958c2..b095a66 100644
--- a/lib/lp/translations/browser/pofile.py
+++ b/lib/lp/translations/browser/pofile.py
@@ -17,7 +17,6 @@ import os.path
import re
from urllib.parse import urlencode
-import six
from lazr.restful.utils import smartquote
from zope.component import getUtility
from zope.publisher.browser import FileUpload
@@ -596,7 +595,7 @@ class POFileTranslateView(BaseTranslationView, POFileMetadataViewMixin):
self.user is not None
and translations_person.translations_relicensing_agreement is None
):
- url = six.ensure_text(str(self.request.URL), "US-ASCII", "replace")
+ url = str(self.request.URL)
if self.request.get("QUERY_STRING", None):
url = url + "?" + self.request["QUERY_STRING"]
diff --git a/lib/lp/translations/doc/poexport-language-pack.rst b/lib/lp/translations/doc/poexport-language-pack.rst
index 751ace6..d4067a3 100644
--- a/lib/lp/translations/doc/poexport-language-pack.rst
+++ b/lib/lp/translations/doc/poexport-language-pack.rst
@@ -98,7 +98,7 @@ And one of the included .po files look like what we expected.
>>> fh = tarfile.extractfile(
... "rosetta-hoary/es/LC_MESSAGES/evolution-2.2.po"
... )
- >>> print(six.ensure_text(fh.readline()))
+ >>> print(fh.readline().decode())
# traducción de es.po al Spanish
diff --git a/lib/lp/translations/doc/potemplate.rst b/lib/lp/translations/doc/potemplate.rst
index 92146d6..f302f86 100644
--- a/lib/lp/translations/doc/potemplate.rst
+++ b/lib/lp/translations/doc/potemplate.rst
@@ -607,7 +607,7 @@ The *-es.po file is indeed the Spanish translation...
>>> file_content = tarfile.extractfile(
... "evolution-2.2/evolution-2.2-es.po"
... )
- >>> print(six.ensure_text(file_content.readline()))
+ >>> print(file_content.readline().decode())
# traducción de es.po al Spanish
And GNU tar can cope with it.
@@ -615,7 +615,7 @@ And GNU tar can cope with it.
>>> from lp.services.helpers import simple_popen2
>>> contents = simple_popen2(["tar", "ztf", "-"], tarfile_bytes)
>>> for line in sorted(contents.splitlines()):
- ... print(six.ensure_text(line))
+ ... print(line.decode())
...
evolution-2.2/
evolution-2.2/evolution-2.2-es.po
@@ -629,5 +629,5 @@ And GNU tar can cope with it.
... ["tar", "zxfO", "-", "evolution-2.2/evolution-2.2-es.po"],
... tarfile_bytes,
... )
- >>> print(six.ensure_text(pofile).split("\n")[0])
+ >>> print(pofile.decode().split("\n")[0])
# traducción de es.po al Spanish
diff --git a/lib/lp/translations/doc/potranslation.rst b/lib/lp/translations/doc/potranslation.rst
index 7c1286b..8b44fc3 100644
--- a/lib/lp/translations/doc/potranslation.rst
+++ b/lib/lp/translations/doc/potranslation.rst
@@ -30,14 +30,3 @@ doesn't already exist, use POTranslation.getOrCreateTranslation.
>>> got = POTranslation.getOrCreateTranslation("In Xanadu did Kubla Khan")
>>> print(got.translation)
In Xanadu did Kubla Khan
-
-If you want to pass non-ascii characters to either of these, it had better be
-either UTF-8 string or, better, a unicode object.
-
- >>> got = POTranslation.getOrCreateTranslation(b"\xc3\x81")
- >>> got = POTranslation.getOrCreateTranslation("\u00c2")
-
- >>> got = POTranslation.getOrCreateTranslation(b"\xc0")
- Traceback (most recent call last):
- ...
- UnicodeDecodeError: 'utf...8' codec can't decode byte 0xc0 in position...
diff --git a/lib/lp/translations/doc/translationimportqueue.rst b/lib/lp/translations/doc/translationimportqueue.rst
index 3801c11..edf81ad 100644
--- a/lib/lp/translations/doc/translationimportqueue.rst
+++ b/lib/lp/translations/doc/translationimportqueue.rst
@@ -1429,11 +1429,9 @@ bug 138650 for an example).
If such bad requests do end up on the import queue, the import queue code will
raise errors about them.
- >>> import six
-
>>> def print_import_failures(import_script):
... """List failures recorded in an import script instance."""
- ... for reason, entries in six.iteritems(script.failures):
+ ... for reason, entries in script.failures.items():
... print(reason)
... for entry in entries:
... print("-> " + entry)
diff --git a/lib/lp/translations/doc/translations-export-to-branch.rst b/lib/lp/translations/doc/translations-export-to-branch.rst
index 4e3507e..f01c7bb 100644
--- a/lib/lp/translations/doc/translations-export-to-branch.rst
+++ b/lib/lp/translations/doc/translations-export-to-branch.rst
@@ -40,7 +40,7 @@ files into the branches. We mock it up here.
...
... def writeFile(self, path, contents):
... self.logger.info("Writing file '%s':" % path)
- ... self.logger.info(six.ensure_text(contents))
+ ... self.logger.info(contents.decode())
... self.written_files += 1
...
... def lockForCommit(self):
diff --git a/lib/lp/translations/model/pomsgid.py b/lib/lp/translations/model/pomsgid.py
index e00bb54..dd8df23 100644
--- a/lib/lp/translations/model/pomsgid.py
+++ b/lib/lp/translations/model/pomsgid.py
@@ -3,7 +3,6 @@
__all__ = ["POMsgID"]
-import six
from storm.expr import Func
from storm.locals import Int, Unicode
from zope.interface import implementer
@@ -46,8 +45,7 @@ class POMsgID(StormBase):
IStore(POMsgID)
.find(
POMsgID,
- Func("sha1", POMsgID.msgid)
- == Func("sha1", six.ensure_text(key)),
+ Func("sha1", POMsgID.msgid) == Func("sha1", key),
)
.one()
)
diff --git a/lib/lp/translations/model/potranslation.py b/lib/lp/translations/model/potranslation.py
index c367956..5d0626e 100644
--- a/lib/lp/translations/model/potranslation.py
+++ b/lib/lp/translations/model/potranslation.py
@@ -3,7 +3,6 @@
__all__ = ["POTranslation"]
-import six
from storm.expr import Func
from storm.locals import Int, Unicode
from zope.interface import implementer
@@ -44,8 +43,7 @@ class POTranslation(StormBase):
IStore(POTranslation)
.find(
POTranslation,
- Func("sha1", POTranslation.translation)
- == Func("sha1", six.ensure_text(key)),
+ Func("sha1", POTranslation.translation) == Func("sha1", key),
)
.one()
)
@@ -60,11 +58,6 @@ class POTranslation(StormBase):
"""Return a POTranslation object for the given translation, or create
it if it doesn't exist.
"""
- # If this is not a unicode object, it had better be ASCII or UTF-8.
- # XXX: JeroenVermeulen 2008-06-06 bug=237868: non-ascii str strings
- # should be contained in the parser or the browser code.
- key = six.ensure_text(key)
-
try:
return cls.getByTranslation(key)
except NotFoundError:
diff --git a/lib/lp/translations/tests/test_translationimportqueue.py b/lib/lp/translations/tests/test_translationimportqueue.py
index c20bf61..8a51550 100644
--- a/lib/lp/translations/tests/test_translationimportqueue.py
+++ b/lib/lp/translations/tests/test_translationimportqueue.py
@@ -4,7 +4,6 @@
import os.path
from operator import attrgetter
-import six
import transaction
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
@@ -330,7 +329,7 @@ class TestGetGuessedPOFile(TestCaseWithFactory):
)
queue_entry = self.queue.addOrUpdateEntry(
"%s.po" % template_path,
- six.ensure_binary(template_name),
+ template_name.encode(),
True,
self.uploaderperson,
distroseries=package.distroseries,
diff --git a/lib/lp/translations/utilities/doc/gettext_po_parser.rst b/lib/lp/translations/utilities/doc/gettext_po_parser.rst
index ae8013e..76710a3 100644
--- a/lib/lp/translations/utilities/doc/gettext_po_parser.rst
+++ b/lib/lp/translations/utilities/doc/gettext_po_parser.rst
@@ -452,7 +452,7 @@ The special symbols and numeric representations of the chars '8', '80' and 'p'
are decoded correctly.
>>> for translation in translation_file.messages[0].translations:
- ... print(repr(six.ensure_str(translation)))
+ ... print(repr(translation))
...
'\x07\x08\x0b\x0c\t\x0b\\"\'\n8 8 80 p\n'
diff --git a/lib/lp/translations/utilities/gettext_po_parser.py b/lib/lp/translations/utilities/gettext_po_parser.py
index 43b5354..a383360 100644
--- a/lib/lp/translations/utilities/gettext_po_parser.py
+++ b/lib/lp/translations/utilities/gettext_po_parser.py
@@ -17,7 +17,6 @@ import re
from datetime import datetime, timezone
from email.utils import parseaddr
-import six
from zope import datetime as zope_datetime
from zope.interface import implementer
@@ -61,11 +60,14 @@ class POSyntaxWarning(Warning):
logging.info(self.message)
def __str__(self):
- return six.ensure_text(self.message)
+ return self.message
def parse_charset(string_to_parse, is_escaped=True):
"""Return charset used in the given string_to_parse."""
+ if isinstance(string_to_parse, bytes):
+ string_to_parse = string_to_parse.decode("UTF-8", "replace")
+
# Scan for the charset in the same way that gettext does.
default_charset = "UTF-8"
pattern = r"charset=([^\s]+)"
@@ -75,9 +77,7 @@ def parse_charset(string_to_parse, is_escaped=True):
# Default to UTF-8 if the header still has the default value or
# is unknown.
charset = default_charset
- match = re.search(
- pattern, six.ensure_text(string_to_parse, "UTF-8", "replace")
- )
+ match = re.search(pattern, string_to_parse)
if match is not None and match.group(1) != b"CHARSET":
charset = match.group(1).strip()
try:
diff --git a/lib/lp/translations/utilities/tests/test_file_importer.py b/lib/lp/translations/utilities/tests/test_file_importer.py
index b33596e..b37590d 100644
--- a/lib/lp/translations/utilities/tests/test_file_importer.py
+++ b/lib/lp/translations/utilities/tests/test_file_importer.py
@@ -5,7 +5,6 @@
from textwrap import dedent
-import six
import transaction
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
@@ -143,7 +142,7 @@ class FileImporterTestCase(TestCaseWithFactory):
potemplate = self.factory.makePOTemplate()
template_entry = self.translation_import_queue.addOrUpdateEntry(
potemplate.path,
- six.ensure_binary(pot_content),
+ pot_content.encode(),
by_maintainer,
self.importer_person,
productseries=potemplate.productseries,
@@ -172,7 +171,7 @@ class FileImporterTestCase(TestCaseWithFactory):
person = person or self.importer_person
translation_entry = self.translation_import_queue.addOrUpdateEntry(
pofile.path,
- six.ensure_binary(po_content),
+ po_content.encode(),
by_maintainer,
person,
productseries=potemplate.productseries,
@@ -202,7 +201,7 @@ class FileImporterTestCase(TestCaseWithFactory):
potemplate = self.factory.makePOTemplate()
template_entry = self.translation_import_queue.addOrUpdateEntry(
potemplate.path,
- six.ensure_binary(TEST_TEMPLATE_EXPORTED),
+ TEST_TEMPLATE_EXPORTED.encode(),
False,
self.importer_person,
productseries=potemplate.productseries,
@@ -467,7 +466,7 @@ class FileImporterTestCase(TestCaseWithFactory):
"should be none.",
)
potmsgset = po_importer.pofile.potemplate.getPOTMsgSetByMsgIDText(
- six.ensure_text(TEST_MSGID)
+ TEST_MSGID
)
message = potmsgset.getCurrentTranslation(
po_importer.potemplate,
@@ -561,7 +560,7 @@ class FileImporterTestCase(TestCaseWithFactory):
# Although the message has an error, it should still be stored
# in the database, though only as a suggestion.
potmsgset = po_importer.pofile.potemplate.getPOTMsgSetByMsgIDText(
- six.ensure_text(TEST_MSGID_ERROR)
+ TEST_MSGID_ERROR
)
message = potmsgset.getLocalTranslationMessages(
po_importer.potemplate, po_importer.pofile.language
@@ -593,7 +592,7 @@ class FileImporterTestCase(TestCaseWithFactory):
po_importer2.importFile()
potmsgset = po_importer.pofile.potemplate.getPOTMsgSetByMsgIDText(
- six.ensure_text(TEST_MSGID_ERROR)
+ TEST_MSGID_ERROR
)
messages = potmsgset.getLocalTranslationMessages(
po_importer.pofile.potemplate, po_importer.pofile.language
@@ -665,7 +664,7 @@ class CreateFileImporterTestCase(TestCaseWithFactory):
po_content = TEST_TRANSLATION_FILE % ("", "foo", "bar")
queue_entry = self.translation_import_queue.addOrUpdateEntry(
pofile.path,
- six.ensure_binary(po_content),
+ po_content.encode(),
by_maintainer,
self.importer_person,
productseries=pofile.potemplate.productseries,
diff --git a/lib/lp/translations/utilities/translation_import.py b/lib/lp/translations/utilities/translation_import.py
index 1535590..901bbc1 100644
--- a/lib/lp/translations/utilities/translation_import.py
+++ b/lib/lp/translations/utilities/translation_import.py
@@ -11,7 +11,6 @@ import posixpath
from datetime import datetime, timezone
from operator import attrgetter
-import six
import transaction
from storm.exceptions import TimeoutError
from zope.component import getUtility
@@ -636,7 +635,7 @@ class FileImporter:
"pomessage": self.format_exporter.exportTranslationMessageData(
message
),
- "error-message": six.ensure_text(errormsg),
+ "error-message": errormsg,
}
)
diff --git a/lib/lp/translations/utilities/translationmerger.py b/lib/lp/translations/utilities/translationmerger.py
index 297f54a..2925e1e 100644
--- a/lib/lp/translations/utilities/translationmerger.py
+++ b/lib/lp/translations/utilities/translationmerger.py
@@ -10,7 +10,6 @@ __all__ = [
from operator import methodcaller
-import six
from storm.locals import ClassAlias, Store
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
@@ -316,8 +315,6 @@ class MessageSharingMerge(LaunchpadScript):
sourcepackagename=sourcepackagename,
)
template_regex = self.options.template_names
- if template_regex is not None:
- template_regex = six.ensure_text(template_regex)
equivalence_classes = subset.groupEquivalentPOTemplates(template_regex)
class_count = len(equivalence_classes)
diff --git a/lib/lp/translations/utilities/xpi_header.py b/lib/lp/translations/utilities/xpi_header.py
index b1aa348..cfabddc 100644
--- a/lib/lp/translations/utilities/xpi_header.py
+++ b/lib/lp/translations/utilities/xpi_header.py
@@ -9,7 +9,6 @@ import io
from email.utils import parseaddr
import defusedxml.cElementTree as cElementTree
-import six
from zope.interface import implementer
from lp.translations.interfaces.translationcommonformat import (
@@ -65,9 +64,11 @@ class XpiHeader:
# Both cElementTree and elementtree fail when trying to parse
# proper unicode strings. Use our raw input instead.
try:
+ raw_content = self._raw_content
+ if not isinstance(raw_content, bytes):
+ raw_content = raw_content.encode()
parse = cElementTree.iterparse(
- io.BytesIO(six.ensure_binary(self._raw_content)),
- forbid_dtd=True,
+ io.BytesIO(raw_content), forbid_dtd=True
)
for event, elem in parse:
if elem.tag == contributor_tag: