diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/htmx.py | 5 | ||||
-rw-r--r-- | core/ld.py | 9 | ||||
-rw-r--r-- | core/signatures.py | 18 |
3 files changed, 14 insertions, 18 deletions
diff --git a/core/htmx.py b/core/htmx.py index c83fba9..a6cf6dd 100644 --- a/core/htmx.py +++ b/core/htmx.py @@ -1,8 +1,5 @@ -from typing import Optional - - class HTMXMixin: - template_name_htmx: Optional[str] = None + template_name_htmx: str | None = None def get_template_name(self): if self.request.htmx and self.template_name_htmx: @@ -1,7 +1,6 @@ import datetime import os import urllib.parse as urllib_parse -from typing import Dict, List, Optional, Union from pyld import jsonld from pyld.jsonld import JsonLdError @@ -396,7 +395,7 @@ def builtin_document_loader(url: str, options={}): ) -def canonicalise(json_data: Dict, include_security: bool = False) -> Dict: +def canonicalise(json_data: dict, include_security: bool = False) -> dict: """ Given an ActivityPub JSON-LD document, round-trips it through the LD systems to end up in a canonicalised, compacted format. @@ -408,7 +407,7 @@ def canonicalise(json_data: Dict, include_security: bool = False) -> Dict: """ if not isinstance(json_data, dict): raise ValueError("Pass decoded JSON data into LDDocument") - context: Union[str, List[str]] + context: str | list[str] if include_security: context = [ "https://www.w3.org/ns/activitystreams", @@ -422,7 +421,7 @@ def canonicalise(json_data: Dict, include_security: bool = False) -> Dict: return jsonld.compact(jsonld.expand(json_data), context) -def get_list(container, key) -> List: +def get_list(container, key) -> list: """ Given a JSON-LD value (that can be either a list, or a dict if it's just one item), always returns a list""" @@ -438,7 +437,7 @@ def format_ld_date(value: datetime.datetime) -> str: return value.strftime(DATETIME_FORMAT) -def parse_ld_date(value: Optional[str]) -> Optional[datetime.datetime]: +def parse_ld_date(value: str | None) -> datetime.datetime | None: if value is None: return None try: diff --git a/core/signatures.py b/core/signatures.py index ead33da..640483a 100644 --- a/core/signatures.py +++ b/core/signatures.py @@ -1,6 +1,6 @@ import base64 import json -from typing import Dict, List, Literal, Optional, Tuple, TypedDict +from typing import Literal, TypedDict from urllib.parse import urlparse import httpx @@ -35,7 +35,7 @@ class VerificationFormatError(VerificationError): class RsaKeys: @classmethod - def generate_keypair(cls) -> Tuple[str, str]: + def generate_keypair(cls) -> tuple[str, str]: """ Generates a new RSA keypair """ @@ -77,7 +77,7 @@ class HttpSignature: raise ValueError(f"Unknown digest algorithm {algorithm}") @classmethod - def headers_from_request(cls, request: HttpRequest, header_names: List[str]) -> str: + def headers_from_request(cls, request: HttpRequest, header_names: list[str]) -> str: """ Creates the to-be-signed header payload from a Django request """ @@ -170,7 +170,7 @@ class HttpSignature: async def signed_request( cls, uri: str, - body: Optional[Dict], + body: dict | None, private_key: str, key_id: str, content_type: str = "application/json", @@ -239,7 +239,7 @@ class HttpSignature: class HttpSignatureDetails(TypedDict): algorithm: str - headers: List[str] + headers: list[str] signature: bytes keyid: str @@ -250,7 +250,7 @@ class LDSignature: """ @classmethod - def verify_signature(cls, document: Dict, public_key: str) -> None: + def verify_signature(cls, document: dict, public_key: str) -> None: """ Verifies a document """ @@ -285,13 +285,13 @@ class LDSignature: @classmethod def create_signature( - cls, document: Dict, private_key: str, key_id: str - ) -> Dict[str, str]: + cls, document: dict, private_key: str, key_id: str + ) -> dict[str, str]: """ Creates the signature for a document """ # Create the options document - options: Dict[str, str] = { + options: dict[str, str] = { "@context": "https://w3id.org/identity/v1", "creator": key_id, "created": format_ld_date(timezone.now()), |