Skip to content

Commit

Permalink
replace print() with app.logger.debug
Browse files Browse the repository at this point in the history
  • Loading branch information
cwt committed Jan 29, 2019
1 parent 96883e8 commit c02b0ae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 28 deletions.
26 changes: 12 additions & 14 deletions activitypub.py
@@ -1,8 +1,8 @@
import logging
import os
import json
from datetime import datetime
from enum import Enum
import json
import logging
import os
from typing import Any
from typing import Dict
from typing import List
Expand All @@ -25,12 +25,11 @@
from config import EXTRA_INBOXES
from config import ID
from config import ME
from config import USER_AGENT
from config import USERNAME
from config import USER_AGENT

logger = logging.getLogger(__name__)


ACTORS_CACHE = LRUCache(maxsize=256)


Expand Down Expand Up @@ -147,7 +146,7 @@ def following(self) -> List[str]:
return [doc["activity"]["object"] for doc in DB.activities.find(q)]

def parse_collection(
self, payload: Optional[Dict[str, Any]] = None, url: Optional[str] = None
self, payload: Optional[Dict[str, Any]]=None, url: Optional[str]=None
) -> List[str]:
"""Resolve/fetch a `Collection`/`OrderedCollection`."""
# Resolve internal collections via MongoDB directly
Expand Down Expand Up @@ -263,7 +262,7 @@ def inbox_undo_like(self, as_actor: ap.Person, like: ap.Like) -> None:
# Update the meta counter if the object is published by the server
DB.activities.update_one(
{"box": Box.OUTBOX.value, "activity.object.id": obj.id},
{"$inc": {"meta.count_like": -1}},
{"$inc": {"meta.count_like":-1}},
)
DB.activities.update_one({"remote_id": like.id}, {"$set": {"meta.undo": True}})

Expand All @@ -280,7 +279,7 @@ def outbox_undo_like(self, as_actor: ap.Person, like: ap.Like) -> None:
obj = like.get_object()
DB.activities.update_one(
{"activity.object.id": obj.id},
{"$inc": {"meta.count_like": -1}, "$set": {"meta.liked": False}},
{"$inc": {"meta.count_like":-1}, "$set": {"meta.liked": False}},
)
DB.activities.update_one({"remote_id": like.id}, {"$set": {"meta.undo": True}})

