From f8c9df4aff68e92b47db14dbcebe2ba8980f99c1 Mon Sep 17 00:00:00 2001 From: Hugh Rundle Date: Fri, 20 Jan 2023 18:20:18 +1100 Subject: [PATCH] pylint fixes --- bookwyrm/activitypub/base_activity.py | 13 +++++++------ bookwyrm/signatures.py | 2 +- bookwyrm/tests/activitypub/test_base_activity.py | 1 + 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/bookwyrm/activitypub/base_activity.py b/bookwyrm/activitypub/base_activity.py index e7061a456..6fc600b77 100644 --- a/bookwyrm/activitypub/base_activity.py +++ b/bookwyrm/activitypub/base_activity.py @@ -1,8 +1,8 @@ """ basics for an activitypub serializer """ from dataclasses import dataclass, fields, MISSING from json import JSONEncoder -import requests import logging +import requests from django.apps import apps from django.db import IntegrityError, transaction @@ -251,10 +251,10 @@ def set_related_field( def get_model_from_type(activity_type): """given the activity, what type of model""" - models = apps.get_models() + activity_models = apps.get_models() model = [ m - for m in models + for m in activity_models if hasattr(m, "activity_serializer") and hasattr(m.activity_serializer, "type") and m.activity_serializer.type == activity_type @@ -280,9 +280,9 @@ def resolve_remote_id( # load the data and create the object try: data = get_data(remote_id) - except requests.HTTPError as e: + except ConnectorException as e: if (e.response is not None) and e.response.status_code == 401: - """This most likely means it's a mastodon with secure fetch enabled.""" + # This most likely means it's a mastodon with secure fetch enabled. data = get_activitypub_data(remote_id) else: logger.info("Could not connect to host for remote_id: %s", remote_id) @@ -306,7 +306,8 @@ def resolve_remote_id( def get_representative(): - username = "%s@%s" % (INSTANCE_ACTOR_USERNAME, DOMAIN) + """Get or create an actor representing the entire instance to sign requests to 'secure mastodon' servers""" + username = f"{INSTANCE_ACTOR_USERNAME}@{DOMAIN}" try: user = models.User.objects.get(username=username) except models.User.DoesNotExist: diff --git a/bookwyrm/signatures.py b/bookwyrm/signatures.py index fb0ad49c1..772d39cce 100644 --- a/bookwyrm/signatures.py +++ b/bookwyrm/signatures.py @@ -32,7 +32,7 @@ def make_signature(method, sender, destination, date, digest=None): ] headers = "(request-target) host date" if digest is not None: - signature_headers.append("digest: %s" % digest) + signature_headers.append(f"digest: {digest}") headers = "(request-target) host date digest" message_to_sign = "\n".join(signature_headers) diff --git a/bookwyrm/tests/activitypub/test_base_activity.py b/bookwyrm/tests/activitypub/test_base_activity.py index 56bc142bb..120cd2c91 100644 --- a/bookwyrm/tests/activitypub/test_base_activity.py +++ b/bookwyrm/tests/activitypub/test_base_activity.py @@ -54,6 +54,7 @@ class BaseActivity(TestCase): self.image_data = output.getvalue() def test_get_representative_not_existing(self, *_): + """test that an instance representative actor is created if it does not exist""" representative = get_representative() self.assertIsInstance(representative, models.User)