Add django-upgrade to pre-commit (#114)

pull/119/head
Paolo Melchiorre 2022-12-05 22:44:50 +01:00 zatwierdzone przez GitHub
rodzic e3f1039a5f
commit 22e25ac454
Nie znaleziono w bazie danych klucza dla tego podpisu
ID klucza GPG: 4AEE18F83AFDEB23
7 zmienionych plików z 18 dodań i 12 usunięć

Wyświetl plik

@ -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:

Wyświetl plik

@ -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

Wyświetl plik

@ -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")

Wyświetl plik

@ -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,

Wyświetl plik

@ -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

Wyświetl plik

@ -38,7 +38,7 @@ class HostMeta(View):
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
<Link rel="lrdd" template="https://%s/.well-known/webfinger?resource={uri}"/>
</XRD>"""
% request.META["HTTP_HOST"],
% request.headers["host"],
content_type="application/xml",
)

Wyświetl plik

@ -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