launchpad-reviewers team mailing list archive
-
launchpad-reviewers team
-
Mailing list archive
-
Message #26499
[Merge] ~cjwatson/launchpad:py3-oci-registry-client into launchpad:master
Colin Watson has proposed merging ~cjwatson/launchpad:py3-oci-registry-client into launchpad:master.
Commit message:
OCIRegistryClient: Fix bytes/text handling of JSON
Requested reviews:
Launchpad code reviewers (launchpad-reviewers)
For more details, see:
https://code.launchpad.net/~cjwatson/launchpad/+git/launchpad/+merge/398976
On Python 3, `json.dumps` returns text, and prior to Python 3.6 `json.loads` required text input as well.
--
Your team Launchpad code reviewers is requested to review the proposed merge of ~cjwatson/launchpad:py3-oci-registry-client into launchpad:master.
diff --git a/lib/lp/oci/model/ociregistryclient.py b/lib/lp/oci/model/ociregistryclient.py
index e4aa271..3ba3348 100644
--- a/lib/lp/oci/model/ociregistryclient.py
+++ b/lib/lp/oci/model/ociregistryclient.py
@@ -80,7 +80,7 @@ class OCIRegistryClient:
"""Read JSON out of a `LibraryFileAlias`."""
try:
reference.open()
- return json.loads(reference.read())
+ return json.loads(reference.read().decode("UTF-8"))
finally:
reference.close()
@@ -276,7 +276,7 @@ class OCIRegistryClient:
# https://docs.docker.com/registry/spec/manifest-v2-2/#manifest-list
# Specifically the Schema 2 manifest.
digest = None
- data = json.dumps(registry_manifest)
+ data = json.dumps(registry_manifest).encode("UTF-8")
size = len(data)
content_type = registry_manifest.get(
"mediaType",
diff --git a/lib/lp/oci/tests/test_ociregistryclient.py b/lib/lp/oci/tests/test_ociregistryclient.py
index dcb2a8c..dcf71a8 100644
--- a/lib/lp/oci/tests/test_ociregistryclient.py
+++ b/lib/lp/oci/tests/test_ociregistryclient.py
@@ -285,7 +285,7 @@ class TestOCIRegistryClient(OCIConfigHelperMixin, SpyProxyCallsMixin,
self.client.upload(self.build)
- request = json.loads(responses.calls[1].request.body)
+ request = json.loads(responses.calls[1].request.body.decode("UTF-8"))
self.assertThat(request, MatchesDict({
"layers": MatchesListwise([