kopia lustrzana https://github.com/snarfed/bridgy-fed
refactor User.ap_address implementations to highlight similarities
rodzic
9b8b02e99f
commit
1a003c8c5b
|
@ -85,7 +85,7 @@ class ActivityPub(User, Protocol):
|
|||
|
||||
return self.ap_actor()
|
||||
|
||||
def ap_address(self):
|
||||
def handle(self):
|
||||
"""Returns this user's ActivityPub address, eg ``@user@foo.com``."""
|
||||
if self.obj and self.obj.as1:
|
||||
addr = as2.address(self.as2())
|
||||
|
@ -94,14 +94,14 @@ class ActivityPub(User, Protocol):
|
|||
|
||||
return as2.address(self.key.id())
|
||||
|
||||
handle = ap_address
|
||||
ap_address = handle
|
||||
|
||||
def ap_actor(self, rest=None):
|
||||
"""Returns this user's ActivityPub actor id URL.
|
||||
|
||||
Eg 'https://foo.com/@user'
|
||||
"""
|
||||
return self.key.id() + (f'/{rest}' if rest else '')
|
||||
"""Returns this user's actor id URL, eg ``https://foo.com/@user``."""
|
||||
url = self.key.id()
|
||||
if rest:
|
||||
url += f'/{rest.lstrip("/")}'
|
||||
return url
|
||||
|
||||
@classmethod
|
||||
def owns_id(cls, id):
|
||||
|
|
12
models.py
12
models.py
|
@ -394,7 +394,7 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
parsed_url[1:] == parsed_this[1:]) # ignore http vs https
|
||||
|
||||
def ap_address(self):
|
||||
"""Returns this user's ActivityPub address, eg '@me@foo.com'.
|
||||
"""Returns this user's ActivityPub address, eg ``@me@foo.com``.
|
||||
|
||||
Returns:
|
||||
str
|
||||
|
@ -405,24 +405,20 @@ class User(StringIdModel, metaclass=ProtocolUserMeta):
|
|||
def ap_actor(self, rest=None):
|
||||
"""Returns this user's ActivityPub/AS2 actor id.
|
||||
|
||||
Eg 'https://fed.brid.gy/ap/atproto/foo.com'
|
||||
Eg ``https://fed.brid.gy/ap/atproto/foo.com`.
|
||||
|
||||
May be overridden by subclasses.
|
||||
|
||||
Args:
|
||||
rest: str, optional, appended to URL path
|
||||
rest (str): optional, appended to URL path
|
||||
|
||||
Returns:
|
||||
str
|
||||
"""
|
||||
# must match the URL route for activitypub.actor()
|
||||
url = common.host_url(f'/ap/{self.ABBREV}/{self.key.id()}')
|
||||
|
||||
if rest:
|
||||
if not rest.startswith('?'):
|
||||
url += '/'
|
||||
url += rest
|
||||
|
||||
url += f'/{rest.lstrip("/")}'
|
||||
return url
|
||||
|
||||
def profile_id(self):
|
||||
|
|
4
web.py
4
web.py
|
@ -127,7 +127,7 @@ class Web(User, Protocol):
|
|||
"""
|
||||
url = common.host_url(self.key.id())
|
||||
if rest:
|
||||
url += f'/{rest}'
|
||||
url += f'/{rest.lstrip("/")}'
|
||||
return url
|
||||
|
||||
def user_page_path(self, rest=None):
|
||||
|
@ -137,7 +137,7 @@ class Web(User, Protocol):
|
|||
if rest:
|
||||
if not rest.startswith('?'):
|
||||
path += '/'
|
||||
path += rest
|
||||
path += rest.lstrip('/')
|
||||
|
||||
return path
|
||||
|
||||
|
|
Ładowanie…
Reference in New Issue