From 2655aa8fa59f1d080cad562bc993995e2b01c940 Mon Sep 17 00:00:00 2001 From: Thomas Sileo Date: Sat, 13 Apr 2019 10:00:56 +0200 Subject: [PATCH] Reformat the files with black --- .drone.yml | 2 +- activitypub.py | 4 ++-- app.py | 19 ++++++++++++++++--- config.py | 5 ++++- tests/federation_test.py | 14 ++++---------- utils/lookup.py | 2 +- utils/media.py | 2 +- utils/opengraph.py | 2 +- 8 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.drone.yml b/.drone.yml index 179e930..f6d7aa3 100644 --- a/.drone.yml +++ b/.drone.yml @@ -9,7 +9,7 @@ steps: commands: - pip install -U pip - pip install mypy flake8 black - # - black --check . + - black --check . - flake8 activitypub.py - mypy --ignore-missing-imports . diff --git a/activitypub.py b/activitypub.py index 4f7104a..db5a977 100644 --- a/activitypub.py +++ b/activitypub.py @@ -58,7 +58,7 @@ def _remove_id(doc: ap.ObjectType) -> ap.ObjectType: """Helper for removing MongoDB's `_id` field.""" doc = doc.copy() if "_id" in doc: - del (doc["_id"]) + del doc["_id"] return doc @@ -425,7 +425,7 @@ class MicroblogPubBackend(Backend): update["$set"][f"{update_prefix}{k}"] = v if len(update["$unset"]) == 0: - del (update["$unset"]) + del update["$unset"] print(f"updating note from outbox {obj!r} {update}") logger.info(f"updating note from outbox {obj!r} {update}") diff --git a/app.py b/app.py index d90502c..f732202 100644 --- a/app.py +++ b/app.py @@ -850,7 +850,11 @@ def _build_thread(data, include_children=True): # noqa: C901 replies.append(dat) else: # Make a Note/Question/... looks like a Create - dat = {"activity": {"object": dat["activity"]}, "meta": dat["meta"], "_id": dat["_id"]} + dat = { + "activity": {"object": dat["activity"]}, + "meta": dat["meta"], + "_id": dat["_id"], + } replies.append(dat) replies = sorted(replies, key=lambda d: d["activity"]["object"]["published"]) @@ -1341,7 +1345,10 @@ def admin_lookup(): @login_required def admin_thread(): data = DB.activities.find_one( - {"type": ActivityType.CREATE.value, "activity.object.id": request.args.get("oid")} + { + "type": ActivityType.CREATE.value, + "activity.object.id": request.args.get("oid"), + } ) if not data: @@ -1385,7 +1392,13 @@ def admin_new(): content = f"@{actor.preferredUsername}@{domain} " thread = _build_thread(data) - return render_template("new.html", reply=reply_id, content=content, thread=thread, emojis=EMOJIS.split(" ")) + return render_template( + "new.html", + reply=reply_id, + content=content, + thread=thread, + emojis=EMOJIS.split(" "), + ) @app.route("/admin/notifications") diff --git a/config.py b/config.py index c3967d0..7b6d6ea 100644 --- a/config.py +++ b/config.py @@ -108,7 +108,10 @@ def create_indexes(): DB.activities.create_index([("activity.object.id", pymongo.ASCENDING)]) DB.activities.create_index([("meta.thread_root_parent", pymongo.ASCENDING)]) DB.activities.create_index( - [("meta.thread_root_parent", pymongo.ASCENDING), ("meta.deleted", pymongo.ASCENDING)] + [ + ("meta.thread_root_parent", pymongo.ASCENDING), + ("meta.deleted", pymongo.ASCENDING), + ] ) DB.activities.create_index( [("activity.object.id", pymongo.ASCENDING), ("meta.deleted", pymongo.ASCENDING)] diff --git a/tests/federation_test.py b/tests/federation_test.py index 6fa34f3..df4499e 100644 --- a/tests/federation_test.py +++ b/tests/federation_test.py @@ -32,15 +32,13 @@ class Instance(object): def _do_req(self, url): """Used to parse collection.""" url = url.replace(self.docker_url, self.host_url) - resp = requests.get(url, headers={'Accept': 'application/activity+json'}) + resp = requests.get(url, headers={"Accept": "application/activity+json"}) resp.raise_for_status() return resp.json() def _parse_collection(self, payload=None, url=None): """Parses a collection (go through all the pages).""" - return parse_collection( - url=url, payload=payload, fetcher=self._do_req, - ) + return parse_collection(url=url, payload=payload, fetcher=self._do_req) def ping(self): """Ensures the homepage is reachable.""" @@ -207,14 +205,10 @@ class Instance(object): def _instances() -> Tuple[Instance, Instance]: """Initializes the client for the two test instances.""" - instance1 = Instance( - "instance1", "http://docker:5006", "http://instance1_web:5005" - ) + instance1 = Instance("instance1", "http://docker:5006", "http://instance1_web:5005") instance1.ping() - instance2 = Instance( - "instance2", "http://docker:5007", "http://instance2_web:5005" - ) + instance2 = Instance("instance2", "http://docker:5007", "http://instance2_web:5005") instance2.ping() # Return the DB diff --git a/utils/lookup.py b/utils/lookup.py index 3e97bfb..4f1e121 100644 --- a/utils/lookup.py +++ b/utils/lookup.py @@ -10,7 +10,7 @@ from little_boxes.webfinger import get_actor_url def lookup(url: str) -> ap.BaseActivity: """Try to find an AP object related to the given URL.""" try: - if url.startswith('@'): + if url.startswith("@"): actor_url = get_actor_url(url) if actor_url: return ap.fetch_remote_activity(actor_url) diff --git a/utils/media.py b/utils/media.py index 06559f7..0dfe44c 100644 --- a/utils/media.py +++ b/utils/media.py @@ -15,7 +15,7 @@ def load(url, user_agent): """Initializes a `PIL.Image` from the URL.""" with requests.get(url, stream=True, headers={"User-Agent": user_agent}) as resp: resp.raise_for_status() - if not resp.headers.get('content-type').startswith('image/'): + if not resp.headers.get("content-type").startswith("image/"): raise ValueError(f"bad content-type {resp.headers.get('content-type')}") resp.raw.decode_content = True diff --git a/utils/opengraph.py b/utils/opengraph.py index df59732..521b645 100644 --- a/utils/opengraph.py +++ b/utils/opengraph.py @@ -48,7 +48,7 @@ def fetch_og_metadata(user_agent, links): logger.debug(f"skipping {l}") continue - r.encoding = 'UTF-8' + r.encoding = "UTF-8" html = r.text try: data = dict(opengraph.OpenGraph(html=html))