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
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:
80 """Read JSON out of a `LibraryFileAlias`."""80 """Read JSON out of a `LibraryFileAlias`."""
81 try:81 try:
82 reference.open()82 reference.open()
83 return json.loads(reference.read())83 return json.loads(reference.read().decode("UTF-8"))
84 finally:84 finally:
85 reference.close()85 reference.close()
8686
@@ -276,7 +276,7 @@ class OCIRegistryClient:
276 # https://docs.docker.com/registry/spec/manifest-v2-2/#manifest-list276 # https://docs.docker.com/registry/spec/manifest-v2-2/#manifest-list
277 # Specifically the Schema 2 manifest.277 # Specifically the Schema 2 manifest.
278 digest = None278 digest = None
279 data = json.dumps(registry_manifest)279 data = json.dumps(registry_manifest).encode("UTF-8")
280 size = len(data)280 size = len(data)
281 content_type = registry_manifest.get(281 content_type = registry_manifest.get(
282 "mediaType",282 "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,
285285
286 self.client.upload(self.build)286 self.client.upload(self.build)
287287
288 request = json.loads(responses.calls[1].request.body)288 request = json.loads(responses.calls[1].request.body.decode("UTF-8"))
289289
290 self.assertThat(request, MatchesDict({290 self.assertThat(request, MatchesDict({
291 "layers": MatchesListwise([291 "layers": MatchesListwise([

Subscribers

People subscribed via source and target branches

to status/vote changes: