From 7511984a6000a22169960e419d5fb07bac38eb11 Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sun, 10 May 2020 11:20:39 +0200 Subject: [PATCH] Fediverse: Fix compatibility with Python 3.4 and 3.5. --- plugins/Fediverse/activitypub.py | 4 ++-- plugins/Fediverse/plugin.py | 12 ++++++------ plugins/Fediverse/test.py | 4 +--- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/plugins/Fediverse/activitypub.py b/plugins/Fediverse/activitypub.py index f23b61bfc..fc4d0750b 100644 --- a/plugins/Fediverse/activitypub.py +++ b/plugins/Fediverse/activitypub.py @@ -140,7 +140,7 @@ def webfinger(hostname, uri): ) with convert_exceptions(WebfingerError, "Invalid JSON: ", True): - return json.loads(content) + return json.loads(content.decode()) def get_instance_actor_url(): @@ -241,4 +241,4 @@ def get_actor_from_url(url): assert content is not None with convert_exceptions(ActivityPubProtocolError, "Invalid JSON: ", True): - return json.loads(content) + return json.loads(content.decode()) diff --git a/plugins/Fediverse/plugin.py b/plugins/Fediverse/plugin.py index a3d3ddcc7..4c569dfc6 100644 --- a/plugins/Fediverse/plugin.py +++ b/plugins/Fediverse/plugin.py @@ -183,7 +183,7 @@ class Fediverse(callbacks.PluginRegexp): content = ap.signed_request( status["object"], headers={"Accept": ap.ACTIVITY_MIMETYPE} ) - status = json.loads(content) + status = json.loads(content.decode()) return self._format_status(irc, status) except ap.ActivityPubProtocolError as e: return "" % e.args[0] @@ -239,9 +239,9 @@ class Fediverse(callbacks.PluginRegexp): if "featured" not in actor: irc.reply(_("No featured statuses.")) return - statuses = json.loads(ap.signed_request(actor["featured"])).get( - "orderedItems", [] - ) + statuses = json.loads( + ap.signed_request(actor["featured"]).decode() + ).get("orderedItems", []) if not statuses: irc.reply(_("No featured statuses.")) return @@ -260,11 +260,11 @@ class Fediverse(callbacks.PluginRegexp): actor = self._get_actor(irc, username) if "outbox" not in actor: irc.error(_("No status."), Raise=True) - outbox = json.loads(ap.signed_request(actor["outbox"])) + outbox = json.loads(ap.signed_request(actor["outbox"]).decode()) # Fetches the first page of the outbox. This should be a good-enough # approximation of the number of statuses to show. - statuses = json.loads(ap.signed_request(outbox["first"])).get( + statuses = json.loads(ap.signed_request(outbox["first"]).decode()).get( "orderedItems", [] ) irc.replies( diff --git a/plugins/Fediverse/test.py b/plugins/Fediverse/test.py index 23599d688..8893bd3eb 100644 --- a/plugins/Fediverse/test.py +++ b/plugins/Fediverse/test.py @@ -256,9 +256,7 @@ OUTBOX_FIRSTPAGE_VALUE = { } OUTBOX_FIRSTPAGE_DATA = json.dumps(OUTBOX_FIRSTPAGE_VALUE).encode() -BOOSTED_URL = ( - "https://example.net/users/BoostedUser/statuses/123456" -) +BOOSTED_URL = "https://example.net/users/BoostedUser/statuses/123456" BOOSTED_VALUE = { "@context": [ "https://www.w3.org/ns/activitystreams",