Merge ~cjwatson/launchpad:unsixify-translations into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 291d7006c71ab9cabb4e7feacb56a37cdbe3ef98
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:unsixify-translations
Merge into: launchpad:master
Diff against target: 384 lines (+28/-56)
15 files modified
lib/lp/translations/browser/pofile.py (+1/-2)
lib/lp/translations/doc/poexport-language-pack.rst (+1/-1)
lib/lp/translations/doc/potemplate.rst (+3/-3)
lib/lp/translations/doc/potranslation.rst (+0/-11)
lib/lp/translations/doc/translationimportqueue.rst (+1/-3)
lib/lp/translations/doc/translations-export-to-branch.rst (+1/-1)
lib/lp/translations/model/pomsgid.py (+1/-3)
lib/lp/translations/model/potranslation.py (+1/-8)
lib/lp/translations/tests/test_translationimportqueue.py (+1/-2)
lib/lp/translations/utilities/doc/gettext_po_parser.rst (+1/-1)
lib/lp/translations/utilities/gettext_po_parser.py (+5/-5)
lib/lp/translations/utilities/tests/test_file_importer.py (+7/-8)
lib/lp/translations/utilities/translation_import.py (+1/-2)
lib/lp/translations/utilities/translationmerger.py (+0/-3)
lib/lp/translations/utilities/xpi_header.py (+4/-3)
Reviewer Review Type Date Requested Status
Jürgen Gmach Approve
Review via email: mp+442910@code.launchpad.net

Commit message

Remove six from lp.translations

To post a comment you must log in.
Revision history for this message
Jürgen Gmach (jugmac00) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/translations/browser/pofile.py b/lib/lp/translations/browser/pofile.py
2index fa958c2..b095a66 100644
3--- a/lib/lp/translations/browser/pofile.py
4+++ b/lib/lp/translations/browser/pofile.py
5@@ -17,7 +17,6 @@ import os.path
6 import re
7 from urllib.parse import urlencode
8
9-import six
10 from lazr.restful.utils import smartquote
11 from zope.component import getUtility
12 from zope.publisher.browser import FileUpload
13@@ -596,7 +595,7 @@ class POFileTranslateView(BaseTranslationView, POFileMetadataViewMixin):
14 self.user is not None
15 and translations_person.translations_relicensing_agreement is None
16 ):
17- url = six.ensure_text(str(self.request.URL), "US-ASCII", "replace")
18+ url = str(self.request.URL)
19 if self.request.get("QUERY_STRING", None):
20 url = url + "?" + self.request["QUERY_STRING"]
21
22diff --git a/lib/lp/translations/doc/poexport-language-pack.rst b/lib/lp/translations/doc/poexport-language-pack.rst
23index 751ace6..d4067a3 100644
24--- a/lib/lp/translations/doc/poexport-language-pack.rst
25+++ b/lib/lp/translations/doc/poexport-language-pack.rst
26@@ -98,7 +98,7 @@ And one of the included .po files look like what we expected.
27 >>> fh = tarfile.extractfile(
28 ... "rosetta-hoary/es/LC_MESSAGES/evolution-2.2.po"
29 ... )
30- >>> print(six.ensure_text(fh.readline()))
31+ >>> print(fh.readline().decode())
32 # traducción de es.po al Spanish
33
34
35diff --git a/lib/lp/translations/doc/potemplate.rst b/lib/lp/translations/doc/potemplate.rst
36index 92146d6..f302f86 100644
37--- a/lib/lp/translations/doc/potemplate.rst
38+++ b/lib/lp/translations/doc/potemplate.rst
39@@ -607,7 +607,7 @@ The *-es.po file is indeed the Spanish translation...
40 >>> file_content = tarfile.extractfile(
41 ... "evolution-2.2/evolution-2.2-es.po"
42 ... )
43- >>> print(six.ensure_text(file_content.readline()))
44+ >>> print(file_content.readline().decode())
45 # traducción de es.po al Spanish
46
47 And GNU tar can cope with it.
48@@ -615,7 +615,7 @@ And GNU tar can cope with it.
49 >>> from lp.services.helpers import simple_popen2
50 >>> contents = simple_popen2(["tar", "ztf", "-"], tarfile_bytes)
51 >>> for line in sorted(contents.splitlines()):
52- ... print(six.ensure_text(line))
53+ ... print(line.decode())
54 ...
55 evolution-2.2/
56 evolution-2.2/evolution-2.2-es.po
57@@ -629,5 +629,5 @@ And GNU tar can cope with it.
58 ... ["tar", "zxfO", "-", "evolution-2.2/evolution-2.2-es.po"],
59 ... tarfile_bytes,
60 ... )
61- >>> print(six.ensure_text(pofile).split("\n")[0])
62+ >>> print(pofile.decode().split("\n")[0])
63 # traducción de es.po al Spanish
64diff --git a/lib/lp/translations/doc/potranslation.rst b/lib/lp/translations/doc/potranslation.rst
65index 7c1286b..8b44fc3 100644
66--- a/lib/lp/translations/doc/potranslation.rst
67+++ b/lib/lp/translations/doc/potranslation.rst
68@@ -30,14 +30,3 @@ doesn't already exist, use POTranslation.getOrCreateTranslation.
69 >>> got = POTranslation.getOrCreateTranslation("In Xanadu did Kubla Khan")
70 >>> print(got.translation)
71 In Xanadu did Kubla Khan
72-
73-If you want to pass non-ascii characters to either of these, it had better be
74-either UTF-8 string or, better, a unicode object.
75-
76- >>> got = POTranslation.getOrCreateTranslation(b"\xc3\x81")
77- >>> got = POTranslation.getOrCreateTranslation("\u00c2")
78-
79- >>> got = POTranslation.getOrCreateTranslation(b"\xc0")
80- Traceback (most recent call last):
81- ...
82- UnicodeDecodeError: 'utf...8' codec can't decode byte 0xc0 in position...
83diff --git a/lib/lp/translations/doc/translationimportqueue.rst b/lib/lp/translations/doc/translationimportqueue.rst
84index 3801c11..edf81ad 100644
85--- a/lib/lp/translations/doc/translationimportqueue.rst
86+++ b/lib/lp/translations/doc/translationimportqueue.rst
87@@ -1429,11 +1429,9 @@ bug 138650 for an example).
88 If such bad requests do end up on the import queue, the import queue code will
89 raise errors about them.
90
91- >>> import six
92-
93 >>> def print_import_failures(import_script):
94 ... """List failures recorded in an import script instance."""
95- ... for reason, entries in six.iteritems(script.failures):
96+ ... for reason, entries in script.failures.items():
97 ... print(reason)
98 ... for entry in entries:
99 ... print("-> " + entry)
100diff --git a/lib/lp/translations/doc/translations-export-to-branch.rst b/lib/lp/translations/doc/translations-export-to-branch.rst
101index 4e3507e..f01c7bb 100644
102--- a/lib/lp/translations/doc/translations-export-to-branch.rst
103+++ b/lib/lp/translations/doc/translations-export-to-branch.rst
104@@ -40,7 +40,7 @@ files into the branches. We mock it up here.
105 ...
106 ... def writeFile(self, path, contents):
107 ... self.logger.info("Writing file '%s':" % path)
108- ... self.logger.info(six.ensure_text(contents))
109+ ... self.logger.info(contents.decode())
110 ... self.written_files += 1
111 ...
112 ... def lockForCommit(self):
113diff --git a/lib/lp/translations/model/pomsgid.py b/lib/lp/translations/model/pomsgid.py
114index e00bb54..dd8df23 100644
115--- a/lib/lp/translations/model/pomsgid.py
116+++ b/lib/lp/translations/model/pomsgid.py
117@@ -3,7 +3,6 @@
118
119 __all__ = ["POMsgID"]
120
121-import six
122 from storm.expr import Func
123 from storm.locals import Int, Unicode
124 from zope.interface import implementer
125@@ -46,8 +45,7 @@ class POMsgID(StormBase):
126 IStore(POMsgID)
127 .find(
128 POMsgID,
129- Func("sha1", POMsgID.msgid)
130- == Func("sha1", six.ensure_text(key)),
131+ Func("sha1", POMsgID.msgid) == Func("sha1", key),
132 )
133 .one()
134 )
135diff --git a/lib/lp/translations/model/potranslation.py b/lib/lp/translations/model/potranslation.py
136index c367956..5d0626e 100644
137--- a/lib/lp/translations/model/potranslation.py
138+++ b/lib/lp/translations/model/potranslation.py
139@@ -3,7 +3,6 @@
140
141 __all__ = ["POTranslation"]
142
143-import six
144 from storm.expr import Func
145 from storm.locals import Int, Unicode
146 from zope.interface import implementer
147@@ -44,8 +43,7 @@ class POTranslation(StormBase):
148 IStore(POTranslation)
149 .find(
150 POTranslation,
151- Func("sha1", POTranslation.translation)
152- == Func("sha1", six.ensure_text(key)),
153+ Func("sha1", POTranslation.translation) == Func("sha1", key),
154 )
155 .one()
156 )
157@@ -60,11 +58,6 @@ class POTranslation(StormBase):
158 """Return a POTranslation object for the given translation, or create
159 it if it doesn't exist.
160 """
161- # If this is not a unicode object, it had better be ASCII or UTF-8.
162- # XXX: JeroenVermeulen 2008-06-06 bug=237868: non-ascii str strings
163- # should be contained in the parser or the browser code.
164- key = six.ensure_text(key)
165-
166 try:
167 return cls.getByTranslation(key)
168 except NotFoundError:
169diff --git a/lib/lp/translations/tests/test_translationimportqueue.py b/lib/lp/translations/tests/test_translationimportqueue.py
170index c20bf61..8a51550 100644
171--- a/lib/lp/translations/tests/test_translationimportqueue.py
172+++ b/lib/lp/translations/tests/test_translationimportqueue.py
173@@ -4,7 +4,6 @@
174 import os.path
175 from operator import attrgetter
176
177-import six
178 import transaction
179 from zope.component import getUtility
180 from zope.security.proxy import removeSecurityProxy
181@@ -330,7 +329,7 @@ class TestGetGuessedPOFile(TestCaseWithFactory):
182 )
183 queue_entry = self.queue.addOrUpdateEntry(
184 "%s.po" % template_path,
185- six.ensure_binary(template_name),
186+ template_name.encode(),
187 True,
188 self.uploaderperson,
189 distroseries=package.distroseries,
190diff --git a/lib/lp/translations/utilities/doc/gettext_po_parser.rst b/lib/lp/translations/utilities/doc/gettext_po_parser.rst
191index ae8013e..76710a3 100644
192--- a/lib/lp/translations/utilities/doc/gettext_po_parser.rst
193+++ b/lib/lp/translations/utilities/doc/gettext_po_parser.rst
194@@ -452,7 +452,7 @@ The special symbols and numeric representations of the chars '8', '80' and 'p'
195 are decoded correctly.
196
197 >>> for translation in translation_file.messages[0].translations:
198- ... print(repr(six.ensure_str(translation)))
199+ ... print(repr(translation))
200 ...
201 '\x07\x08\x0b\x0c\t\x0b\\"\'\n8 8 80 p\n'
202
203diff --git a/lib/lp/translations/utilities/gettext_po_parser.py b/lib/lp/translations/utilities/gettext_po_parser.py
204index 43b5354..a383360 100644
205--- a/lib/lp/translations/utilities/gettext_po_parser.py
206+++ b/lib/lp/translations/utilities/gettext_po_parser.py
207@@ -17,7 +17,6 @@ import re
208 from datetime import datetime, timezone
209 from email.utils import parseaddr
210
211-import six
212 from zope import datetime as zope_datetime
213 from zope.interface import implementer
214
215@@ -61,11 +60,14 @@ class POSyntaxWarning(Warning):
216 logging.info(self.message)
217
218 def __str__(self):
219- return six.ensure_text(self.message)
220+ return self.message
221
222
223 def parse_charset(string_to_parse, is_escaped=True):
224 """Return charset used in the given string_to_parse."""
225+ if isinstance(string_to_parse, bytes):
226+ string_to_parse = string_to_parse.decode("UTF-8", "replace")
227+
228 # Scan for the charset in the same way that gettext does.
229 default_charset = "UTF-8"
230 pattern = r"charset=([^\s]+)"
231@@ -75,9 +77,7 @@ def parse_charset(string_to_parse, is_escaped=True):
232 # Default to UTF-8 if the header still has the default value or
233 # is unknown.
234 charset = default_charset
235- match = re.search(
236- pattern, six.ensure_text(string_to_parse, "UTF-8", "replace")
237- )
238+ match = re.search(pattern, string_to_parse)
239 if match is not None and match.group(1) != b"CHARSET":
240 charset = match.group(1).strip()
241 try:
242diff --git a/lib/lp/translations/utilities/tests/test_file_importer.py b/lib/lp/translations/utilities/tests/test_file_importer.py
243index b33596e..b37590d 100644
244--- a/lib/lp/translations/utilities/tests/test_file_importer.py
245+++ b/lib/lp/translations/utilities/tests/test_file_importer.py
246@@ -5,7 +5,6 @@
247
248 from textwrap import dedent
249
250-import six
251 import transaction
252 from zope.component import getUtility
253 from zope.security.proxy import removeSecurityProxy
254@@ -143,7 +142,7 @@ class FileImporterTestCase(TestCaseWithFactory):
255 potemplate = self.factory.makePOTemplate()
256 template_entry = self.translation_import_queue.addOrUpdateEntry(
257 potemplate.path,
258- six.ensure_binary(pot_content),
259+ pot_content.encode(),
260 by_maintainer,
261 self.importer_person,
262 productseries=potemplate.productseries,
263@@ -172,7 +171,7 @@ class FileImporterTestCase(TestCaseWithFactory):
264 person = person or self.importer_person
265 translation_entry = self.translation_import_queue.addOrUpdateEntry(
266 pofile.path,
267- six.ensure_binary(po_content),
268+ po_content.encode(),
269 by_maintainer,
270 person,
271 productseries=potemplate.productseries,
272@@ -202,7 +201,7 @@ class FileImporterTestCase(TestCaseWithFactory):
273 potemplate = self.factory.makePOTemplate()
274 template_entry = self.translation_import_queue.addOrUpdateEntry(
275 potemplate.path,
276- six.ensure_binary(TEST_TEMPLATE_EXPORTED),
277+ TEST_TEMPLATE_EXPORTED.encode(),
278 False,
279 self.importer_person,
280 productseries=potemplate.productseries,
281@@ -467,7 +466,7 @@ class FileImporterTestCase(TestCaseWithFactory):
282 "should be none.",
283 )
284 potmsgset = po_importer.pofile.potemplate.getPOTMsgSetByMsgIDText(
285- six.ensure_text(TEST_MSGID)
286+ TEST_MSGID
287 )
288 message = potmsgset.getCurrentTranslation(
289 po_importer.potemplate,
290@@ -561,7 +560,7 @@ class FileImporterTestCase(TestCaseWithFactory):
291 # Although the message has an error, it should still be stored
292 # in the database, though only as a suggestion.
293 potmsgset = po_importer.pofile.potemplate.getPOTMsgSetByMsgIDText(
294- six.ensure_text(TEST_MSGID_ERROR)
295+ TEST_MSGID_ERROR
296 )
297 message = potmsgset.getLocalTranslationMessages(
298 po_importer.potemplate, po_importer.pofile.language
299@@ -593,7 +592,7 @@ class FileImporterTestCase(TestCaseWithFactory):
300 po_importer2.importFile()
301
302 potmsgset = po_importer.pofile.potemplate.getPOTMsgSetByMsgIDText(
303- six.ensure_text(TEST_MSGID_ERROR)
304+ TEST_MSGID_ERROR
305 )
306 messages = potmsgset.getLocalTranslationMessages(
307 po_importer.pofile.potemplate, po_importer.pofile.language
308@@ -665,7 +664,7 @@ class CreateFileImporterTestCase(TestCaseWithFactory):
309 po_content = TEST_TRANSLATION_FILE % ("", "foo", "bar")
310 queue_entry = self.translation_import_queue.addOrUpdateEntry(
311 pofile.path,
312- six.ensure_binary(po_content),
313+ po_content.encode(),
314 by_maintainer,
315 self.importer_person,
316 productseries=pofile.potemplate.productseries,
317diff --git a/lib/lp/translations/utilities/translation_import.py b/lib/lp/translations/utilities/translation_import.py
318index 1535590..901bbc1 100644
319--- a/lib/lp/translations/utilities/translation_import.py
320+++ b/lib/lp/translations/utilities/translation_import.py
321@@ -11,7 +11,6 @@ import posixpath
322 from datetime import datetime, timezone
323 from operator import attrgetter
324
325-import six
326 import transaction
327 from storm.exceptions import TimeoutError
328 from zope.component import getUtility
329@@ -636,7 +635,7 @@ class FileImporter:
330 "pomessage": self.format_exporter.exportTranslationMessageData(
331 message
332 ),
333- "error-message": six.ensure_text(errormsg),
334+ "error-message": errormsg,
335 }
336 )
337
338diff --git a/lib/lp/translations/utilities/translationmerger.py b/lib/lp/translations/utilities/translationmerger.py
339index 297f54a..2925e1e 100644
340--- a/lib/lp/translations/utilities/translationmerger.py
341+++ b/lib/lp/translations/utilities/translationmerger.py
342@@ -10,7 +10,6 @@ __all__ = [
343
344 from operator import methodcaller
345
346-import six
347 from storm.locals import ClassAlias, Store
348 from zope.component import getUtility
349 from zope.security.proxy import removeSecurityProxy
350@@ -316,8 +315,6 @@ class MessageSharingMerge(LaunchpadScript):
351 sourcepackagename=sourcepackagename,
352 )
353 template_regex = self.options.template_names
354- if template_regex is not None:
355- template_regex = six.ensure_text(template_regex)
356 equivalence_classes = subset.groupEquivalentPOTemplates(template_regex)
357
358 class_count = len(equivalence_classes)
359diff --git a/lib/lp/translations/utilities/xpi_header.py b/lib/lp/translations/utilities/xpi_header.py
360index b1aa348..cfabddc 100644
361--- a/lib/lp/translations/utilities/xpi_header.py
362+++ b/lib/lp/translations/utilities/xpi_header.py
363@@ -9,7 +9,6 @@ import io
364 from email.utils import parseaddr
365
366 import defusedxml.cElementTree as cElementTree
367-import six
368 from zope.interface import implementer
369
370 from lp.translations.interfaces.translationcommonformat import (
371@@ -65,9 +64,11 @@ class XpiHeader:
372 # Both cElementTree and elementtree fail when trying to parse
373 # proper unicode strings. Use our raw input instead.
374 try:
375+ raw_content = self._raw_content
376+ if not isinstance(raw_content, bytes):
377+ raw_content = raw_content.encode()
378 parse = cElementTree.iterparse(
379- io.BytesIO(six.ensure_binary(self._raw_content)),
380- forbid_dtd=True,
381+ io.BytesIO(raw_content), forbid_dtd=True
382 )
383 for event, elem in parse:
384 if elem.tag == contributor_tag:

Subscribers

People subscribed via source and target branches

to status/vote changes: