noop: convert a few %s'es to f-strings

thanks flynt! https://github.com/ikamensh/flynt
pull/386/head
Ryan Barrett 2023-01-24 12:17:24 -08:00
rodzic 965554a714
commit bb2d3e03de
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 6BE31FDF4776E9D4
6 zmienionych plików z 17 dodań i 19 usunięć

Wyświetl plik

@ -72,8 +72,7 @@ def inbox(domain=None):
if type == 'Accept': # eg in response to a Follow
return '' # noop
if type not in SUPPORTED_TYPES:
error('Sorry, %s activities are not supported yet.' % type,
status=501)
error(f'Sorry, {type} activities are not supported yet.', status=501)
# TODO: verify signature if there is one
@ -161,12 +160,12 @@ def accept_follow(follow, follow_unwrapped, user):
if isinstance(followee_unwrapped, dict) else followee_unwrapped)
follower = follow.get('actor')
if not followee or not followee_id or not follower:
error('Follow activity requires object and actor. Got: %s' % follow)
error(f'Follow activity requires object and actor. Got: {follow}')
inbox = follower.get('inbox')
follower_id = follower.get('id')
if not inbox or not follower_id:
error('Follow actor requires id and inbox. Got: %s', follower)
error(f'Follow actor requires id and inbox. Got: {follower}')
# rendered mf2 HTML proxy pages (in render.py) fall back to redirecting to
# the follow's AS2 id field, but Mastodon's ids are URLs that don't load in
@ -189,8 +188,8 @@ def accept_follow(follow, follow_unwrapped, user):
# send AP Accept
accept = {
'@context': 'https://www.w3.org/ns/activitystreams',
'id': util.tag_uri(common.PRIMARY_DOMAIN, 'accept/%s/%s' % (
(followee_domain, follow.get('id')))),
'id': util.tag_uri(common.PRIMARY_DOMAIN,
f'accept/{followee_domain}/{follow.get("id")}'),
'type': 'Accept',
'actor': followee,
'object': {
@ -223,7 +222,7 @@ def undo_follow(undo_unwrapped):
if isinstance(followee, dict):
followee = followee.get('id') or util.get_url(followee)
if not follower or not followee:
error('Undo of Follow requires object with actor and object. Got: %s' % follow)
error(f'Undo of Follow requires object with actor and object. Got: {follow}')
# deactivate Follower
user_domain = util.domain_from_link(followee, minimize=False)

Wyświetl plik

@ -198,7 +198,7 @@ def get_as2(url, user=None):
requests_response attribute with the last requests.Response we received.
"""
def _error(resp):
msg = "Couldn't fetch %s as ActivityStreams 2" % url
msg = f"Couldn't fetch {url} as ActivityStreams 2"
logger.warning(msg)
err = BadGateway(msg)
err.requests_response = resp
@ -374,7 +374,7 @@ def postprocess_as2(activity, user=None, target=None, create=True):
if len(in_reply_to) > 1:
logger.warning(
"AS2 doesn't support multiple inReplyTo URLs! "
'Only using the first: %s' % in_reply_to[0])
f'Only using the first: {in_reply_to[0]}')
activity['inReplyTo'] = in_reply_to[0]
# Mastodon evidently requires a Mention tag for replies to generate a

Wyświetl plik

@ -96,8 +96,7 @@ class User(StringIdModel):
return user
def href(self):
return 'data:application/magic-public-key,RSA.%s.%s' % (
self.mod, self.public_exponent)
return f'data:application/magic-public-key,RSA.{self.mod}.{self.public_exponent}'
def public_pem(self):
"""Returns: bytes"""
@ -317,7 +316,7 @@ class Activity(StringIdModel):
def _id(cls, source, target):
assert source
assert target
return '%s %s' % (cls._encode(source), cls._encode(target))
return f'{cls._encode(source)} {cls._encode(target)}'
@classmethod
def _encode(cls, val):
@ -352,7 +351,7 @@ class Follower(StringIdModel):
def _id(cls, dest, src):
assert src
assert dest
return '%s %s' % (dest, src)
return f'{dest} {src}'
@classmethod
def get_or_create(cls, dest, src, **kwargs):

Wyświetl plik

@ -188,8 +188,8 @@ class WebfingerTest(testutil.TestCase):
'foo.com', 'http://foo.com/', 'https://foo.com/',
'http://localhost/foo.com'):
with self.subTest(resource=resource):
url = '/.well-known/webfinger?%s' % urllib.parse.urlencode(
{'resource': resource})
url = (f'/.well-known/webfinger?' +
urllib.parse.urlencode({'resource': resource}))
got = self.client.get(url, headers={'Accept': 'application/json'})
self.assertEqual(200, got.status_code, got.get_data(as_text=True))
self.assertEqual('application/jrd+json', got.headers['Content-Type'])
@ -232,8 +232,8 @@ class WebfingerTest(testutil.TestCase):
'acct:foo.com@localhost',
):
with self.subTest(resource=resource):
url = '/.well-known/webfinger?%s' % urllib.parse.urlencode(
{'resource': resource})
url = (f'/.well-known/webfinger?' +
urllib.parse.urlencode({'resource': resource}))
got = self.client.get(url, headers={'Accept': 'application/json'})
self.assertEqual(200, got.status_code, got.get_data(as_text=True))
self.assertEqual('application/jrd+json', got.headers['Content-Type'])

Wyświetl plik

@ -763,7 +763,7 @@ class WebmentionTest(testutil.TestCase):
self.update_as2 if inbox == 'https://updated/inbox' else self.create_as2,
json_loads(call[1]['data']))
activity = Activity.get_by_id('https://orig/post %s' % inbox)
activity = Activity.get_by_id(f'https://orig/post {inbox}')
self.assertEqual(['orig'], activity.domain)
self.assertEqual('out', activity.direction, inbox)
self.assertEqual('activitypub', activity.protocol, inbox)

Wyświetl plik

@ -25,7 +25,7 @@ class TestCase(unittest.TestCase, testutil.Asserts):
self.client = app.test_client()
# clear datastore
requests.post('http://%s/reset' % ndb_client.host)
requests.post(f'http://{ndb_client.host}/reset')
self.ndb_context = ndb_client.context()
self.ndb_context.__enter__()