mirror of
https://github.com/jointakahe/takahe.git
synced 2025-06-05 10:18:50 +00:00
Add django-upgrade to pre-commit (#114)
This commit is contained in:
parent
e3f1039a5f
commit
22e25ac454
7 changed files with 18 additions and 12 deletions
|
@ -20,6 +20,12 @@ repos:
|
||||||
- id: pyupgrade
|
- id: pyupgrade
|
||||||
args: [--py310-plus]
|
args: [--py310-plus]
|
||||||
|
|
||||||
|
- repo: https://github.com/adamchainz/django-upgrade
|
||||||
|
rev: "1.12.0"
|
||||||
|
hooks:
|
||||||
|
- id: django-upgrade
|
||||||
|
args: [--target-version, "4.1"]
|
||||||
|
|
||||||
- repo: https://github.com/psf/black
|
- repo: https://github.com/psf/black
|
||||||
rev: 22.10.0
|
rev: 22.10.0
|
||||||
hooks:
|
hooks:
|
||||||
|
|
|
@ -21,7 +21,7 @@ class Individual(TemplateView):
|
||||||
self.identity = by_handle_or_404(self.request, handle, local=False)
|
self.identity = by_handle_or_404(self.request, handle, local=False)
|
||||||
self.post_obj = get_object_or_404(self.identity.posts, pk=post_id)
|
self.post_obj = get_object_or_404(self.identity.posts, pk=post_id)
|
||||||
# If they're coming in looking for JSON, they want the actor
|
# If they're coming in looking for JSON, they want the actor
|
||||||
accept = request.META.get("HTTP_ACCEPT", "text/html").lower()
|
accept = request.headers.get("accept", "text/html").lower()
|
||||||
if (
|
if (
|
||||||
"application/json" in accept
|
"application/json" in accept
|
||||||
or "application/ld" in accept
|
or "application/ld" in accept
|
||||||
|
|
|
@ -142,19 +142,19 @@ class HttpSignature:
|
||||||
Verifies that the request has a valid signature for its body
|
Verifies that the request has a valid signature for its body
|
||||||
"""
|
"""
|
||||||
# Verify body digest
|
# Verify body digest
|
||||||
if "HTTP_DIGEST" in request.META:
|
if "digest" in request.headers:
|
||||||
expected_digest = HttpSignature.calculate_digest(request.body)
|
expected_digest = HttpSignature.calculate_digest(request.body)
|
||||||
if request.META["HTTP_DIGEST"] != expected_digest:
|
if request.headers["digest"] != expected_digest:
|
||||||
raise VerificationFormatError("Digest is incorrect")
|
raise VerificationFormatError("Digest is incorrect")
|
||||||
# Verify date header
|
# Verify date header
|
||||||
if "HTTP_DATE" in request.META and not skip_date:
|
if "date" in request.headers and not skip_date:
|
||||||
header_date = parse_http_date(request.META["HTTP_DATE"])
|
header_date = parse_http_date(request.headers["date"])
|
||||||
if abs(timezone.now().timestamp() - header_date) > 60:
|
if abs(timezone.now().timestamp() - header_date) > 60:
|
||||||
raise VerificationFormatError("Date is too far away")
|
raise VerificationFormatError("Date is too far away")
|
||||||
# Get the signature details
|
# Get the signature details
|
||||||
if "HTTP_SIGNATURE" not in request.META:
|
if "signature" not in request.headers:
|
||||||
raise VerificationFormatError("No signature header present")
|
raise VerificationFormatError("No signature header present")
|
||||||
signature_details = cls.parse_signature(request.META["HTTP_SIGNATURE"])
|
signature_details = cls.parse_signature(request.headers["signature"])
|
||||||
# Reject unknown algorithms
|
# Reject unknown algorithms
|
||||||
if signature_details["algorithm"] != "rsa-sha256":
|
if signature_details["algorithm"] != "rsa-sha256":
|
||||||
raise VerificationFormatError("Unknown signature algorithm")
|
raise VerificationFormatError("Unknown signature algorithm")
|
||||||
|
|
|
@ -210,7 +210,7 @@ if SETUP.DATABASE_SERVER:
|
||||||
else:
|
else:
|
||||||
DATABASES = {
|
DATABASES = {
|
||||||
"default": {
|
"default": {
|
||||||
"ENGINE": "django.db.backends.postgresql_psycopg2",
|
"ENGINE": "django.db.backends.postgresql",
|
||||||
"HOST": SETUP.PGHOST,
|
"HOST": SETUP.PGHOST,
|
||||||
"PORT": SETUP.PGPORT,
|
"PORT": SETUP.PGPORT,
|
||||||
"NAME": SETUP.PGNAME,
|
"NAME": SETUP.PGNAME,
|
||||||
|
|
|
@ -9,10 +9,10 @@ def by_handle_or_404(request, handle, local=True, fetch=False) -> Identity:
|
||||||
Domain-sensitive, so it will understand short handles on alternate domains.
|
Domain-sensitive, so it will understand short handles on alternate domains.
|
||||||
"""
|
"""
|
||||||
if "@" not in handle:
|
if "@" not in handle:
|
||||||
if "HTTP_HOST" not in request.META:
|
if "host" not in request.headers:
|
||||||
raise Http404("No hostname available")
|
raise Http404("No hostname available")
|
||||||
username = handle
|
username = handle
|
||||||
domain_instance = Domain.get_domain(request.META["HTTP_HOST"])
|
domain_instance = Domain.get_domain(request.headers["host"])
|
||||||
if domain_instance is None:
|
if domain_instance is None:
|
||||||
raise Http404("No matching domains found")
|
raise Http404("No matching domains found")
|
||||||
domain = domain_instance.domain
|
domain = domain_instance.domain
|
||||||
|
|
|
@ -38,7 +38,7 @@ class HostMeta(View):
|
||||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||||
<Link rel="lrdd" template="https://%s/.well-known/webfinger?resource={uri}"/>
|
<Link rel="lrdd" template="https://%s/.well-known/webfinger?resource={uri}"/>
|
||||||
</XRD>"""
|
</XRD>"""
|
||||||
% request.META["HTTP_HOST"],
|
% request.headers["host"],
|
||||||
content_type="application/xml",
|
content_type="application/xml",
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ class ViewIdentity(ListView):
|
||||||
):
|
):
|
||||||
self.identity.transition_perform(IdentityStates.outdated)
|
self.identity.transition_perform(IdentityStates.outdated)
|
||||||
# If they're coming in looking for JSON, they want the actor
|
# If they're coming in looking for JSON, they want the actor
|
||||||
accept = request.META.get("HTTP_ACCEPT", "text/html").lower()
|
accept = request.headers.get("accept", "text/html").lower()
|
||||||
if (
|
if (
|
||||||
"application/json" in accept
|
"application/json" in accept
|
||||||
or "application/ld" in accept
|
or "application/ld" in accept
|
||||||
|
|
Loading…
Reference in a new issue