Merge ~cjwatson/launchpad:unsixify-trivial-strings into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: e77de9d3429deb3e9c4e7fa154a3efa9ec92f8f3
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:unsixify-trivial-strings
Merge into: launchpad:master
Diff against target: 895 lines (+81/-129)
28 files modified
lib/lp/archivepublisher/tests/archive-signing.rst (+1/-1)
lib/lp/archivepublisher/tests/test_publisher.py (+1/-1)
lib/lp/blueprints/browser/specification.py (+1/-2)
lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.rst (+3/-5)
lib/lp/code/model/gitref.py (+1/-2)
lib/lp/registry/browser/tests/test_distroseries.py (+1/-2)
lib/lp/scripts/tests/test_garbo.py (+1/-5)
lib/lp/services/gpg/handler.py (+1/-2)
lib/lp/services/librarian/client.py (+1/-1)
lib/lp/services/librarianserver/tests/test_doc.py (+2/-11)
lib/lp/services/mail/doc/emailauthentication.rst (+1/-1)
lib/lp/services/mail/doc/signedmessage.rst (+1/-1)
lib/lp/services/mail/incoming.py (+6/-6)
lib/lp/services/testing/tests/test_parallel.py (+3/-6)
lib/lp/services/tokens.py (+1/-4)
lib/lp/services/utils.py (+1/-2)
lib/lp/services/verification/tests/logintoken.py (+1/-3)
lib/lp/services/webapp/escaping.py (+2/-3)
lib/lp/soyuz/stories/ppa/xx-ppa-files.rst (+14/-26)
lib/lp/testing/gpgkeys/__init__.py (+1/-2)
lib/lp/translations/doc/poimport-pofile-old-po-imported.rst (+4/-4)
lib/lp/translations/doc/poimport-pofile-syntax-error.rst (+12/-12)
lib/lp/translations/doc/poimport.rst (+10/-10)
lib/lp/translations/doc/rosetta-karma.rst (+4/-4)
lib/lp/translations/doc/rosetta-poimport-script.rst (+2/-2)
lib/lp/translations/scripts/po_import.py (+1/-4)
lib/lp/translations/utilities/tests/test_gettext_po_exporter.py (+2/-4)
lib/lp/translations/utilities/tests/test_translation_importer.py (+2/-3)
Reviewer Review Type Date Requested Status
Colin Watson (community) Approve
Review via email: mp+436828@code.launchpad.net

Commit message

Avoid six.ensure_* in obvious cases

Description of the change

If we're dealing with something where it's obvious whether it's `bytes` or `str` (e.g. a literal or something that we just did an `isinstance` check on), then there's no need to use `six.ensure_*`; just use `.decode`/`.encode` directly.

`lp.testing.pages.http` accepts either `bytes` or `str`.

To post a comment you must log in.
Revision history for this message
Colin Watson (cjwatson) wrote :

