convert %-formatted strings with args in logging.* calls to f-strings

pull/86/head
Ryan Barrett 2021-12-27 22:45:57 -08:00
rodzic fcb7c366ba
commit 2f28be09be
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
6 zmienionych plików z 18 dodań i 23 usunięć

Wyświetl plik

@ -49,8 +49,7 @@ def send(activity, inbox_url, user_domain):
Returns:
requests.Response
"""
logging.info('Sending AP request from %s: %s', user_domain,
json_dumps(activity, indent=2))
logging.info('Sending AP request from {user_domain}: {json_dumps(activity, indent=2)}')
# prepare HTTP Signature (required by Mastodon)
# https://w3c.github.io/activitypub/#authorization
@ -86,15 +85,12 @@ def actor(domain):
if tld in common.TLD_BLOCKLIST:
error('', status=404)
mf2 = util.fetch_mf2('http://%s/' % domain, gateway=True,
headers=common.HEADERS)
# logging.info('Parsed mf2 for %s: %s', resp.url, json_dumps(mf2, indent=2))
mf2 = util.fetch_mf2(f'http://{domain}/', gateway=True, headers=common.HEADERS)
hcard = mf2util.representative_hcard(mf2, mf2['url'])
logging.info('Representative h-card: %s', json_dumps(hcard, indent=2))
logging.info(f'Representative h-card: {json_dumps(hcard, indent=2)}')
if not hcard:
error("""\
Coul find a representative h-card (http://microformats.org/wiki/representative-hcard-parsing) on %s""" % mf2['url'])
error(f"Couldn't find a representative h-card (http://microformats.org/wiki/representative-hcard-parsing) on {mf2['url']}")
key = MagicKey.get_or_create(domain)
obj = common.postprocess_as2(
@ -106,7 +102,7 @@ Coul find a representative h-card (http://microformats.org/wiki/representative-h
'following': f'{request.host_url}{domain}/following',
'followers': f'{request.host_url}{domain}/followers',
})
logging.info('Returning: %s', json_dumps(obj, indent=2))
logging.info(f'Returning: {json_dumps(obj, indent=2)}')
return (obj, {
'Content-Type': common.CONTENT_TYPE_AS2,
@ -248,10 +244,10 @@ def undo_follow(undo_unwrapped):
user_domain = util.domain_from_link(followee)
follower_obj = Follower.get_by_id(Follower._id(user_domain, follower))
if follower_obj:
logging.info('Marking %s as inactive' % follower_obj.key)
logging.info(f'Marking {follower_obj.key} as inactive')
follower_obj.status = 'inactive'
follower_obj.put()
else:
logging.warning('No Follower found for %s %s', user_domain, follower)
logging.warning(f'No Follower found for {user_domain} {follower}')
# TODO send webmention with 410 of u-follow

Wyświetl plik

@ -78,7 +78,7 @@ def _requests_fn(fn, url, parse_json=False, **kwargs):
kwargs.setdefault('headers', {}).update(HEADERS)
resp = fn(url, gateway=True, **kwargs)
logging.info('Got %s headers:%s', resp.status_code, resp.headers)
logging.info(f'Got {resp.status_code} headers: {resp.headers}')
type = content_type(resp)
if (type and type != 'text/html' and
(type.startswith('text/') or type.endswith('+json') or type.endswith('/json'))):
@ -192,8 +192,7 @@ def send_webmentions(activity_wrapped, proxy=None, **response_props):
errors = [] # stores (code, body) tuples
for target in targets:
if util.domain_from_link(target) == util.domain_from_link(source):
logging.info('Skipping same-domain webmention from %s to %s',
source, target)
logging.info(f'Skipping same-domain webmention from {source} to {target}')
continue
response = Response(source=source, target=target, direction='in',
@ -202,7 +201,7 @@ def send_webmentions(activity_wrapped, proxy=None, **response_props):
wm_source = (response.proxy_url()
if verb in ('follow', 'like', 'share') or proxy
else source)
logging.info('Sending webmention from %s to %s', wm_source, target)
logging.info(f'Sending webmention from {wm_source} to {target}')
try:
endpoint = webmention.discover(target, headers=HEADERS).endpoint

Wyświetl plik

@ -87,12 +87,12 @@ class Response(StringIdModel):
if source and target:
assert 'id' not in kwargs
kwargs['id'] = self._id(source, target)
logging.info('Response id (source target): %s', kwargs['id'])
logging.info(f"Response id (source target): {kwargs['id']}")
super(Response, self).__init__(**kwargs)
@classmethod
def get_or_create(cls, source=None, target=None, **kwargs):
logging.info('Response source target: %s %s', source, target)
logging.info(f'Response source target: {source} {target}')
return cls.get_or_insert(cls._id(source, target), **kwargs)
def source(self):
@ -149,6 +149,6 @@ class Follower(StringIdModel):
@classmethod
def get_or_create(cls, user_domain, follower_id, **kwargs):
logging.info('new Follower for %s %s', user_domain, follower_id)
logging.info(f'new Follower for {user_domain} {follower_id}')
return cls.get_or_insert(cls._id(user_domain, follower_id), **kwargs)

Wyświetl plik

@ -62,7 +62,7 @@ def redir(to):
return convert_to_as2(to)
# redirect
logging.info('redirecting to %s', to)
logging.info(f'redirecting to {to}')
return redirect(to, code=301)
@ -74,10 +74,10 @@ def convert_to_as2(url):
"""
mf2 = util.fetch_mf2(url)
entry = mf2util.find_first_entry(mf2, ['h-entry'])
logging.info('Parsed mf2 for %s: %s', mf2['url'], json_dumps(entry, indent=2))
logging.info(f"Parsed mf2 for {mf2['url']}: {json_dumps(entry, indent=2)}")
obj = common.postprocess_as2(as2.from_as1(microformats2.json_to_object(entry)))
logging.info('Returning: %s', json_dumps(obj, indent=2))
logging.info(f'Returning: {json_dumps(obj, indent=2)}')
return obj, {
'Content-Type': common.CONTENT_TYPE_AS2,

Wyświetl plik

@ -48,7 +48,7 @@ class User(flask_util.XrdOrJrd):
resp = common.requests_get(candidate)
parsed = util.parse_html(resp)
mf2 = util.parse_mf2(parsed, url=resp.url)
# logging.debug('Parsed mf2 for %s: %s', resp.url, json_dumps(mf2, indent=2))
# logging.debug(f'Parsed mf2 for {resp.url}: {json_dumps(mf2, indent=2)}')
hcard = mf2util.representative_hcard(mf2, resp.url)
if hcard:
logging.info(f'Representative h-card: {json_dumps(hcard, indent=2)}')

Wyświetl plik

@ -48,7 +48,7 @@ class Webmention(View):
self.source_domain = urllib.parse.urlparse(self.source_url).netloc.split(':')[0]
self.source_mf2 = util.parse_mf2(source_resp)
# logging.debug('Parsed mf2 for %s: %s', source_resp.url, json_dumps(self.source_mf2 indent=2))
# logging.debug(f'Parsed mf2 for {source_resp.url} : {json_dumps(self.source_mf2 indent=2)}')
# check for backlink to bridgy fed (for webmention spec and to confirm
# source's intent to federate to mastodon)