Run Black over the whole codebase
This commit is contained in:
parent
cd990e4e2f
commit
2e7d12b3e6
109 changed files with 1539 additions and 1209 deletions
|
@ -2,4 +2,4 @@ from django.apps import AppConfig
|
|||
|
||||
|
||||
class WellKnownsConfig(AppConfig):
|
||||
name = 'wellknowns'
|
||||
name = "wellknowns"
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.core.files.storage import default_storage
|
|||
|
||||
|
||||
class Favicon:
|
||||
def __init__(self, size, rel='icon', mime='image/png'):
|
||||
def __init__(self, size, rel="icon", mime="image/png"):
|
||||
self.rel = rel
|
||||
self.mime = mime
|
||||
if not isinstance(size, tuple):
|
||||
|
@ -12,18 +12,18 @@ class Favicon:
|
|||
|
||||
@property
|
||||
def url(self):
|
||||
return default_storage.url('favicon/' + self.filename)
|
||||
return default_storage.url("favicon/" + self.filename)
|
||||
|
||||
@property
|
||||
def filename(self):
|
||||
return 'favicon-{0}.png'.format(*self.size)
|
||||
return "favicon-{0}.png".format(*self.size)
|
||||
|
||||
@property
|
||||
def sizes(self):
|
||||
return 'x'.join(str(s) for s in self.size)
|
||||
return "x".join(str(s) for s in self.size)
|
||||
|
||||
|
||||
tile_sizes = {'small': 128, 'medium': 270, 'wide': (558, 270), 'large': 558}
|
||||
tile_sizes = {"small": 128, "medium": 270, "wide": (558, 270), "large": 558}
|
||||
|
||||
|
||||
class Tile(Favicon):
|
||||
|
@ -33,13 +33,17 @@ class Tile(Favicon):
|
|||
|
||||
@property
|
||||
def filename(self):
|
||||
return '{0}tile.png'.format(self.size_name)
|
||||
return "{0}tile.png".format(self.size_name)
|
||||
|
||||
|
||||
sizes = (32, 57, 76, 96, 120, 128, 144, 180, 195, 228)
|
||||
icons = tuple(chain(
|
||||
(Favicon(s) for s in sizes),
|
||||
(Tile(s) for s in tile_sizes.keys()),
|
||||
(Favicon(152, rel='apple-touch-icon-precomposed'),
|
||||
Favicon(196, rel='shortcut icon'))
|
||||
))
|
||||
icons = tuple(
|
||||
chain(
|
||||
(Favicon(s) for s in sizes),
|
||||
(Tile(s) for s in tile_sizes.keys()),
|
||||
(
|
||||
Favicon(152, rel="apple-touch-icon-precomposed"),
|
||||
Favicon(196, rel="shortcut icon"),
|
||||
),
|
||||
)
|
||||
)
|
||||
|
|
|
@ -5,22 +5,22 @@ import pytest
|
|||
|
||||
@pytest.mark.django_db
|
||||
def test_host_meta_json(client):
|
||||
res = client.get('/.well-known/host-meta.json')
|
||||
res = client.get("/.well-known/host-meta.json")
|
||||
assert res.status_code == 200
|
||||
assert res['Content-Type'] == 'application/json'
|
||||
assert res["Content-Type"] == "application/json"
|
||||
meta = json.loads(res.content)
|
||||
assert meta.keys() == {'links', 'subject'}
|
||||
assert meta['subject'] == 'https://example.com'
|
||||
assert len(meta['links']) == 13
|
||||
assert meta.keys() == {"links", "subject"}
|
||||
assert meta["subject"] == "https://example.com"
|
||||
assert len(meta["links"]) == 13
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
def test_host_meta_xml(client):
|
||||
res = client.get('/.well-known/host-meta')
|
||||
res = client.get("/.well-known/host-meta")
|
||||
assert res.status_code == 200
|
||||
assert res['Content-Type'] == 'application/xrd+xml'
|
||||
assert res["Content-Type"] == "application/xrd+xml"
|
||||
root = etree.XML(res.content)
|
||||
ns = '{http://docs.oasis-open.org/ns/xri/xrd-1.0}'
|
||||
assert root.tag == (ns + 'XRD')
|
||||
assert root.findtext(ns + 'Subject') == 'https://example.com'
|
||||
assert len(root.findall(ns + 'Link')) == 13
|
||||
ns = "{http://docs.oasis-open.org/ns/xri/xrd-1.0}"
|
||||
assert root.tag == (ns + "XRD")
|
||||
assert root.findtext(ns + "Subject") == "https://example.com"
|
||||
assert len(root.findall(ns + "Link")) == 13
|
||||
|
|
|
@ -2,12 +2,12 @@ from ...views import static
|
|||
|
||||
|
||||
def test_redirect_to_static(rf):
|
||||
res = static.redirect_to_static('abcd')(rf.get('/'))
|
||||
res = static.redirect_to_static("abcd")(rf.get("/"))
|
||||
assert res.status_code == 302
|
||||
assert res.url == '/static/wellknowns/abcd'
|
||||
assert res.url == "/static/wellknowns/abcd"
|
||||
|
||||
|
||||
def test_keybase(rf):
|
||||
res = static.keybase(rf.get('/.well-knowns/keybase.txt'))
|
||||
res = static.keybase(rf.get("/.well-knowns/keybase.txt"))
|
||||
assert res.status_code == 302
|
||||
assert res.url == '/static/wellknowns/keybase.txt'
|
||||
assert res.url == "/static/wellknowns/keybase.txt"
|
||||
|
|
|
@ -2,11 +2,11 @@ from django.urls import path
|
|||
|
||||
from . import views
|
||||
|
||||
app_name = 'wellknowns'
|
||||
app_name = "wellknowns"
|
||||
urlpatterns = [
|
||||
path('keybase.txt', views.keybase, name='keybase'),
|
||||
path('host-meta', views.host_meta_xml, name='host-meta'),
|
||||
path('host-meta.json', views.host_meta_json, name='host-meta.json'),
|
||||
path('manifest.json', views.manifest, name='manifest'),
|
||||
path('webfinger', views.webfinger, name='webfinger'),
|
||||
path("keybase.txt", views.keybase, name="keybase"),
|
||||
path("host-meta", views.host_meta_xml, name="host-meta"),
|
||||
path("host-meta.json", views.host_meta_json, name="host-meta.json"),
|
||||
path("manifest.json", views.manifest, name="manifest"),
|
||||
path("webfinger", views.webfinger, name="webfinger"),
|
||||
]
|
||||
|
|
|
@ -9,58 +9,55 @@ from xrd import XRD, Attribute, Element, Link
|
|||
def add_links(request, dest):
|
||||
base = origin(request)
|
||||
pkg = load_package_json()
|
||||
webfinger = reverse('wellknowns:webfinger') + '?resource={uri}'
|
||||
license = 'https://creativecommons.org/licenses/by-sa/4.0/'
|
||||
webfinger = reverse("wellknowns:webfinger") + "?resource={uri}"
|
||||
license = "https://creativecommons.org/licenses/by-sa/4.0/"
|
||||
|
||||
links = (
|
||||
Link(
|
||||
href=urljoin(base, reverse('entries:atom')),
|
||||
rel='alternate', type_='application/atom+xml',
|
||||
href=urljoin(base, reverse("entries:atom")),
|
||||
rel="alternate",
|
||||
type_="application/atom+xml",
|
||||
),
|
||||
Link(
|
||||
href=urljoin(base, reverse('entries:rss')),
|
||||
rel='alternate', type_='application/rss+xml',
|
||||
href=urljoin(base, reverse("entries:rss")),
|
||||
rel="alternate",
|
||||
type_="application/rss+xml",
|
||||
),
|
||||
Link(
|
||||
href=urljoin(base, reverse('lemonauth:indie')),
|
||||
rel='authorization_endpoint'
|
||||
href=urljoin(base, reverse("lemonauth:indie")), rel="authorization_endpoint"
|
||||
),
|
||||
Link(href=pkg['repository'], type_='text/html', rel='code-repository'),
|
||||
Link(href=settings.PUSH_HUB, rel='hub'),
|
||||
Link(href=license, type_='text/html', rel='license'),
|
||||
Link(href=license+'rdf', type_='application/rdf+xml', rel='license'),
|
||||
Link(href=pkg["repository"], type_="text/html", rel="code-repository"),
|
||||
Link(href=settings.PUSH_HUB, rel="hub"),
|
||||
Link(href=license, type_="text/html", rel="license"),
|
||||
Link(href=license + "rdf", type_="application/rdf+xml", rel="license"),
|
||||
Link(
|
||||
template=urljoin(base, webfinger),
|
||||
type_='application/json', rel='lrdd',
|
||||
type_="application/json",
|
||||
rel="lrdd",
|
||||
),
|
||||
Link(
|
||||
href=urljoin(base, reverse('wellknowns:manifest')),
|
||||
rel='manifest', type_='application/json',
|
||||
href=urljoin(base, reverse("wellknowns:manifest")),
|
||||
rel="manifest",
|
||||
type_="application/json",
|
||||
),
|
||||
Link(
|
||||
href=urljoin(base, reverse('micropub:micropub')),
|
||||
rel='micropub'
|
||||
),
|
||||
Link(
|
||||
href=urljoin(base, reverse('lemonauth:token')),
|
||||
rel='token_endpoint'
|
||||
),
|
||||
Link(href='https://openid.indieauth.com/openid', rel='openid.server'),
|
||||
Link(href=base, rel='openid.delegate'),
|
||||
Link(href=urljoin(base, reverse("micropub:micropub")), rel="micropub"),
|
||||
Link(href=urljoin(base, reverse("lemonauth:token")), rel="token_endpoint"),
|
||||
Link(href="https://openid.indieauth.com/openid", rel="openid.server"),
|
||||
Link(href=base, rel="openid.delegate"),
|
||||
)
|
||||
dest.extend(links)
|
||||
|
||||
|
||||
def host_meta(request):
|
||||
h = XRD(subject='https://' + request.site.domain)
|
||||
h = XRD(subject="https://" + request.site.domain)
|
||||
add_links(request, h.links)
|
||||
return h
|
||||
|
||||
|
||||
def host_meta_xml(request):
|
||||
return HttpResponse(
|
||||
host_meta(request).to_xml().toprettyxml(indent=' ', encoding='utf-8'),
|
||||
content_type='application/xrd+xml',
|
||||
host_meta(request).to_xml().toprettyxml(indent=" ", encoding="utf-8"),
|
||||
content_type="application/xrd+xml",
|
||||
)
|
||||
|
||||
|
||||
|
@ -71,13 +68,15 @@ def host_meta_json(request):
|
|||
links = []
|
||||
for l in meta.links:
|
||||
link = {
|
||||
'rel': l.rel, 'type': l.type,
|
||||
'href': l.href, 'template': l.template,
|
||||
"rel": l.rel,
|
||||
"type": l.type,
|
||||
"href": l.href,
|
||||
"template": l.template,
|
||||
}
|
||||
for k in list(link.keys()):
|
||||
if not link[k]:
|
||||
del link[k]
|
||||
links.append(link)
|
||||
|
||||
meta = {'links': links, 'subject': meta.subject}
|
||||
meta = {"links": links, "subject": meta.subject}
|
||||
return JsonResponse(meta)
|
||||
|
|
|
@ -8,23 +8,24 @@ from textwrap import shorten
|
|||
|
||||
|
||||
def manifest_icons(base):
|
||||
return [{'src': i.url, 'type': i.mime, 'sizes': i.sizes} for i in sorted(icons, key=lambda i: i.size)]
|
||||
return [
|
||||
{"src": i.url, "type": i.mime, "sizes": i.sizes}
|
||||
for i in sorted(icons, key=lambda i: i.size)
|
||||
]
|
||||
|
||||
|
||||
def manifest(request):
|
||||
base = utils.origin(request)
|
||||
start_url = reverse('home:index') + '?utm_source=homescreen'
|
||||
start_url = reverse("home:index") + "?utm_source=homescreen"
|
||||
|
||||
app = {
|
||||
'name': request.site.name,
|
||||
'short_name': shorten(request.site.name, width=20, placeholder=''),
|
||||
'icons': manifest_icons(base),
|
||||
|
||||
'display': 'browser',
|
||||
'start_url': urljoin(base, start_url),
|
||||
|
||||
'background_color': color(0),
|
||||
'theme_color': color(3),
|
||||
"name": request.site.name,
|
||||
"short_name": shorten(request.site.name, width=20, placeholder=""),
|
||||
"icons": manifest_icons(base),
|
||||
"display": "browser",
|
||||
"start_url": urljoin(base, start_url),
|
||||
"background_color": color(0),
|
||||
"theme_color": color(3),
|
||||
}
|
||||
|
||||
return JsonResponse(app, content_type='application/manifest+json')
|
||||
return JsonResponse(app, content_type="application/manifest+json")
|
||||
|
|
|
@ -3,7 +3,7 @@ from django.templatetags.static import static
|
|||
|
||||
|
||||
def redirect_to_static(file):
|
||||
return RedirectView.as_view(url=static('wellknowns/' + file))
|
||||
return RedirectView.as_view(url=static("wellknowns/" + file))
|
||||
|
||||
|
||||
keybase = redirect_to_static('keybase.txt')
|
||||
keybase = redirect_to_static("keybase.txt")
|
||||
|
|
|
@ -3,9 +3,9 @@ from urllib.parse import urlencode, urlparse
|
|||
|
||||
from users.models import User
|
||||
|
||||
AVATAR = 'http://webfinger.net/rel/avatar'
|
||||
PROFILE_PAGE = 'http://webfinger.net/rel/profile-page'
|
||||
BRIDGY_FED = 'https://fed.brid.gy/.well-known/webfinger'
|
||||
AVATAR = "http://webfinger.net/rel/avatar"
|
||||
PROFILE_PAGE = "http://webfinger.net/rel/profile-page"
|
||||
BRIDGY_FED = "https://fed.brid.gy/.well-known/webfinger"
|
||||
|
||||
|
||||
def https_resource_matching(resource):
|
||||
|
@ -15,10 +15,10 @@ def https_resource_matching(resource):
|
|||
resource, if a user with matching email or XMPP address exists locally.
|
||||
Will throw `User.DoesNotExist` if no such user exists.
|
||||
"""
|
||||
if resource.scheme == 'mailto':
|
||||
query = {'email': resource.path}
|
||||
if resource.scheme == "mailto":
|
||||
query = {"email": resource.path}
|
||||
else:
|
||||
query = {'xmpp': resource.path}
|
||||
query = {"xmpp": resource.path}
|
||||
return User.objects.get(**query).absolute_url
|
||||
|
||||
|
||||
|
@ -41,19 +41,19 @@ def webfinger(request):
|
|||
original resource will be preserved in the redirect - and likely fail to
|
||||
find anything at Bridgy's end either.
|
||||
"""
|
||||
if 'resource' not in request.GET:
|
||||
return HttpResponseBadRequest('resource parameter missing')
|
||||
resource = request.GET['resource']
|
||||
if "resource" not in request.GET:
|
||||
return HttpResponseBadRequest("resource parameter missing")
|
||||
resource = request.GET["resource"]
|
||||
try:
|
||||
res = urlparse(resource)
|
||||
except ValueError:
|
||||
return HttpResponseBadRequest('resource parameter malformed')
|
||||
return HttpResponseBadRequest("resource parameter malformed")
|
||||
|
||||
if res.scheme in ('mailto', 'xmpp'):
|
||||
if res.scheme in ("mailto", "xmpp"):
|
||||
try:
|
||||
resource = https_resource_matching(res)
|
||||
except User.DoesNotExist:
|
||||
pass
|
||||
|
||||
query = urlencode({'resource': resource})
|
||||
return HttpResponseRedirect(BRIDGY_FED + '?' + query)
|
||||
query = urlencode({"resource": resource})
|
||||
return HttpResponseRedirect(BRIDGY_FED + "?" + query)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue