replace NODEINFO_NS with NodeinfoVersion enum
This commit is contained in:
parent
558cd9f597
commit
8bcc8ffd27
3 changed files with 17 additions and 10 deletions
|
@ -32,6 +32,7 @@ MODULES = {
|
|||
"NodeinfoProtocol": "enums",
|
||||
"NodeinfoServiceInbound": "enums",
|
||||
"NodeinfoServiceOutbound": "enums",
|
||||
"NodeinfoVersion": "enums",
|
||||
"ObjectType": "enums",
|
||||
|
||||
# exceptions
|
||||
|
|
|
@ -136,6 +136,11 @@ class NodeinfoServiceOutbound(StrEnum):
|
|||
XMPP = "xmpp"
|
||||
|
||||
|
||||
class NodeinfoVersion(StrEnum):
|
||||
V20 = "http://nodeinfo.diaspora.software/ns/schema/2.0"
|
||||
V21 = "http://nodeinfo.diaspora.software/ns/schema/2.1"
|
||||
|
||||
|
||||
class ObjectType(StrEnum):
|
||||
"ActivityPub object types"
|
||||
|
||||
|
|
|
@ -7,16 +7,11 @@ from typing import Any, Optional, Type
|
|||
from .enums import (
|
||||
NodeinfoProtocol,
|
||||
NodeinfoServiceInbound,
|
||||
NodeinfoServiceOutbound
|
||||
NodeinfoServiceOutbound,
|
||||
NodeinfoVersion
|
||||
)
|
||||
|
||||
|
||||
NODEINFO_NS: dict[str, str] = {
|
||||
"20": "http://nodeinfo.diaspora.software/ns/schema/2.0",
|
||||
"21": "http://nodeinfo.diaspora.software/ns/schema/2.1"
|
||||
}
|
||||
|
||||
|
||||
class HostMeta(str):
|
||||
"An object that represents the ``/.well-known/host-meta`` endpoint"
|
||||
|
||||
|
@ -265,10 +260,16 @@ class WellKnownNodeinfo(dict):
|
|||
data = []
|
||||
|
||||
if v20:
|
||||
data.append({"rel": NODEINFO_NS["20"], "href": v20})
|
||||
data.append({
|
||||
"rel": NodeinfoVersion.V20.value,
|
||||
"href": v20
|
||||
})
|
||||
|
||||
if v21:
|
||||
data.append({"rel": NODEINFO_NS["21"], "href": v21})
|
||||
data.append({
|
||||
"rel": NodeinfoVersion.V21.value,
|
||||
"href": v21
|
||||
})
|
||||
|
||||
return cls({"links": data})
|
||||
|
||||
|
@ -330,7 +331,7 @@ class WellKnownNodeinfo(dict):
|
|||
"""
|
||||
|
||||
for item in self["links"]:
|
||||
if item["rel"] == NODEINFO_NS[version]:
|
||||
if item["rel"] == NodeinfoVersion.parse("V" + version):
|
||||
return item["href"]
|
||||
|
||||
raise KeyError(version)
|
||||
|
|
Loading…
Reference in a new issue