launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #25961
[Merge] ~cjwatson/launchpad:py3-character-ranges into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-character-ranges into launchpad:master.
Commit message:
Adjust character range handling for Python 3
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/395943
We need to use `six.unichr` rather than `unichr`, and `six.int2byte` rather than `chr` (where the intent is to produce bytes).
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-character-ranges into launchpad:master.
diff --git a/lib/lp/code/browser/tests/test_branchmergeproposal.py b/lib/lp/code/browser/tests/test_branchmergeproposal.py
index eacb6e3..a5b3520 100644
--- a/lib/lp/code/browser/tests/test_branchmergeproposal.py
+++ b/lib/lp/code/browser/tests/test_branchmergeproposal.py
@@ -1399,8 +1399,8 @@ class TestBranchMergeProposalView(TestCaseWithFactory):
self.assertIs(None, view.preview_diff_text)
def test_preview_diff_utf8(self):
- """A preview_diff in utf-8 should decoded as utf-8."""
- text = ''.join(unichr(x) for x in range(255))
+ """A preview_diff in utf-8 should be decoded as utf-8."""
+ text = ''.join(six.unichr(x) for x in range(255))
diff_bytes = ''.join(unified_diff('', text)).encode('utf-8')
self.setPreviewDiff(diff_bytes)
transaction.commit()
@@ -1411,7 +1411,7 @@ class TestBranchMergeProposalView(TestCaseWithFactory):
def test_preview_diff_all_chars(self):
"""preview_diff should work on diffs containing all possible bytes."""
- text = b''.join(chr(x) for x in range(255))
+ text = b''.join(six.int2byte(x) for x in range(255))
diff_bytes = b''.join(unified_diff(b'', text))
self.setPreviewDiff(diff_bytes)
transaction.commit()
@@ -1423,7 +1423,7 @@ class TestBranchMergeProposalView(TestCaseWithFactory):
def test_preview_diff_timeout(self):
# The preview_diff will recover from a timeout set to get the
# librarian content.
- text = b''.join(chr(x) for x in range(255))
+ text = b''.join(six.int2byte(x) for x in range(255))
diff_bytes = b''.join(unified_diff(b'', text))
preview_diff = self.setPreviewDiff(diff_bytes)
transaction.commit()
@@ -1443,7 +1443,7 @@ class TestBranchMergeProposalView(TestCaseWithFactory):
# The preview_diff will recover from a LookupError while getting the
# librarian content. (This can happen e.g. on staging replicas of
# the production database.)
- text = b''.join(chr(x) for x in range(255))
+ text = b''.join(six.int2byte(x) for x in range(255))
diff_bytes = b''.join(unified_diff(b'', text))
preview_diff = self.setPreviewDiff(diff_bytes)
transaction.commit()
diff --git a/lib/lp/code/model/tests/test_branchhosting.py b/lib/lp/code/model/tests/test_branchhosting.py
index 35734ad..4fe2ee6 100644
--- a/lib/lp/code/model/tests/test_branchhosting.py
+++ b/lib/lp/code/model/tests/test_branchhosting.py
@@ -16,6 +16,7 @@ import re
from lazr.restful.utils import get_current_browser_request
import responses
+import six
from testtools.matchers import MatchesStructure
from zope.component import getUtility
from zope.interface import implementer
@@ -158,14 +159,14 @@ class TestBranchHostingClient(TestCase):
"+branch-id/123/+json/files/%2Brev%20id%3F/%2Bfile/%20name%3F")
def test_getBlob(self):
- blob = b"".join(chr(i) for i in range(256))
+ blob = b"".join(six.int2byte(i) for i in range(256))
with self.mockRequests("GET", body=blob):
response = self.client.getBlob(123, "file-id")
self.assertEqual(blob, response)
self.assertRequest("+branch-id/123/download/head%3A/file-id")
def test_getBlob_revision(self):
- blob = b"".join(chr(i) for i in range(256))
+ blob = b"".join(six.int2byte(i) for i in range(256))
with self.mockRequests("GET", body=blob):
response = self.client.getBlob(123, "file-id", rev="a")
self.assertEqual(blob, response)
@@ -198,7 +199,7 @@ class TestBranchHostingClient(TestCase):
self.client.getBlob, 123, "file-id")
def test_getBlob_url_quoting(self):
- blob = b"".join(chr(i) for i in range(256))
+ blob = b"".join(six.int2byte(i) for i in range(256))
with self.mockRequests("GET", body=blob):
self.client.getBlob(123, "+file/ id?", rev="+rev id?")
self.assertRequest(
@@ -206,7 +207,7 @@ class TestBranchHostingClient(TestCase):
def test_works_in_job(self):
# `BranchHostingClient` is usable from a running job.
- blob = b"".join(chr(i) for i in range(256))
+ blob = b"".join(six.int2byte(i) for i in range(256))
@implementer(IRunnableJob)
class GetBlobJob(BaseRunnableJob):
diff --git a/lib/lp/code/model/tests/test_branchnamespace.py b/lib/lp/code/model/tests/test_branchnamespace.py
index 2c38d98..668363a 100644
--- a/lib/lp/code/model/tests/test_branchnamespace.py
+++ b/lib/lp/code/model/tests/test_branchnamespace.py
@@ -7,6 +7,7 @@ from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
+import six
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
@@ -1109,7 +1110,7 @@ class BaseValidateNewBranchMixin:
def test_permitted_first_character(self):
# The first character of a branch name must be a letter or a number.
namespace = self._getNamespace(self.factory.makePerson())
- for c in [chr(i) for i in range(128)]:
+ for c in [six.unichr(i) for i in range(128)]:
if c.isalnum():
namespace.validateBranchName(c)
else:
@@ -1121,7 +1122,7 @@ class BaseValidateNewBranchMixin:
# After the first character, letters, numbers and certain punctuation
# is permitted.
namespace = self._getNamespace(self.factory.makePerson())
- for c in [chr(i) for i in range(128)]:
+ for c in [six.unichr(i) for i in range(128)]:
if c.isalnum() or c in '+-_@.':
namespace.validateBranchName('a' + c)
else:
diff --git a/lib/lp/code/model/tests/test_githosting.py b/lib/lp/code/model/tests/test_githosting.py
index 23d6063..0044307 100644
--- a/lib/lp/code/model/tests/test_githosting.py
+++ b/lib/lp/code/model/tests/test_githosting.py
@@ -21,6 +21,7 @@ import re
from lazr.restful.utils import get_current_browser_request
import responses
+import six
from six.moves.urllib.parse import (
parse_qsl,
urlsplit,
@@ -332,7 +333,7 @@ class TestGitHostingClient(TestCase):
self.client.delete, "123")
def test_getBlob(self):
- blob = b''.join(chr(i) for i in range(256))
+ blob = b''.join(six.int2byte(i) for i in range(256))
payload = {"data": blob.encode("base64"), "size": len(blob)}
with self.mockRequests("GET", json=payload):
response = self.client.getBlob("123", "dir/path/file/name")
@@ -341,7 +342,7 @@ class TestGitHostingClient(TestCase):
"repo/123/blob/dir/path/file/name", method="GET")
def test_getBlob_revision(self):
- blob = b''.join(chr(i) for i in range(256))
+ blob = b''.join(six.int2byte(i) for i in range(256))
payload = {"data": blob.encode("base64"), "size": len(blob)}
with self.mockRequests("GET", json=payload):
response = self.client.getBlob("123", "dir/path/file/name", "dev")
@@ -373,7 +374,7 @@ class TestGitHostingClient(TestCase):
self.client.getBlob, "123", "dir/path/file/name")
def test_getBlob_url_quoting(self):
- blob = b''.join(chr(i) for i in range(256))
+ blob = b''.join(six.int2byte(i) for i in range(256))
payload = {"data": blob.encode("base64"), "size": len(blob)}
with self.mockRequests("GET", json=payload):
self.client.getBlob("123", "dir/+file name?.txt", "+rev/ no?")
@@ -403,7 +404,7 @@ class TestGitHostingClient(TestCase):
self.client.getBlob, "123", "dir/path/file/name")
def test_getBlob_wrong_size(self):
- blob = b''.join(chr(i) for i in range(256))
+ blob = b''.join(six.int2byte(i) for i in range(256))
payload = {"data": blob.encode("base64"), "size": 0}
with self.mockRequests("GET", json=payload):
self.assertRaisesWithContent(
diff --git a/lib/lp/code/model/tests/test_gitnamespace.py b/lib/lp/code/model/tests/test_gitnamespace.py
index 3755bbd..5c12dbb 100644
--- a/lib/lp/code/model/tests/test_gitnamespace.py
+++ b/lib/lp/code/model/tests/test_gitnamespace.py
@@ -5,6 +5,7 @@
from __future__ import absolute_import, print_function, unicode_literals
+import six
from zope.component import getUtility
from zope.security.proxy import removeSecurityProxy
@@ -1117,7 +1118,7 @@ class BaseValidateNewRepositoryMixin:
# The first character of a repository name must be a letter or a
# number.
namespace = self._getNamespace(self.factory.makePerson())
- for c in [unichr(i) for i in range(128)]:
+ for c in [six.unichr(i) for i in range(128)]:
if c.isalnum():
namespace.validateRepositoryName(c)
else:
@@ -1129,7 +1130,7 @@ class BaseValidateNewRepositoryMixin:
# After the first character, letters, numbers and certain
# punctuation is permitted.
namespace = self._getNamespace(self.factory.makePerson())
- for c in [unichr(i) for i in range(128)]:
+ for c in [six.unichr(i) for i in range(128)]:
if c.isalnum() or c in "+-_@.":
namespace.validateRepositoryName("a" + c)
else: