add HostMeta and HostMetaJson objects
This commit is contained in:
parent
5afbf789fd
commit
051ee020ea
|
@ -12,6 +12,8 @@ MODULES = {
|
|||
'Signature': 'misc',
|
||||
|
||||
#objects
|
||||
'HostMeta': 'objects',
|
||||
'HostMetaJson': 'objects',
|
||||
'Nodeinfo': 'objects',
|
||||
'Webfinger': 'objects',
|
||||
'WellKnownNodeinfo': 'objects',
|
||||
|
|
|
@ -127,6 +127,9 @@ class Dotdict(dict):
|
|||
if isinstance(value, dict) and not isinstance(value, Dotdict):
|
||||
value = Dotdict(value)
|
||||
|
||||
elif key == 'links' and isinstance(value, (list,tuple,set)):
|
||||
value = [Dotdict(v) for v in value]
|
||||
|
||||
dict.__setitem__(self, key, value)
|
||||
|
||||
|
||||
|
|
|
@ -8,6 +8,46 @@ NODEINFO_NS = {
|
|||
}
|
||||
|
||||
|
||||
class HostMeta(str):
|
||||
'An object that represents the "/.well-known/host-meta" endpoint'
|
||||
|
||||
def __new__(cls, data):
|
||||
return str.__new__(cls, data)
|
||||
|
||||
|
||||
@classmethod
|
||||
def new(cls, domain) -> 'aputils.HostMeta':
|
||||
'''
|
||||
Generate a new host-meta xml string
|
||||
|
||||
:param str domain: Domain to use for the template url
|
||||
'''
|
||||
return cls(f'''<?xml version="1.0" encoding="UTF-8">
|
||||
<XRD xmlns="http://docs.oasis-open.org/ns/xri/xrd-1.0">
|
||||
<Link rel="lrdd" template="https://{domain}/.well-known/webfinger?resource={{uri}}" />
|
||||
</XRD>''')
|
||||
|
||||
|
||||
class HostMetaJson(Dotdict):
|
||||
'An object that represents the "/.well-known/host-meta.json" endpoint'
|
||||
|
||||
@classmethod
|
||||
def new(cls, domain) -> 'aputils.HostMetaJson':
|
||||
'''
|
||||
Generate a new host-meta dict
|
||||
|
||||
:param str domain: Domain to use for the template url
|
||||
'''
|
||||
return cls({
|
||||
'links': [
|
||||
{
|
||||
'rel': 'lrdd',
|
||||
'template': f'https://{domain}/.well-known/webfinger?resource={{uri}}'
|
||||
}
|
||||
]
|
||||
})
|
||||
|
||||
|
||||
class Nodeinfo(Dotdict):
|
||||
'An object that represents a nodeinfo endpoint'
|
||||
|
||||
|
@ -100,13 +140,7 @@ class Nodeinfo(Dotdict):
|
|||
|
||||
|
||||
class Webfinger(Dotdict):
|
||||
'An object that represents the /.well-known/webfinger endpoint'
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
if key == 'links':
|
||||
value = [Dotdict(item) for item in value]
|
||||
|
||||
Dotdict.__setitem__(self, key, value)
|
||||
'An object that represents the "/.well-known/webfinger" endpoint'
|
||||
|
||||
|
||||
@classmethod
|
||||
|
@ -198,14 +232,7 @@ class Webfinger(Dotdict):
|
|||
|
||||
|
||||
class WellKnownNodeinfo(Dotdict):
|
||||
'An object that represents the /.well-known/nodeinfo endpoint'
|
||||
|
||||
def __setitem__(self, key, value):
|
||||
if key == 'links':
|
||||
value = [Dotdict(item) for item in value]
|
||||
|
||||
Dotdict.__setitem__(self, key, value)
|
||||
|
||||
'An object that represents the "/.well-known/nodeinfo" endpoint'
|
||||
|
||||
@classmethod
|
||||
def new(cls, v20=None, v21=None):
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
Objects
|
||||
=======
|
||||
|
||||
.. autoclass:: aputils.HostMeta
|
||||
:members:
|
||||
:show-inheritance:
|
||||
:exclude-members: __new__
|
||||
|
||||
.. autoclass:: aputils.HostMetaJson
|
||||
:members:
|
||||
:show-inheritance:
|
||||
|
||||
.. autoclass:: aputils.Nodeinfo
|
||||
:members:
|
||||
:show-inheritance:
|
||||
|
|
Loading…
Reference in a new issue