Expand Down Expand Up @@ -314,7 +313,7 @@ def inbox_undo_announce(self, as_actor: ap.Person, announce: ap.Announce) -> Non
obj = announce.get_object()
# Update the meta counter if the object is published by the server
DB.activities.update_one(
{"activity.object.id": obj.id}, {"$inc": {"meta.count_boost": -1}}
{"activity.object.id": obj.id}, {"$inc": {"meta.count_boost":-1}}
)
DB.activities.update_one(
{"remote_id": announce.id}, {"$set": {"meta.undo": True}}
Expand Down Expand Up @@ -427,7 +426,6 @@ def outbox_update(self, as_actor: ap.Person, _update: ap.Update) -> None:
if len(update["$unset"]) == 0:
del (update["$unset"])

print(f"updating note from outbox {obj!r} {update}")
logger.info(f"updating note from outbox {obj!r} {update}")
DB.activities.update_one({"activity.object.id": obj["id"]}, update)
# FIXME(tsileo): should send an Update (but not a partial one, to all the note's recipients
Expand All @@ -450,7 +448,7 @@ def _handle_replies_delete(

DB.activities.update_one(
{"activity.object.id": in_reply_to},
{"$inc": {"meta.count_reply": -1, "meta.count_direct_reply": -1}},
{"$inc": {"meta.count_reply":-1, "meta.count_direct_reply":-1}},
)

@ensure_it_is_me
Expand Down Expand Up @@ -552,8 +550,8 @@ def json_feed(path: str) -> Dict[str, Any]:
"version": "https://jsonfeed.org/version/1",
"user_comment": (
"This is a microblog feed. You can add this to your feed reader using the following URL: "
+ ID
+ path
+ID
+path
),
"title": USERNAME,
"home_page_url": ID,
Expand All @@ -568,7 +566,7 @@ def json_feed(path: str) -> Dict[str, Any]:


def build_inbox_json_feed(
path: str, request_cursor: Optional[str] = None
path: str, request_cursor: Optional[str]=None
) -> Dict[str, Any]:
"""Build a JSON feed from the inbox activities."""
data = []
Expand Down
24 changes: 12 additions & 12 deletions app.py
Expand Up @@ -334,11 +334,11 @@ def admin_login():
if pwd and verify_pass(pwd):
if devices:
resp = json.loads(request.form.get("resp"))
print(resp)
app.logger.debug(resp)
try:
u2f.complete_authentication(session["challenge"], resp)
except ValueError as exc:
print("failed", exc)
app.logger.debug("failed", exc)
abort(401)
return
finally:
Expand Down Expand Up @@ -555,7 +555,7 @@ def with_replies():

def _build_thread(data, include_children=True):
data["_requested"] = True
print(data)
app.logger.debug(data)
root_id = data["meta"].get("thread_root_parent", data["activity"]["object"]["id"])

query = {
Expand Down Expand Up @@ -833,7 +833,7 @@ def outbox():
abort(401)

data = request.get_json(force=True)
print(data)
app.logger.debug(data)
activity = ap.parse_activity(data)
activity_id = tasks.post_to_outbox(activity)

Expand Down Expand Up @@ -1035,7 +1035,7 @@ def admin_lookup():
actor=data.get_actor().to_dict(),
)

print(data)
app.logger.debug(data)
return render_template(
"lookup.html", data=data, meta=meta, url=request.form.get("url")
)
Expand Down Expand Up @@ -1070,7 +1070,7 @@ def admin_new():
reply_id = None
content = ""
thread = []
print(request.args)
app.logger.debug(request.args)
if request.args.get("reply"):
data = DB.activities.find_one({"activity.object.id": request.args.get("reply")})
if data:
Expand Down Expand Up @@ -1693,7 +1693,7 @@ def get_client_id_data(url):
for item in data["items"]:
if "h-x-app" in item["type"] or "h-app" in item["type"]:
props = item.get("properties", {})
print(props)
app.logger.debug(props)
return dict(
logo=_get_prop(props, "logo"),
name=_get_prop(props, "name"),
Expand All @@ -1716,7 +1716,7 @@ def indieauth_flow():

code = binascii.hexlify(os.urandom(8)).decode("utf-8")
auth.update(code=code, verified=False)
print(auth)
app.logger.debug(auth)
if not auth["redirect_uri"]:
abort(500)

Expand All @@ -1741,7 +1741,7 @@ def indieauth_endpoint():
response_type = request.args.get("response_type", "id")
scope = request.args.get("scope", "").split()

print("STATE", state)
app.logger.debug("STATE", state)
return render_template(
"indieauth_flow.html",
client=get_client_id_data(client_id),
Expand All @@ -1767,8 +1767,8 @@ def indieauth_endpoint():
{"$set": {"verified": True}},
sort=[("_id", pymongo.DESCENDING)],
)
print(auth)
print(code, redirect_uri, client_id)
app.logger.debug(auth)
app.logger.debug(code, redirect_uri, client_id)

if not auth:
abort(403)
Expand All @@ -1778,7 +1778,7 @@ def indieauth_endpoint():
me = auth["me"]
state = auth["state"]
scope = " ".join(auth["scope"])
print("STATE", state)
app.logger.debug("STATE", state)
return build_auth_resp({"me": me, "state": state, "scope": scope})


Expand Down
4 changes: 2 additions & 2 deletions filters.py
Expand Up @@ -167,7 +167,7 @@ def url_or_id(d):

@blueprint.app_template_filter()
def get_url(u):
print(f"GET_URL({u!r})")
current_app.logger.debug(f"GET_URL({u!r})")
if isinstance(u, list):
for l in u:
if l.get("mimeType") == "text/html":
Expand All @@ -188,7 +188,7 @@ def get_actor(url):
url = url[0]
if isinstance(url, dict):
url = url.get("id")
print(f"GET_ACTOR {url}")
current_app.logger.debug(f"GET_ACTOR {url}")
try:
return get_backend().fetch_iri(url)
except (ActivityNotFoundError, ActivityGoneError):
Expand Down

0 comments on commit c02b0ae

Please sign in to comment.