forked from forks/microblog.pub
Reformat the files with black
This commit is contained in:
parent
3d74c5ff7e
commit
2655aa8fa5
8 changed files with 30 additions and 20 deletions
|
@ -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 .
|
||||
|
||||
|
|
|
@ -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}")
|
||||
|
|
19
app.py
19
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")
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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))
|
||||
|
|
Loading…
Reference in a new issue