Update Black & run for whole repository
This commit is contained in:
parent
68210d5330
commit
850dc69091
53 changed files with 441 additions and 149 deletions
|
|
@ -15,7 +15,8 @@ logger = logging.getLogger(__name__)
|
|||
def get_actor_data(actor_url):
|
||||
logger.debug("Fetching actor %s", actor_url)
|
||||
response = session.get_session().get(
|
||||
actor_url, headers={"Accept": "application/activity+json"},
|
||||
actor_url,
|
||||
headers={"Accept": "application/activity+json"},
|
||||
)
|
||||
response.raise_for_status()
|
||||
try:
|
||||
|
|
|
|||
|
|
@ -53,7 +53,9 @@ class SignatureAuthentication(authentication.BaseAuthentication):
|
|||
actor = actors.get_actor(actor_url)
|
||||
except Exception as e:
|
||||
logger.info(
|
||||
"Discarding HTTP request from actor/domain %s, %s", actor_url, str(e),
|
||||
"Discarding HTTP request from actor/domain %s, %s",
|
||||
actor_url,
|
||||
str(e),
|
||||
)
|
||||
raise rest_exceptions.AuthenticationFailed(
|
||||
"Cannot fetch remote actor to authenticate signature"
|
||||
|
|
|
|||
|
|
@ -128,7 +128,9 @@ class ActorFactory(NoUpdateOnCreate, factory.django.DjangoModelFactory):
|
|||
model = models.Actor
|
||||
|
||||
class Params:
|
||||
with_real_keys = factory.Trait(keys=factory.LazyFunction(keys.get_key_pair),)
|
||||
with_real_keys = factory.Trait(
|
||||
keys=factory.LazyFunction(keys.get_key_pair),
|
||||
)
|
||||
|
||||
@factory.post_generation
|
||||
def local(self, create, extracted, **kwargs):
|
||||
|
|
|
|||
|
|
@ -192,7 +192,9 @@ def prepare_for_serializer(payload, config, fallbacks={}):
|
|||
for a in aliases:
|
||||
try:
|
||||
value = get_value(
|
||||
payload[a["property"]], keep=a.get("keep"), attr=a.get("attr"),
|
||||
payload[a["property"]],
|
||||
keep=a.get("keep"),
|
||||
attr=a.get("attr"),
|
||||
)
|
||||
except (IndexError, KeyError):
|
||||
continue
|
||||
|
|
|
|||
|
|
@ -9,7 +9,9 @@ def get_library_data(library_url, actor):
|
|||
auth = signing.get_auth(actor.private_key, actor.private_key_id)
|
||||
try:
|
||||
response = session.get_session().get(
|
||||
library_url, auth=auth, headers={"Accept": "application/activity+json"},
|
||||
library_url,
|
||||
auth=auth,
|
||||
headers={"Accept": "application/activity+json"},
|
||||
)
|
||||
except requests.ConnectionError:
|
||||
return {"errors": ["This library is not reachable"]}
|
||||
|
|
@ -30,7 +32,9 @@ def get_library_data(library_url, actor):
|
|||
def get_library_page(library, page_url, actor):
|
||||
auth = signing.get_auth(actor.private_key, actor.private_key_id)
|
||||
response = session.get_session().get(
|
||||
page_url, auth=auth, headers={"Accept": "application/activity+json"},
|
||||
page_url,
|
||||
auth=auth,
|
||||
headers={"Accept": "application/activity+json"},
|
||||
)
|
||||
serializer = serializers.CollectionPageSerializer(
|
||||
data=response.json(),
|
||||
|
|
|
|||
|
|
@ -196,7 +196,8 @@ def inbox_create_audio(payload, context):
|
|||
if is_channel:
|
||||
channel = context["actor"].get_channel()
|
||||
serializer = serializers.ChannelCreateUploadSerializer(
|
||||
data=payload, context={"channel": channel},
|
||||
data=payload,
|
||||
context={"channel": channel},
|
||||
)
|
||||
else:
|
||||
serializer = serializers.UploadSerializer(
|
||||
|
|
|
|||
|
|
@ -500,7 +500,10 @@ def create_or_update_channel(actor, rss_url, attributed_to_fid, **validated_data
|
|||
reverse("federation:music:libraries-detail", kwargs={"uuid": uid})
|
||||
)
|
||||
library = attributed_to.libraries.create(
|
||||
privacy_level="everyone", name=artist_defaults["name"], fid=fid, uuid=uid,
|
||||
privacy_level="everyone",
|
||||
name=artist_defaults["name"],
|
||||
fid=fid,
|
||||
uuid=uid,
|
||||
)
|
||||
else:
|
||||
library = artist.channel.library
|
||||
|
|
@ -512,7 +515,9 @@ def create_or_update_channel(actor, rss_url, attributed_to_fid, **validated_data
|
|||
"library": library,
|
||||
}
|
||||
channel, created = audio_models.Channel.objects.update_or_create(
|
||||
actor=actor, attributed_to=attributed_to, defaults=channel_defaults,
|
||||
actor=actor,
|
||||
attributed_to=attributed_to,
|
||||
defaults=channel_defaults,
|
||||
)
|
||||
return channel
|
||||
|
||||
|
|
@ -1734,7 +1739,8 @@ class FlagSerializer(jsonld.JsonLdSerializer):
|
|||
}
|
||||
|
||||
report, created = moderation_models.Report.objects.update_or_create(
|
||||
fid=validated_data["id"], defaults=kwargs,
|
||||
fid=validated_data["id"],
|
||||
defaults=kwargs,
|
||||
)
|
||||
moderation_signals.report_created.send(sender=None, report=report)
|
||||
return report
|
||||
|
|
|
|||
|
|
@ -338,7 +338,9 @@ def fetch(fetch_obj):
|
|||
if not payload:
|
||||
return error("blocked", message="Blocked by MRF")
|
||||
response = session.get_session().get(
|
||||
auth=auth, url=url, headers={"Accept": "application/activity+json"},
|
||||
auth=auth,
|
||||
url=url,
|
||||
headers={"Accept": "application/activity+json"},
|
||||
)
|
||||
logger.debug("Remote answered with %s: %s", response.status_code, response.text)
|
||||
response.raise_for_status()
|
||||
|
|
@ -425,7 +427,9 @@ def fetch(fetch_obj):
|
|||
# first page fetch is synchronous, so that at least some data is available
|
||||
# in the UI after subscription
|
||||
result = fetch_collection(
|
||||
obj.actor.outbox_url, channel_id=obj.pk, max_pages=1,
|
||||
obj.actor.outbox_url,
|
||||
channel_id=obj.pk,
|
||||
max_pages=1,
|
||||
)
|
||||
except Exception:
|
||||
logger.exception(
|
||||
|
|
@ -473,7 +477,8 @@ class PreserveSomeDataCollector(Collector):
|
|||
@celery.app.task(name="federation.remove_actor")
|
||||
@transaction.atomic
|
||||
@celery.require_instance(
|
||||
models.Actor.objects.all(), "actor",
|
||||
models.Actor.objects.all(),
|
||||
"actor",
|
||||
)
|
||||
def remove_actor(actor):
|
||||
# Then we broadcast the info over federation. We do this *before* deleting objects
|
||||
|
|
@ -531,7 +536,9 @@ def match_serializer(payload, conf):
|
|||
|
||||
@celery.app.task(name="federation.fetch_collection")
|
||||
@celery.require_instance(
|
||||
audio_models.Channel.objects.all(), "channel", allow_null=True,
|
||||
audio_models.Channel.objects.all(),
|
||||
"channel",
|
||||
allow_null=True,
|
||||
)
|
||||
def fetch_collection(url, max_pages, channel, is_page=False):
|
||||
actor = actors.get_service_actor()
|
||||
|
|
@ -564,7 +571,11 @@ def fetch_collection(url, max_pages, channel, is_page=False):
|
|||
for i in range(max_pages):
|
||||
page_url = results["next_page"]
|
||||
logger.debug("Handling page %s on max %s, at %s", i + 1, max_pages, page_url)
|
||||
page = utils.retrieve_ap_object(page_url, actor=actor, serializer_class=None,)
|
||||
page = utils.retrieve_ap_object(
|
||||
page_url,
|
||||
actor=actor,
|
||||
serializer_class=None,
|
||||
)
|
||||
try:
|
||||
items = page["orderedItems"]
|
||||
except KeyError:
|
||||
|
|
|
|||
|
|
@ -470,7 +470,8 @@ class IndexViewSet(FederationMixin, viewsets.GenericViewSet):
|
|||
return super().dispatch(request, *args, **kwargs)
|
||||
|
||||
@action(
|
||||
methods=["get"], detail=False,
|
||||
methods=["get"],
|
||||
detail=False,
|
||||
)
|
||||
def libraries(self, request, *args, **kwargs):
|
||||
libraries = (
|
||||
|
|
@ -497,7 +498,8 @@ class IndexViewSet(FederationMixin, viewsets.GenericViewSet):
|
|||
return response.Response({}, status=200)
|
||||
|
||||
@action(
|
||||
methods=["get"], detail=False,
|
||||
methods=["get"],
|
||||
detail=False,
|
||||
)
|
||||
def channels(self, request, *args, **kwargs):
|
||||
actors = (
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue