From 1c41b6dca43caf6e562c0a892e35af6060516cb2 Mon Sep 17 00:00:00 2001 From: Reid 'arrdem' McKenzie Date: Sun, 20 Nov 2022 22:39:44 -0700 Subject: [PATCH] Fmt --- .../src/python/relay/__main__.py | 18 +++++++--------- .../src/python/relay/application.py | 12 ++++++----- .../src/python/relay/config.py | 1 - .../src/python/relay/database.py | 2 +- .../src/python/relay/http_debug.py | 6 +++--- .../src/python/relay/misc.py | 21 +++++++++++-------- .../src/python/relay/processors.py | 5 ++--- .../src/python/relay/views.py | 14 ++++++++----- 8 files changed, 42 insertions(+), 37 deletions(-) diff --git a/projects/activitypub_relay/src/python/relay/__main__.py b/projects/activitypub_relay/src/python/relay/__main__.py index 745e22c..0ea2655 100644 --- a/projects/activitypub_relay/src/python/relay/__main__.py +++ b/projects/activitypub_relay/src/python/relay/__main__.py @@ -1,14 +1,16 @@ -import Crypto import asyncio -import click -import platform import logging import os - +import platform from urllib.parse import urlparse -from relay import misc, __version__ -from relay.application import Application, request_id_middleware +import Crypto +import click +from relay import __version__, misc +from relay.application import ( + Application, + request_id_middleware, +) from relay.config import relay_software_names @@ -39,7 +41,6 @@ def cli(ctx, config): @click.pass_obj def cli_inbox(ctx: Application): "Manage the inboxes in the database" - pass @cli_inbox.command("list") @@ -161,7 +162,6 @@ def cli_inbox_remove(obj: Application, inbox): @cli.group("instance") def cli_instance(): "Manage instance bans" - pass @cli_instance.command("list") @@ -214,7 +214,6 @@ def cli_instance_unban(obj: Application, target): @cli.group("software") def cli_software(): "Manage banned software" - pass @cli_software.command("list") @@ -301,7 +300,6 @@ def cli_software_unban(obj: Application, name, fetch_nodeinfo): @cli.group("whitelist") def cli_whitelist(): "Manage the instance whitelist" - pass @cli_whitelist.command("list") diff --git a/projects/activitypub_relay/src/python/relay/application.py b/projects/activitypub_relay/src/python/relay/application.py index d8e99fc..5085df9 100644 --- a/projects/activitypub_relay/src/python/relay/application.py +++ b/projects/activitypub_relay/src/python/relay/application.py @@ -1,19 +1,21 @@ import asyncio +from datetime import datetime, timedelta import logging import os import signal +from uuid import uuid4 from aiohttp import web from cachetools import LRUCache -from datetime import datetime, timedelta - from relay.config import RelayConfig from relay.database import RelayDatabase -from relay.misc import DotDict, check_open_port, set_app +from relay.misc import ( + check_open_port, + DotDict, + set_app, +) from relay.views import routes -from uuid import uuid4 - class Application(web.Application): def __init__(self, cfgpath, middlewares=None): diff --git a/projects/activitypub_relay/src/python/relay/config.py b/projects/activitypub_relay/src/python/relay/config.py index d810965..7726589 100644 --- a/projects/activitypub_relay/src/python/relay/config.py +++ b/projects/activitypub_relay/src/python/relay/config.py @@ -2,7 +2,6 @@ from pathlib import Path from urllib.parse import urlparse from relay.misc import DotDict - import yaml diff --git a/projects/activitypub_relay/src/python/relay/database.py b/projects/activitypub_relay/src/python/relay/database.py index 94d945f..df42c61 100644 --- a/projects/activitypub_relay/src/python/relay/database.py +++ b/projects/activitypub_relay/src/python/relay/database.py @@ -1,8 +1,8 @@ import json import logging +from urllib.parse import urlparse from Crypto.PublicKey import RSA -from urllib.parse import urlparse class RelayDatabase(dict): diff --git a/projects/activitypub_relay/src/python/relay/http_debug.py b/projects/activitypub_relay/src/python/relay/http_debug.py index 17a71dd..42ddb38 100644 --- a/projects/activitypub_relay/src/python/relay/http_debug.py +++ b/projects/activitypub_relay/src/python/relay/http_debug.py @@ -1,7 +1,7 @@ -import logging -import aiohttp - from collections import defaultdict +import logging + +import aiohttp STATS = { diff --git a/projects/activitypub_relay/src/python/relay/misc.py b/projects/activitypub_relay/src/python/relay/misc.py index b371c79..8c43a3b 100644 --- a/projects/activitypub_relay/src/python/relay/misc.py +++ b/projects/activitypub_relay/src/python/relay/misc.py @@ -1,24 +1,27 @@ import base64 +from datetime import datetime import json +from json.decoder import JSONDecodeError import logging import socket +from urllib.parse import urlparse import uuid -from random import randint from Crypto.Hash import SHA, SHA256, SHA512 from Crypto.PublicKey import RSA from Crypto.Signature import PKCS1_v1_5 from aiohttp import ClientSession -from aiohttp.client_exceptions import ClientResponseError, ClientConnectorError +from aiohttp.client_exceptions import ( + ClientConnectorError, + ClientResponseError, +) from aiohttp.hdrs import METH_ALL as METHODS -from aiohttp.web import Response as AiohttpResponse, View as AiohttpView -from datetime import datetime -from json.decoder import JSONDecodeError -from urllib.parse import urlparse +from aiohttp.web import ( + Response as AiohttpResponse, + View as AiohttpView, +) from async_lru import alru_cache - from relay.http_debug import http_debug - from retry import retry @@ -339,7 +342,7 @@ class DotDict(dict): # misc properties @property def domain(self): - return urlparse(getattr(self, 'id', None) or getattr(self, 'actor')).hostname + return urlparse(getattr(self, "id", None) or getattr(self, "actor")).hostname # actor properties @property diff --git a/projects/activitypub_relay/src/python/relay/processors.py b/projects/activitypub_relay/src/python/relay/processors.py index 1191cb2..741c813 100644 --- a/projects/activitypub_relay/src/python/relay/processors.py +++ b/projects/activitypub_relay/src/python/relay/processors.py @@ -1,5 +1,4 @@ import asyncio -import json import logging from relay import misc @@ -105,11 +104,11 @@ async def run_processor(request, actor, data, software): return logging.info(f'{request.id}: New "{data.type}" from actor: {actor.id}') - logging.debug(f'{request.id}: {data!r}') + logging.debug(f"{request.id}: {data!r}") env = dict(data=data, actor=actor, software=software) try: return await processors.get(data.type, handle_dont)(request, actor, data, software) except: - logging.exception(f'{request.id}] {env!r}') + logging.exception(f"{request.id}] {env!r}") diff --git a/projects/activitypub_relay/src/python/relay/views.py b/projects/activitypub_relay/src/python/relay/views.py index cf602ad..8352209 100644 --- a/projects/activitypub_relay/src/python/relay/views.py +++ b/projects/activitypub_relay/src/python/relay/views.py @@ -1,12 +1,16 @@ -import json import logging +from aiohttp.web import HTTPUnauthorized from relay import __version__, misc from relay.http_debug import STATS -from relay.misc import DotDict, Message, Response, WKNodeinfo +from relay.misc import ( + DotDict, + Message, + Response, + WKNodeinfo, +) from relay.processors import run_processor -from aiohttp.web import HTTPUnauthorized routes = [] @@ -91,7 +95,7 @@ async def inbox(request): # This PROBABLY means we can do without this data ever ... but here it is. # Trying to deal with actors/visibility - if isinstance(data.object, dict) and not data.object.get('discoverable', True): + if isinstance(data.object, dict) and not data.object.get("discoverable", True): actor = DotDict({"id": "dummy-for-undiscoverable-object"}) # Normal path of looking up the actor... @@ -100,7 +104,7 @@ async def inbox(request): # FIXME: Needs a cache actor = await misc.request(data.actorid) except: - logging.exception(f'{request.id}: {data!r}') + logging.exception(f"{request.id}: {data!r}") return logging.debug(f"Inbox >> {data!r}")