Self-approving this, since the changes are trivial enough as to be not worth using reviewer time on, and I've done a full test run locally.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/archivepublisher/tests/archive-signing.rst b/lib/lp/archivepublisher/tests/archive-signing.rst
2index 13511cc..dc8eba9 100644
3--- a/lib/lp/archivepublisher/tests/archive-signing.rst
4+++ b/lib/lp/archivepublisher/tests/archive-signing.rst
5@@ -204,7 +204,7 @@ to test the export functions.
6 ... self.fingerprint = "fpr"
7 ...
8 ... def export(self):
9- ... return six.ensure_binary("Secret %s" % self.secret)
10+ ... return ("Secret %s" % self.secret).encode()
11 ...
12
13 exportSecretKey() raises an error if given a public key.
14diff --git a/lib/lp/archivepublisher/tests/test_publisher.py b/lib/lp/archivepublisher/tests/test_publisher.py
15index f3ac846..33fc909 100644
16--- a/lib/lp/archivepublisher/tests/test_publisher.py
17+++ b/lib/lp/archivepublisher/tests/test_publisher.py
18@@ -3507,7 +3507,7 @@ class TestUpdateByHash(TestPublisherBase):
19 for sourcename in ("foo", "bar", "baz"):
20 self.getPubSource(
21 sourcename=sourcename,
22- filecontent=six.ensure_binary("Source: %s\n" % sourcename),
23+ filecontent=("Source: %s\n" % sourcename).encode(),
24 )
25 self.runSteps(publisher, step_a=True, step_c=True, step_d=True)
26 with open(suite_path("Release"), "rb") as f:
27diff --git a/lib/lp/blueprints/browser/specification.py b/lib/lp/blueprints/browser/specification.py
28index b43ef4a..1186390 100644
29--- a/lib/lp/blueprints/browser/specification.py
30+++ b/lib/lp/blueprints/browser/specification.py
31@@ -41,7 +41,6 @@ from operator import attrgetter
32 from subprocess import PIPE, Popen
33 from typing import List
34
35-import six
36 from lazr.restful.interface import copy_field, use_template
37 from lazr.restful.interfaces import (
38 IFieldHTMLRenderer,
39@@ -1491,7 +1490,7 @@ def to_DOT_ID(value):
40
41 """
42 if isinstance(value, bytes):
43- unitext = six.ensure_text(value, encoding="ascii")
44+ unitext = value.decode(encoding="ascii")
45 else:
46 unitext = str(value)
47 output = unitext.replace('"', '\\"')
48diff --git a/lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.rst b/lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.rst
49index 598d95d..5f36cf6 100644
50--- a/lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.rst
51+++ b/lib/lp/bugs/stories/guided-filebug/xx-bug-reporting-tools.rst
52@@ -73,11 +73,9 @@ The most common case will be that the user is sent to the guided
53 >>> filebug_url = "http://%s%s" % (filebug_host, filebug_path)
54 >>> contents = str(
55 ... http(
56- ... six.ensure_binary(
57- ... "GET %s HTTP/1.1\nHostname: %s\n"
58- ... "Authorization: Basic test@canonical.com:test\n\n"
59- ... % (filebug_path, filebug_host)
60- ... )
61+ ... "GET %s HTTP/1.1\nHostname: %s\n"
62+ ... "Authorization: Basic test@canonical.com:test\n\n"
63+ ... % (filebug_path, filebug_host)
64 ... )
65 ... )
66
67diff --git a/lib/lp/code/model/gitref.py b/lib/lp/code/model/gitref.py
68index eed9381..60ef93f 100644
69--- a/lib/lp/code/model/gitref.py
70+++ b/lib/lp/code/model/gitref.py
71@@ -14,7 +14,6 @@ from urllib.parse import quote, quote_plus, urlsplit
72
73 import pytz
74 import requests
75-import six
76 from lazr.lifecycle.event import ObjectCreatedEvent
77 from storm.expr import And, Or
78 from storm.locals import DateTime, Int, Not, Reference, Store, Unicode
79@@ -406,7 +405,7 @@ class GitRefMixin:
80 memcache_key += ":limit=%s" % limit
81 if stop is not None:
82 memcache_key += ":stop=%s" % stop
83- memcache_key = six.ensure_binary(memcache_key)
84+ memcache_key = memcache_key.encode()
85
86 description = "log information for %s:%s" % (path, start)
87 log = memcache_client.get_json(memcache_key, logger, description)
88diff --git a/lib/lp/registry/browser/tests/test_distroseries.py b/lib/lp/registry/browser/tests/test_distroseries.py
89index fd9a066..f3e256f 100644
90--- a/lib/lp/registry/browser/tests/test_distroseries.py
91+++ b/lib/lp/registry/browser/tests/test_distroseries.py
92@@ -9,7 +9,6 @@ from datetime import timedelta
93 from textwrap import TextWrapper
94 from urllib.parse import urlencode, urlparse
95
96-import six
97 import soupmatchers
98 from fixtures import FakeLogger
99 from lazr.restful.interfaces import IJSONRequestCache
100@@ -1022,7 +1021,7 @@ class TestDistroSeriesLocalDiffPerformance(
101 list(prepare_statements(rec2)),
102 )
103 for line in diff:
104- yield six.ensure_binary("%s\n" % line)
105+ yield ("%s\n" % line).encode()
106
107 return statement_diff
108
109diff --git a/lib/lp/scripts/tests/test_garbo.py b/lib/lp/scripts/tests/test_garbo.py
110index dce4882..eae9163 100644
111--- a/lib/lp/scripts/tests/test_garbo.py
112+++ b/lib/lp/scripts/tests/test_garbo.py
113@@ -14,7 +14,6 @@ from datetime import datetime, timedelta
114 from functools import partial
115 from textwrap import dedent
116
117-import six
118 import transaction
119 from psycopg2 import IntegrityError
120 from pytz import UTC
121@@ -1416,10 +1415,7 @@ class TestGarbo(FakeAdapterMixin, TestCaseWithFactory):
122 naked_bug.heat_last_updated = old_update
123 IPrimaryStore(FeatureFlag).add(
124 FeatureFlag(
125- "default",
126- 0,
127- "bugs.heat_updates.cutoff",
128- six.ensure_text(cutoff.isoformat()),
129+ "default", 0, "bugs.heat_updates.cutoff", cutoff.isoformat()
130 )
131 )
132 transaction.commit()
133diff --git a/lib/lp/services/gpg/handler.py b/lib/lp/services/gpg/handler.py
134index 821a05d..b00378a 100644
135--- a/lib/lp/services/gpg/handler.py
136+++ b/lib/lp/services/gpg/handler.py
137@@ -23,7 +23,6 @@ from urllib.parse import urlencode
138 import gpgme
139 import pytz
140 import requests
141-import six
142 from lazr.restful.utils import get_current_browser_request
143 from zope.component import getUtility
144 from zope.interface import implementer
145@@ -472,7 +471,7 @@ class GPGHandler:
146 del os.environ["GPG_AGENT_INFO"]
147
148 def passphrase_cb(uid_hint, passphrase_info, prev_was_bad, fd):
149- os.write(fd, six.ensure_binary("%s\n" % password))
150+ os.write(fd, ("%s\n" % password).encode())
151
152 context.passphrase_cb = passphrase_cb
153
154diff --git a/lib/lp/services/librarian/client.py b/lib/lp/services/librarian/client.py
155index ddf1117..c8a803e 100644
156--- a/lib/lp/services/librarian/client.py
157+++ b/lib/lp/services/librarian/client.py
158@@ -131,7 +131,7 @@ class FileUploadClient:
159 self._checkError()
160
161 def _sendHeader(self, name, value):
162- self._sendLine(six.ensure_binary("%s: %s" % (name, value)))
163+ self._sendLine(("%s: %s" % (name, value)).encode())
164
165 def addFile(
166 self,
167diff --git a/lib/lp/services/librarianserver/tests/test_doc.py b/lib/lp/services/librarianserver/tests/test_doc.py
168index b9f7e67..4ae056a 100644
169--- a/lib/lp/services/librarianserver/tests/test_doc.py
170+++ b/lib/lp/services/librarianserver/tests/test_doc.py
171@@ -7,8 +7,6 @@ Run the doctests and pagetests.
172
173 import os
174
175-import six
176-
177 from lp.services.librarianserver.libraryprotocol import FileUploadProtocol
178 from lp.services.librarianserver.storage import WrongDatabaseError
179 from lp.services.testing import build_test_suite
180@@ -112,10 +110,7 @@ def upload_request(request):
181 server.dataReceived(request.replace(b"\n", b"\r\n"))
182
183 # Report on what happened
184- print(
185- "reply: %r"
186- % six.ensure_str(server.transport.bytesWritten.rstrip(b"\r\n"))
187- )
188+ print("reply: %r" % server.transport.bytesWritten.rstrip(b"\r\n").decode())
189
190 if server.transport.connectionLost:
191 print("connection closed")
192@@ -124,11 +119,7 @@ def upload_request(request):
193 if mockFile is not None and mockFile.stored:
194 print(
195 "file '%s' stored as %s, contents: %r"
196- % (
197- mockFile.name,
198- mockFile.mimetype,
199- six.ensure_str(mockFile.bytes),
200- )
201+ % (mockFile.name, mockFile.mimetype, mockFile.bytes.decode())
202 )
203
204 # Cleanup: remove the observer.
205diff --git a/lib/lp/services/mail/doc/emailauthentication.rst b/lib/lp/services/mail/doc/emailauthentication.rst
206index 7ddb3a4..94ba727 100644
207--- a/lib/lp/services/mail/doc/emailauthentication.rst
208+++ b/lib/lp/services/mail/doc/emailauthentication.rst
209@@ -156,7 +156,7 @@ starts failing, Python is probably fixed, so the manual boundary parsing
210 hack can be removed.
211
212 >>> msg = read_test_message("signed_folded_header.txt")
213- >>> print(six.ensure_str(msg.parsed_bytes))
214+ >>> print(msg.parsed_bytes.decode())
215 ... # doctest: -NORMALIZE_WHITESPACE
216 Date:...
217 ...
218diff --git a/lib/lp/services/mail/doc/signedmessage.rst b/lib/lp/services/mail/doc/signedmessage.rst
219index e93b6d7..a18bb64 100644
220--- a/lib/lp/services/mail/doc/signedmessage.rst
221+++ b/lib/lp/services/mail/doc/signedmessage.rst
222@@ -14,7 +14,7 @@ the attributes are correctly set.
223 True
224 >>> msg["To"]
225 'someone'
226- >>> print(six.ensure_text(msg.parsed_bytes))
227+ >>> print(msg.parsed_bytes.decode())
228 To: someone
229 <BLANKLINE>
230 Hello.
231diff --git a/lib/lp/services/mail/incoming.py b/lib/lp/services/mail/incoming.py
232index 6519976..9f2c990 100644
233--- a/lib/lp/services/mail/incoming.py
234+++ b/lib/lp/services/mail/incoming.py
235@@ -69,20 +69,20 @@ def canonicalise_line_endings(buf):
236 >>> b = canonicalise_line_endings(b"\n\nfoo\nbar\rbaz\r\n")
237 >>> isinstance(b, bytes)
238 True
239- >>> six.ensure_str(b)
240- '\r\n\r\nfoo\r\nbar\r\nbaz\r\n'
241+ >>> b
242+ b'\r\n\r\nfoo\r\nbar\r\nbaz\r\n'
243
244 >>> b = canonicalise_line_endings(b"\r\rfoo\r\nbar\rbaz\n")
245 >>> isinstance(b, bytes)
246 True
247- >>> six.ensure_str(b)
248- '\r\n\r\nfoo\r\nbar\r\nbaz\r\n'
249+ >>> b
250+ b'\r\n\r\nfoo\r\nbar\r\nbaz\r\n'
251
252 >>> b = canonicalise_line_endings(b"\r\nfoo\r\nbar\nbaz\r")
253 >>> isinstance(b, bytes)
254 True
255- >>> six.ensure_str(b)
256- '\r\nfoo\r\nbar\r\nbaz\r\n'
257+ >>> b
258+ b'\r\nfoo\r\nbar\r\nbaz\r\n'
259 """
260 if non_canonicalised_line_endings.search(buf):
261 buf = non_canonicalised_line_endings.sub(b"\r\n", buf)
262diff --git a/lib/lp/services/testing/tests/test_parallel.py b/lib/lp/services/testing/tests/test_parallel.py
263index 41636b7..0a3739c 100644
264--- a/lib/lp/services/testing/tests/test_parallel.py
265+++ b/lib/lp/services/testing/tests/test_parallel.py
266@@ -8,7 +8,6 @@ import subprocess
267 import tempfile
268 from textwrap import dedent
269
270-import six
271 from fixtures import PopenFixture, TestWithFixtures
272 from testtools import TestCase, TestResult
273
274@@ -106,16 +105,14 @@ class TestUtilities(TestCase, TestWithFixtures):
275 return {
276 "stdin": io.BytesIO(),
277 "stdout": io.BytesIO(
278- six.ensure_binary(
279- dedent(
280- """\
281+ dedent(
282+ """\
283 test: quux
284 successful: quux
285 test: glom
286 successful: glom
287 """
288- )
289- )
290+ ).encode()
291 ),
292 }
293
294diff --git a/lib/lp/services/tokens.py b/lib/lp/services/tokens.py
295index 551f61e..e4f92cf 100644
296--- a/lib/lp/services/tokens.py
297+++ b/lib/lp/services/tokens.py
298@@ -9,8 +9,6 @@ __all__ = [
299
300 import random
301
302-import six
303-
304
305 def create_token(token_length):
306 """Create a random token string.
307@@ -20,8 +18,7 @@ def create_token(token_length):
308 # Since tokens are, in general, user-visible, vowels are not included
309 # below to prevent them from having curse/offensive words.
310 characters = "0123456789bcdfghjklmnpqrstvwxzBCDFGHJKLMNPQRSTVWXZ"
311- token = "".join(
312+ return "".join(
313 random.SystemRandom().choice(characters)
314 for count in range(token_length)
315 )
316- return six.ensure_text(token)
317diff --git a/lib/lp/services/utils.py b/lib/lp/services/utils.py
318index dfa3f10..495be31 100644
319--- a/lib/lp/services/utils.py
320+++ b/lib/lp/services/utils.py
321@@ -41,7 +41,6 @@ from textwrap import dedent
322 from types import FunctionType
323
324 import pytz
325-import six
326 from lazr.enum import BaseItem
327 from twisted.python.util import mergeFunctionMetadata
328 from zope.security.proxy import isinstance as zope_isinstance
329@@ -123,7 +122,7 @@ def value_string(item):
330 elif zope_isinstance(item, BaseItem):
331 return item.title
332 elif zope_isinstance(item, bytes):
333- return six.ensure_text(item)
334+ return item.decode()
335 else:
336 return str(item)
337
338diff --git a/lib/lp/services/verification/tests/logintoken.py b/lib/lp/services/verification/tests/logintoken.py
339index a45f131..0836d27 100644
340--- a/lib/lp/services/verification/tests/logintoken.py
341+++ b/lib/lp/services/verification/tests/logintoken.py
342@@ -6,8 +6,6 @@
343 import email
344 import re
345
346-import six
347-
348
349 def get_token_url_from_email(email_msg):
350 """Return the logintoken URL contained in the given email message."""
351@@ -17,4 +15,4 @@ def get_token_url_from_email(email_msg):
352
353 def get_token_url_from_bytes(buf):
354 """Return the logintoken URL contained in the given byte string."""
355- return six.ensure_str(re.findall(rb"http.*/token/.*", buf)[0])
356+ return re.findall(rb"http.*/token/.*", buf)[0].decode()
357diff --git a/lib/lp/services/webapp/escaping.py b/lib/lp/services/webapp/escaping.py
358index 5df92a3..ac188d5 100644
359--- a/lib/lp/services/webapp/escaping.py
360+++ b/lib/lp/services/webapp/escaping.py
361@@ -7,7 +7,6 @@ __all__ = [
362 "structured",
363 ]
364
365-import six
366 from lazr.restful.utils import get_current_browser_request
367 from zope.i18n import Message, translate
368 from zope.interface import implementer
369@@ -49,7 +48,7 @@ def html_escape(message):
370 # first. See bug #54987.
371 raw = translate_if_i18n(message)
372 if isinstance(raw, bytes):
373- raw = six.ensure_text(raw)
374+ raw = raw.decode()
375 else:
376 raw = str(raw)
377 for needle, replacement in HTML_REPLACEMENTS:
378@@ -90,7 +89,7 @@ class structured:
379 def __init__(self, text, *reps, **kwreps):
380 text = translate_if_i18n(text)
381 if isinstance(text, bytes):
382- text = six.ensure_text(text)
383+ text = text.decode()
384 else:
385 text = str(text)
386 self.text = text
387diff --git a/lib/lp/soyuz/stories/ppa/xx-ppa-files.rst b/lib/lp/soyuz/stories/ppa/xx-ppa-files.rst
388index 525a1f1..7e0ce09 100644
389--- a/lib/lp/soyuz/stories/ppa/xx-ppa-files.rst
390+++ b/lib/lp/soyuz/stories/ppa/xx-ppa-files.rst
391@@ -305,13 +305,11 @@ The 'No Privileges' user, the PPA owner, can download the DSC file.
392
393 >>> print(
394 ... http(
395- ... six.ensure_binary(
396- ... r"""
397+ ... r"""
398 ... GET %s HTTP/1.1
399 ... Authorization: Basic no-priv@canonical.com:test
400 ... """
401- ... % (dsc_file_lp_url.replace("http://launchpad.test", ""))
402- ... )
403+ ... % (dsc_file_lp_url.replace("http://launchpad.test", ""))
404 ... )
405 ... )
406 HTTP/1.1 303 See Other
407@@ -333,13 +331,11 @@ Binary files are served via '+files' rather than '+sourcefiles'.
408 zope.security.interfaces.Unauthorized
409 >>> print(
410 ... http(
411- ... six.ensure_binary(
412- ... r"""
413+ ... r"""
414 ... GET %s HTTP/1.1
415 ... Authorization: Basic no-priv@canonical.com:test
416 ... """
417- ... % (deb_file_lp_url.replace("http://launchpad.test", ""))
418- ... )
419+ ... % (deb_file_lp_url.replace("http://launchpad.test", ""))
420 ... )
421 ... )
422 HTTP/1.1 303 See Other
423@@ -390,12 +386,10 @@ binaries across to no-priv's public ppa.
424
425 >>> print(
426 ... http(
427- ... six.ensure_binary(
428- ... r"""
429+ ... r"""
430 ... GET %s HTTP/1.1
431 ... """
432- ... % file_lp_url.replace("http://launchpad.test", "")
433- ... )
434+ ... % file_lp_url.replace("http://launchpad.test", "")
435 ... )
436 ... )
437 HTTP/1.1 303 See Other
438@@ -424,13 +418,11 @@ redirect to the files for the default named PPA.
439
440 >>> print(
441 ... http(
442- ... six.ensure_binary(
443- ... r"""
444+ ... r"""
445 ... GET %s HTTP/1.1
446 ... """
447- ... % file_lp_url_without_ppa_name.replace(
448- ... "http://launchpad.test", ""
449- ... )
450+ ... % file_lp_url_without_ppa_name.replace(
451+ ... "http://launchpad.test", ""
452 ... )
453 ... )
454 ... ) # noqa
455@@ -446,13 +438,11 @@ The same redirection happens for +archive/+build/blah urls:
456 ... )
457 >>> print(
458 ... http(
459- ... six.ensure_binary(
460- ... r"""
461+ ... r"""
462 ... GET %s HTTP/1.1
463 ... """
464- ... % buildlog_lp_url_without_ppa_name.replace(
465- ... "http://launchpad.test", ""
466- ... )
467+ ... % buildlog_lp_url_without_ppa_name.replace(
468+ ... "http://launchpad.test", ""
469 ... )
470 ... )
471 ... )
472@@ -515,12 +505,10 @@ LP proxy URL a proper NotFound error is raised.
473 http://launchpad.test/~no-priv/+archive/ubuntu/ppa/+sourcefiles/test-pkg/1.0/test-pkg_1.0.dsc
474
475 >>> not_found_file = http(
476- ... six.ensure_binary(
477- ... r"""
478+ ... r"""
479 ... GET %s HTTP/1.1
480 ... """
481- ... % file_lp_url.replace("http://launchpad.test", "")
482- ... )
483+ ... % file_lp_url.replace("http://launchpad.test", "")
484 ... )
485
486 It results in a 404 response.
487diff --git a/lib/lp/testing/gpgkeys/__init__.py b/lib/lp/testing/gpgkeys/__init__.py
488index 46b9581..a7cd653 100644
489--- a/lib/lp/testing/gpgkeys/__init__.py
490+++ b/lib/lp/testing/gpgkeys/__init__.py
491@@ -20,7 +20,6 @@ import os
492 from io import BytesIO
493
494 import gpgme
495-import six
496 from zope.component import getUtility
497
498 from lp.registry.interfaces.gpg import IGPGKeySet
499@@ -133,7 +132,7 @@ def decrypt_content(content, password):
500 plain = BytesIO()
501
502 def passphrase_cb(uid_hint, passphrase_info, prev_was_bad, fd):
503- os.write(fd, six.ensure_binary("%s\n" % password))
504+ os.write(fd, ("%s\n" % password).encode())
505
506 ctx.passphrase_cb = passphrase_cb
507
508diff --git a/lib/lp/translations/doc/poimport-pofile-old-po-imported.rst b/lib/lp/translations/doc/poimport-pofile-old-po-imported.rst
509index 059c172..6474ebc 100644
510--- a/lib/lp/translations/doc/poimport-pofile-old-po-imported.rst
511+++ b/lib/lp/translations/doc/poimport-pofile-old-po-imported.rst
512@@ -64,7 +64,7 @@ We create the POFile object where we are going to attach the .po file.
513
514 First, we do a valid import.
515
516- >>> pofile_contents = six.ensure_binary(
517+ >>> pofile_contents = (
518 ... r"""
519 ... msgid ""
520 ... msgstr ""
521@@ -79,7 +79,7 @@ First, we do a valid import.
522 ... msgstr "blah"
523 ... """
524 ... % datetime.datetime.now(UTC).isoformat()
525- ... )
526+ ... ).encode()
527 >>> by_maintainer = False
528 >>> entry = translation_import_queue.addOrUpdateEntry(
529 ... pofile.path,
530@@ -121,7 +121,7 @@ file we just imported.
531 Now, we are going to import a .po file that has a 'PO-Revision-Date'
532 field with a date older than a previous .po import.
533
534- >>> pofile_contents = six.ensure_binary(
535+ >>> pofile_contents = (
536 ... r"""
537 ... msgid ""
538 ... msgstr ""
539@@ -136,7 +136,7 @@ field with a date older than a previous .po import.
540 ... msgstr "blah"
541 ... """
542 ... % datetime.datetime.now(UTC).isoformat()
543- ... )
544+ ... ).encode()
545 >>> by_maintainer = False
546 >>> entry = translation_import_queue.addOrUpdateEntry(
547 ... pofile.path,
548diff --git a/lib/lp/translations/doc/poimport-pofile-syntax-error.rst b/lib/lp/translations/doc/poimport-pofile-syntax-error.rst
549index 86d379b..9e9c10b 100644
550--- a/lib/lp/translations/doc/poimport-pofile-syntax-error.rst
551+++ b/lib/lp/translations/doc/poimport-pofile-syntax-error.rst
552@@ -60,7 +60,7 @@ We create the POFile object where we are going to attach the .po file.
553 Let's import a .po file that misses the '"' char after msgstr. That's a
554 syntax error.
555
556- >>> pofile_contents = six.ensure_binary(
557+ >>> pofile_contents = (
558 ... r"""
559 ... msgid ""
560 ... msgstr ""
561@@ -75,7 +75,7 @@ syntax error.
562 ... msgstr blah"
563 ... """
564 ... % datetime.datetime.now(UTC).isoformat()
565- ... )
566+ ... ).encode()
567 >>> by_maintainer = False
568 >>> entry = translation_import_queue.addOrUpdateEntry(
569 ... pofile.path,
570@@ -213,7 +213,7 @@ In his rush to be the first Sumerian translator for Firefox, Mark
571 submits a translation with a nonsensical plurals definition.
572
573 >>> pofile = potemplate.newPOFile("sux")
574- >>> pofile_contents = six.ensure_binary(
575+ >>> pofile_contents = (
576 ... r"""
577 ... msgid ""
578 ... msgstr ""
579@@ -227,7 +227,7 @@ submits a translation with a nonsensical plurals definition.
580 ... msgstr "bar"
581 ... """
582 ... % datetime.datetime.now(UTC).isoformat()
583- ... )
584+ ... ).encode()
585 >>> entry = translation_import_queue.addOrUpdateEntry(
586 ... pofile.path,
587 ... pofile_contents,
588@@ -266,7 +266,7 @@ Not enough forms
589 Mark mistakenly attempts to import a translation with "zero" plural
590 forms. He receives an email notifying him of a syntax error.
591
592- >>> pofile_contents = six.ensure_binary(
593+ >>> pofile_contents = (
594 ... r"""
595 ... msgid ""
596 ... msgstr ""
597@@ -280,7 +280,7 @@ forms. He receives an email notifying him of a syntax error.
598 ... msgstr "bar"
599 ... """
600 ... % datetime.datetime.now(UTC).isoformat()
601- ... )
602+ ... ).encode()
603 >>> entry = translation_import_queue.addOrUpdateEntry(
604 ... pofile.path,
605 ... pofile_contents,
606@@ -313,7 +313,7 @@ forms. He receives an email notifying him of a syntax error.
607 On his next attempt, Mark accidentally types a negative number of plural
608 forms. The same error is given.
609
610- >>> pofile_contents = six.ensure_binary(
611+ >>> pofile_contents = (
612 ... r"""
613 ... msgid ""
614 ... msgstr ""
615@@ -327,7 +327,7 @@ forms. The same error is given.
616 ... msgstr "bar"
617 ... """
618 ... % datetime.datetime.now(UTC).isoformat()
619- ... )
620+ ... ).encode()
621 >>> entry = translation_import_queue.addOrUpdateEntry(
622 ... pofile.path,
623 ... pofile_contents,
624@@ -371,7 +371,7 @@ to get that information corrected if need be.
625 >>> pofile = potemplate.newPOFile("ar")
626
627 # PO file with nplurals=7, a value we can't handle.
628- >>> pofile_contents = six.ensure_binary(
629+ >>> pofile_contents = (
630 ... r"""
631 ... msgid ""
632 ... msgstr ""
633@@ -392,7 +392,7 @@ to get that information corrected if need be.
634 ... msgstr[6] "barim %%d"
635 ... """
636 ... % datetime.datetime.now(UTC).isoformat()
637- ... )
638+ ... ).encode()
639 >>> entry = translation_import_queue.addOrUpdateEntry(
640 ... pofile.path,
641 ... pofile_contents,
642@@ -444,7 +444,7 @@ Once Mark has checked the language page and corrected the number of
643 plural forms, the file imports just fine.
644
645 # Same PO file as before, but with nplurals=6.
646- >>> pofile_contents = six.ensure_binary(
647+ >>> pofile_contents = (
648 ... r"""
649 ... msgid ""
650 ... msgstr ""
651@@ -464,7 +464,7 @@ plural forms, the file imports just fine.
652 ... msgstr[5] "barorum %%d"
653 ... """
654 ... % datetime.datetime.now(UTC).isoformat()
655- ... )
656+ ... ).encode()
657 >>> entry = translation_import_queue.addOrUpdateEntry(
658 ... pofile.path,
659 ... pofile_contents,
660diff --git a/lib/lp/translations/doc/poimport.rst b/lib/lp/translations/doc/poimport.rst
661index 31b7369..b0a15b3 100644
662--- a/lib/lp/translations/doc/poimport.rst
663+++ b/lib/lp/translations/doc/poimport.rst
664@@ -59,7 +59,7 @@ And this is the POTemplate where the import will be done.
665
666 This is the file that'll get imported.
667
668- >>> potemplate_contents = six.ensure_binary(
669+ >>> potemplate_contents = (
670 ... r"""
671 ... msgid ""
672 ... msgstr ""
673@@ -92,7 +92,7 @@ This is the file that'll get imported.
674 ... msgstr ""
675 ... """
676 ... % datetime.datetime.now(UTC).isoformat()
677- ... ) # noqa
678+ ... ).encode() # noqa
679
680 We sometimes saw deadlocks as POFile statistics were updated after
681 importing a template. The operation would read all translation messages
682@@ -239,7 +239,7 @@ Import With Errors
683 Here are the contents of the file we'll be importing. It has some
684 validation errors.
685
686- >>> pofile_with_errors = six.ensure_binary(
687+ >>> pofile_with_errors = (
688 ... r"""
689 ... msgid ""
690 ... msgstr ""
691@@ -273,7 +273,7 @@ validation errors.
692 ... msgstr[3] "We have four! %%d"
693 ... """
694 ... % datetime.datetime.now(UTC).isoformat()
695- ... ) # noqa
696+ ... ).encode() # noqa
697
698 This is the dbschema that controls the validation of a translation.
699
700@@ -456,7 +456,7 @@ instance) and they don't mean that any messages failed to import.
701
702 For example, here's a gettext PO file with two headers.
703
704- >>> pofile_with_warning = six.ensure_binary(
705+ >>> pofile_with_warning = (
706 ... r"""
707 ... msgid ""
708 ... msgstr ""
709@@ -475,7 +475,7 @@ For example, here's a gettext PO file with two headers.
710 ... msgstr "b"
711 ... """
712 ... % datetime.datetime.now(UTC).isoformat()
713- ... ) # noqa
714+ ... ).encode() # noqa
715 >>> eo_pofile = potemplate.newPOFile("eo")
716 >>> warning_entry = translation_import_queue.addOrUpdateEntry(
717 ... "eo.po",
718@@ -526,7 +526,7 @@ Import Without Errors
719 Now, let's import one without errors. This file changes one translation
720 and adds another one.
721
722- >>> pofile_without_errors = six.ensure_binary(
723+ >>> pofile_without_errors = (
724 ... r"""
725 ... msgid ""
726 ... msgstr ""
727@@ -547,7 +547,7 @@ and adds another one.
728 ... msgstr "helpful@example.com"
729 ... """
730 ... % datetime.datetime.now(UTC).isoformat()
731- ... )
732+ ... ).encode()
733 >>> entry = translation_import_queue.addOrUpdateEntry(
734 ... pofile.path,
735 ... pofile_without_errors,
736@@ -701,7 +701,7 @@ plural forms).
737
738 We'll import a POFile with 3 plural forms into this POFile:
739
740- >>> pofile_with_plurals = six.ensure_binary(
741+ >>> pofile_with_plurals = (
742 ... r"""
743 ... msgid ""
744 ... msgstr ""
745@@ -719,7 +719,7 @@ We'll import a POFile with 3 plural forms into this POFile:
746 ... msgstr[2] "Third form %%d"
747 ... """
748 ... % datetime.datetime.now(UTC).isoformat()
749- ... ) # noqa
750+ ... ).encode() # noqa
751
752 We now import this POFile as this language's translation for the source
753 package:
754diff --git a/lib/lp/translations/doc/rosetta-karma.rst b/lib/lp/translations/doc/rosetta-karma.rst
755index 91d255c..457dd91 100644
756--- a/lib/lp/translations/doc/rosetta-karma.rst
757+++ b/lib/lp/translations/doc/rosetta-karma.rst
758@@ -130,7 +130,7 @@ Let's say that we have this .po file to import:
759 >>> import datetime
760 >>> import pytz
761 >>> UTC = pytz.timezone("UTC")
762- >>> pofile_contents = six.ensure_binary(
763+ >>> pofile_contents = (
764 ... r"""
765 ... msgid ""
766 ... msgstr ""
767@@ -141,7 +141,7 @@ Let's say that we have this .po file to import:
768 ... msgstr "bar"
769 ... """
770 ... % datetime.datetime.now(UTC).isoformat()
771- ... )
772+ ... ).encode()
773 >>> potemplate = POTemplate.get(1)
774 >>> pofile = potemplate.getPOFileByLang("es")
775
776@@ -215,7 +215,7 @@ Tell the PO file to import from the file data it has.
777 Now, the user is going to upload a local edition of the .po file. In this
778 case, we will give karma *only* because the translation change.
779
780- >>> pofile_contents = six.ensure_binary(
781+ >>> pofile_contents = (
782 ... r"""
783 ... msgid ""
784 ... msgstr ""
785@@ -226,7 +226,7 @@ case, we will give karma *only* because the translation change.
786 ... msgstr "bars"
787 ... """
788 ... % datetime.datetime.now(UTC).isoformat()
789- ... )
790+ ... ).encode()
791
792 We attach the new file as not coming from upstream.
793
794diff --git a/lib/lp/translations/doc/rosetta-poimport-script.rst b/lib/lp/translations/doc/rosetta-poimport-script.rst
795index 4131971..bb4273c 100644
796--- a/lib/lp/translations/doc/rosetta-poimport-script.rst
797+++ b/lib/lp/translations/doc/rosetta-poimport-script.rst
798@@ -32,7 +32,7 @@ the sampledata.
799 None
800
801 >>> pofile = potemplate.newPOFile("sr")
802- >>> pofile_content = six.ensure_binary(
803+ >>> pofile_content = (
804 ... """
805 ... msgid ""
806 ... msgstr ""
807@@ -45,7 +45,7 @@ the sampledata.
808 ... msgstr "Bar"
809 ... """
810 ... % datetime.datetime.now(UTC).isoformat()
811- ... )
812+ ... ).encode()
813
814 We clean the import queue.
815
816diff --git a/lib/lp/translations/scripts/po_import.py b/lib/lp/translations/scripts/po_import.py
817index ddbce5d..e7b2f3e 100644
818--- a/lib/lp/translations/scripts/po_import.py
819+++ b/lib/lp/translations/scripts/po_import.py
820@@ -11,7 +11,6 @@ import sys
821 from datetime import datetime, timedelta
822
823 import pytz
824-import six
825 from zope.component import getUtility
826
827 from lp.app.interfaces.launchpad import ILaunchpadCelebrities
828@@ -79,9 +78,7 @@ class TranslationsImport(LaunchpadCronScript):
829
830 def _registerFailure(self, entry, reason, traceback=False, abort=False):
831 """Note that a queue entry is unusable in some way."""
832- reason_text = (
833- six.ensure_text(reason) if reason is bytes else str(reason)
834- )
835+ reason_text = reason.decode() if reason is bytes else str(reason)
836 entry.setStatus(
837 RosettaImportStatus.FAILED,
838 getUtility(ILaunchpadCelebrities).rosetta_experts,
839diff --git a/lib/lp/translations/utilities/tests/test_gettext_po_exporter.py b/lib/lp/translations/utilities/tests/test_gettext_po_exporter.py
840index 7e055d7..7780873 100644
841--- a/lib/lp/translations/utilities/tests/test_gettext_po_exporter.py
842+++ b/lib/lp/translations/utilities/tests/test_gettext_po_exporter.py
843@@ -3,7 +3,6 @@
844
845 from textwrap import dedent
846
847-import six
848 from zope.interface.verify import verifyObject
849
850 from lp.services.helpers import test_diff
851@@ -47,12 +46,11 @@ class GettextPOExporterTestCase(TestCaseWithFactory):
852 return
853
854 import_lines = [
855- six.ensure_text(line, errors="replace")
856- for line in import_file.split(b"\n")
857+ line.decode(errors="replace") for line in import_file.split(b"\n")
858 ]
859 # Remove X-Launchpad-Export-Date line to prevent time bombs in tests.
860 export_lines = [
861- six.ensure_text(line, errors="replace")
862+ line.decode(errors="replace")
863 for line in export_file.split(b"\n")
864 if (
865 not line.startswith(b'"X-Launchpad-Export-Date:')
866diff --git a/lib/lp/translations/utilities/tests/test_translation_importer.py b/lib/lp/translations/utilities/tests/test_translation_importer.py
867index 03af93c..98925ae 100644
868--- a/lib/lp/translations/utilities/tests/test_translation_importer.py
869+++ b/lib/lp/translations/utilities/tests/test_translation_importer.py
870@@ -5,7 +5,6 @@
871
872 from io import BytesIO
873
874-import six
875 import transaction
876
877 from lp.services.log.logger import DevNullLogger
878@@ -262,7 +261,7 @@ class TranslationImporterTestCase(TestCaseWithFactory):
879 pofile=pofile, potmsgset=potmsgset1
880 )
881
882- text = six.ensure_binary(
883+ text = (
884 """
885 msgid ""
886 msgstr ""
887@@ -275,7 +274,7 @@ class TranslationImporterTestCase(TestCaseWithFactory):
888 msgstr "A translation."
889 """
890 % potmsgset2.msgid_singular.msgid
891- )
892+ ).encode()
893
894 entry = self.factory.makeTranslationImportQueueEntry(
895 "foo.po",

Subscribers

People subscribed via source and target branches

to status/vote changes: