Fediverse: Fix compatibility with Python 3.4 and 3.5.

This commit is contained in:
Valentin Lorentz 2020-05-10 11:20:39 +02:00
parent 27219409b4
commit 7511984a60
3 changed files with 9 additions and 11 deletions

View File

@ -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())

View File

@ -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 "<Could not fetch status: %s>" % 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(

View File

@ -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",