From 22e25ac454b52686685d4d9f1241416cd35fafda Mon Sep 17 00:00:00 2001 From: Paolo Melchiorre Date: Mon, 5 Dec 2022 22:44:50 +0100 Subject: Add django-upgrade to pre-commit (#114) --- .pre-commit-config.yaml | 6 ++++++ activities/views/posts.py | 2 +- core/signatures.py | 12 ++++++------ takahe/settings.py | 2 +- users/shortcuts.py | 4 ++-- users/views/activitypub.py | 2 +- users/views/identity.py | 2 +- 7 files changed, 18 insertions(+), 12 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index abc8050..d31e946 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -20,6 +20,12 @@ repos: - id: pyupgrade 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 rev: 22.10.0 hooks: diff --git a/activities/views/posts.py b/activities/views/posts.py index 60873a7..65b324a 100644 --- a/activities/views/posts.py +++ b/activities/views/posts.py @@ -21,7 +21,7 @@ class Individual(TemplateView): self.identity = by_handle_or_404(self.request, handle, local=False) 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 - accept = request.META.get("HTTP_ACCEPT", "text/html").lower() + accept = request.headers.get("accept", "text/html").lower() if ( "application/json" in accept or "application/ld" in accept diff --git a/core/signatures.py b/core/signatures.py index 640483a..d0443c3 100644 --- a/core/signatures.py +++ b/core/signatures.py @@ -142,19 +142,19 @@ class HttpSignature: Verifies that the request has a valid signature for its body """ # Verify body digest - if "HTTP_DIGEST" in request.META: + if "digest" in request.headers: 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") # Verify date header - if "HTTP_DATE" in request.META and not skip_date: - header_date = parse_http_date(request.META["HTTP_DATE"]) + if "date" in request.headers and not skip_date: + header_date = parse_http_date(request.headers["date"]) if abs(timezone.now().timestamp() - header_date) > 60: raise VerificationFormatError("Date is too far away") # Get the signature details - if "HTTP_SIGNATURE" not in request.META: + if "signature" not in request.headers: 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 if signature_details["algorithm"] != "rsa-sha256": raise VerificationFormatError("Unknown signature algorithm") diff --git a/takahe/settings.py b/takahe/settings.py index 9769e98..d46ec73 100644 --- a/takahe/settings.py +++ b/takahe/settings.py @@ -210,7 +210,7 @@ if SETUP.DATABASE_SERVER: else: DATABASES = { "default": { - "ENGINE": "django.db.backends.postgresql_psycopg2", + "ENGINE": "django.db.backends.postgresql", "HOST": SETUP.PGHOST, "PORT": SETUP.PGPORT, "NAME": SETUP.PGNAME, diff --git a/users/shortcuts.py b/users/shortcuts.py index 0726218..8377a7f 100644 --- a/users/shortcuts.py +++ b/users/shortcuts.py @@ -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. """ if "@" not in handle: - if "HTTP_HOST" not in request.META: + if "host" not in request.headers: raise Http404("No hostname available") username = handle - domain_instance = Domain.get_domain(request.META["HTTP_HOST"]) + domain_instance = Domain.get_domain(request.headers["host"]) if domain_instance is None: raise Http404("No matching domains found") domain = domain_instance.domain diff --git a/users/views/activitypub.py b/users/views/activitypub.py index c3395a4..b155b08 100644 --- a/users/views/activitypub.py +++ b/users/views/activitypub.py @@ -38,7 +38,7 @@ class HostMeta(View): """ - % request.META["HTTP_HOST"], + % request.headers["host"], content_type="application/xml", ) diff --git a/users/views/identity.py b/users/views/identity.py index d98ce9d..27d2e4e 100644 --- a/users/views/identity.py +++ b/users/views/identity.py @@ -42,7 +42,7 @@ class ViewIdentity(ListView): ): self.identity.transition_perform(IdentityStates.outdated) # 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 ( "application/json" in accept or "application/ld" in accept -- cgit v1.2.3