Merge ~cjwatson/launchpad:py3-oci-registry-client into launchpad:master

Proposed by Colin Watson
Status: Merged
Approved by: Colin Watson
Approved revision: 4d4d108cdf80208605c7b942b1b4531a345fdb71
Merge reported by: Otto Co-Pilot
Merged at revision: not available
Proposed branch: ~cjwatson/launchpad:py3-oci-registry-client
Merge into: launchpad:master
Diff against target: 35 lines (+3/-3)
2 files modified
lib/lp/oci/model/ociregistryclient.py (+2/-2)
lib/lp/oci/tests/test_ociregistryclient.py (+1/-1)
Reviewer Review Type Date Requested Status
Cristian Gonzalez (community) Approve
Review via email: mp+398976@code.launchpad.net

Commit message

OCIRegistryClient: Fix bytes/text handling of JSON

Description of the change

On Python 3, `json.dumps` returns text, and prior to Python 3.6 `json.loads` required text input as well.

To post a comment you must log in.
Revision history for this message
Cristian Gonzalez (cristiangsp) wrote :

Looks good!

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/lib/lp/oci/model/ociregistryclient.py b/lib/lp/oci/model/ociregistryclient.py
2index e4aa271..3ba3348 100644
3--- a/lib/lp/oci/model/ociregistryclient.py
4+++ b/lib/lp/oci/model/ociregistryclient.py
5@@ -80,7 +80,7 @@ class OCIRegistryClient:
6 """Read JSON out of a `LibraryFileAlias`."""
7 try:
8 reference.open()
9- return json.loads(reference.read())
10+ return json.loads(reference.read().decode("UTF-8"))
11 finally:
12 reference.close()
13
14@@ -276,7 +276,7 @@ class OCIRegistryClient:
15 # https://docs.docker.com/registry/spec/manifest-v2-2/#manifest-list
16 # Specifically the Schema 2 manifest.
17 digest = None
18- data = json.dumps(registry_manifest)
19+ data = json.dumps(registry_manifest).encode("UTF-8")
20 size = len(data)
21 content_type = registry_manifest.get(
22 "mediaType",
23diff --git a/lib/lp/oci/tests/test_ociregistryclient.py b/lib/lp/oci/tests/test_ociregistryclient.py
24index dcb2a8c..dcf71a8 100644
25--- a/lib/lp/oci/tests/test_ociregistryclient.py
26+++ b/lib/lp/oci/tests/test_ociregistryclient.py
27@@ -285,7 +285,7 @@ class TestOCIRegistryClient(OCIConfigHelperMixin, SpyProxyCallsMixin,
28
29 self.client.upload(self.build)
30
31- request = json.loads(responses.calls[1].request.body)
32+ request = json.loads(responses.calls[1].request.body.decode("UTF-8"))
33
34 self.assertThat(request, MatchesDict({
35 "layers": MatchesListwise([

Subscribers

People subscribed via source and target branches

to status/vote changes: