Skip to content

Commit 1dd0bf1

Browse files
committed
Merge branch 'next' of https://github.com/fedi-libs/apmodel into next
2 parents 39e5f9b + 551d317 commit 1dd0bf1

26 files changed

+92
-126
lines changed

src/apmodel/_core/_initial/_registry_bootstrap.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,4 +60,3 @@
6060
"http://litepub.social/ns#EmojiReact": "apmodel.extra.litepub.emoji_react.EmojiReact",
6161
"http://schema.org#PropertyValue": "apmodel.extra.schema.propertyvalue.PropertyValue",
6262
}
63-

src/apmodel/_core/_jsonjd/loader.py

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,16 +37,15 @@ def get_schema(path: str) -> dict:
3737
return full_data.get("schema", {})
3838

3939

40-
def cached_loader(
41-
requests_loader: Callable[[str, dict], dict], url, options={}
42-
):
40+
def cached_loader(requests_loader: Callable[[str, dict], dict], url, options={}):
4341
if "headers" not in options:
4442
options["headers"] = {}
45-
options["headers"]["Accept"] = (
46-
"application/ld+json;profile=http://www.w3.org/ns/json-ld#context, application/ld+json, application/json;q=0.5, text/html;q=0.8, application/xhtml+xml;q=0.8"
47-
)
43+
options["headers"][
44+
"Accept"
45+
] = "application/ld+json;profile=http://www.w3.org/ns/json-ld#context, application/ld+json, application/json;q=0.5, text/html;q=0.8, application/xhtml+xml;q=0.8"
4846
return requests_loader(url, options)
4947

48+
5049
def create_document_loader(*args, **kwargs):
5150
requests_loader = requests.requests_document_loader(*args, **kwargs)
5251

@@ -67,7 +66,11 @@ def loader(url, options={}):
6766

6867
# Handle instance-specific LitePub contexts for Akkoma, etc.
6968
if parsed_url.path.endswith(
70-
("/contexts/litepub.jsonld", "/litepub.jsonld", "/schemas/litepub-0.1.jsonld")
69+
(
70+
"/contexts/litepub.jsonld",
71+
"/litepub.jsonld",
72+
"/schemas/litepub-0.1.jsonld",
73+
)
7174
):
7275
file_path = os.path.join(_PRELOADS_DIR, "litepub-0.1.jsonld")
7376
if os.path.exists(file_path):

src/apmodel/_core/key.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ def _load_private_key_from_multibase(
1717
elif codec.name == "rsa-priv":
1818
priv_key = serialization.load_der_private_key(data, password=None)
1919
if not isinstance(priv_key, rsa.RSAPrivateKey):
20-
raise ValueError(
21-
f"Unsupported Key Type for rsa-priv: {type(priv_key)}"
22-
)
20+
raise ValueError(f"Unsupported Key Type for rsa-priv: {type(priv_key)}")
2321
return priv_key
2422

2523
else:
@@ -43,9 +41,7 @@ def _load_public_key_from_multibase(
4341
elif codec.name == "rsa-pub":
4442
pub_key = serialization.load_der_public_key(data)
4543
if not isinstance(pub_key, rsa.RSAPublicKey):
46-
raise ValueError(
47-
f"Unsupported Key Type for rsa-pub: {type(pub_key)}"
48-
)
44+
raise ValueError(f"Unsupported Key Type for rsa-pub: {type(pub_key)}")
4945
return pub_key
5046

5147
else:

src/apmodel/_version.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
commit_id: COMMIT_ID
2929
__commit_id__: COMMIT_ID
3030

31-
__version__ = version = '0.4.5.post1.dev37+g1613af455.d20251221'
32-
__version_tuple__ = version_tuple = (0, 4, 5, 'post1', 'dev37', 'g1613af455.d20251221')
31+
__version__ = version = "0.4.5.post1.dev37+g1613af455.d20251221"
32+
__version_tuple__ = version_tuple = (0, 4, 5, "post1", "dev37", "g1613af455.d20251221")
3333

3434
__commit_id__ = commit_id = None

src/apmodel/context.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ def full_context(self) -> List[str | Dict[str, Any]]:
6060
result.append(self.definitions)
6161
return result
6262

63-
@model_validator(mode='before')
63+
@model_validator(mode="before")
6464
@classmethod
6565
def validate_input(cls, value: Any) -> Any:
6666
if isinstance(value, cls):
@@ -71,15 +71,14 @@ def validate_input(cls, value: Any) -> Any:
7171
temp_instance.add(value)
7272
return {
7373
"urls": temp_instance.urls,
74-
"definitions": temp_instance.definitions
74+
"definitions": temp_instance.definitions,
7575
}
7676
return value
7777

7878
@model_serializer
7979
def serialize_model(self) -> List[str | Dict[str, Any]]:
8080
return self.full_context
8181

82-
8382
def __repr__(self) -> str:
8483
return f"LDContext({self.full_context})"
8584

@@ -101,4 +100,4 @@ def __add__(self: LDContextType, other: LDContext) -> LDContextType:
101100
def __iadd__(self: LDContextType, other: LDContext) -> LDContextType:
102101
if isinstance(other, LDContext):
103102
self.add(other.full_context)
104-
return self
103+
return self

src/apmodel/core/activity.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class Activity(Object):
3434
@classmethod
3535
def convert_models(cls, v: Any, info: ValidationInfo) -> Any:
3636
from ..loader import load
37+
3738
if isinstance(v, Object):
3839
return v
3940
if isinstance(v, str):

src/apmodel/core/collection.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,7 @@ class Collection(Object):
1717
first: Optional[str | CollectionPage | Link] = Field(default=None)
1818
last: Optional[str | CollectionPage | Link] = Field(default=None)
1919
items: Optional[List[Object | Link | Dict[str, Any]]] = Field(default=None)
20-
ordered_items: Optional[List[Object | Link | Dict[str, Any]]] = Field(
21-
default=None
22-
)
20+
ordered_items: Optional[List[Object | Link | Dict[str, Any]]] = Field(default=None)
2321

2422
@field_validator("ordered_items")
2523
@classmethod

src/apmodel/core/link.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,7 @@
1212

1313
class Link(ActivityPubModel):
1414
context: LDContext = Field(
15-
default_factory=lambda: LDContext(
16-
["https://www.w3.org/ns/activitystreams"]
17-
),
15+
default_factory=lambda: LDContext(["https://www.w3.org/ns/activitystreams"]),
1816
kw_only=True,
1917
alias="@context",
2018
)
@@ -24,6 +22,4 @@ class Link(ActivityPubModel):
2422
name: Optional[str] = Field(default=None, kw_only=True)
2523
href: Optional[str] = Field(default=None)
2624
hreflang: Optional[str] = Field(default=None)
27-
media_type: Optional[str] = Field(
28-
default=None
29-
)
25+
media_type: Optional[str] = Field(default=None)

src/apmodel/core/object.py

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,7 @@
2222

2323
class Object(ActivityPubModel):
2424
context: LDContext = Field(
25-
default_factory=lambda: LDContext(
26-
["https://www.w3.org/ns/activitystreams"]
27-
),
25+
default_factory=lambda: LDContext(["https://www.w3.org/ns/activitystreams"]),
2826
kw_only=True,
2927
alias="@context",
3028
)
@@ -36,12 +34,10 @@ class Object(ActivityPubModel):
3634
url: Optional["str | Link"] = Field(default=None)
3735
published: Optional[str] = Field(default=None)
3836
updated: Optional[str] = Field(default=None)
39-
attributed_to: Optional["str | Actor | List[str | Actor]"] = Field(
37+
attributed_to: Optional["str | Actor | List[str | Actor]"] = Field(default=None)
38+
audience: Optional["str | Object | Dict[str, Any] | List[str | Object]"] = Field(
4039
default=None
4140
)
42-
audience: Optional["str | Object | Dict[str, Any] | List[str | Object]"] = (
43-
Field(default=None)
44-
)
4541
to: Optional[
4642
"str | Object | Dict[str, Any] | List[str | Object | Dict[str, Any]]"
4743
] = Field(default=None)
@@ -64,9 +60,7 @@ class Object(ActivityPubModel):
6460
likes: Optional["Collection"] = Field(default=None)
6561
shares: Optional["Collection"] = Field(default=None)
6662
scope: "Optional[Object | Dict[str, Any]]" = Field(default=None)
67-
tag: "List[Object | Hashtag | Emoji | Dict[str, Any]]" = Field(
68-
default_factory=list
69-
)
63+
tag: "List[Object | Hashtag | Emoji | Dict[str, Any]]" = Field(default_factory=list)
7064
attachment: "List[PropertyValue | Dict[str, Any] | Object | Link]" = Field(
7165
default_factory=list
7266
)
@@ -77,9 +71,7 @@ def _convert_field_to_model(cls, v: Any, info: ValidationInfo) -> Any:
7771

7872
if v is None:
7973
return None
80-
parent_context = (
81-
info.context.get("ld_context") if info.context else None
82-
)
74+
parent_context = info.context.get("ld_context") if info.context else None
8375
return load(v, "raw", parent_context=parent_context)
8476

8577
@field_validator("url", mode="before")
@@ -160,7 +152,8 @@ def validate_likes(cls, v: Any, info: ValidationInfo) -> Any:
160152
@field_validator("shares", mode="before")
161153
@classmethod
162154
def validate_shares(cls, v: Any, info: ValidationInfo) -> Any:
163-
return cls._convert_field_to_model(v, info)
155+
return cls._convert_field_to_model(v, info)
156+
164157
@field_validator("scope", mode="before")
165158
@classmethod
166159
def validate_scope(cls, v: Any, info: ValidationInfo) -> Any:

src/apmodel/extra/cid/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
from .data_integrity_proof import DataIntegrityProof
22
from .multikey import Multikey
33

4-
__all__ = [
5-
"DataIntegrityProof",
6-
"Multikey"
7-
]
4+
__all__ = ["DataIntegrityProof", "Multikey"]

0 commit comments

Comments
 (0)