forked from indymedia/epicyon
More actor parsing
parent
1c62500763
commit
ec9941d7ca
24
tests.py
24
tests.py
|
@ -1585,6 +1585,30 @@ def testActorParsing():
|
||||||
nickname = getNicknameFromActor(actor)
|
nickname = getNicknameFromActor(actor)
|
||||||
assert nickname == 'mynick'
|
assert nickname == 'mynick'
|
||||||
|
|
||||||
|
actor = 'https://element/accounts/badger'
|
||||||
|
domain, port = getDomainFromActor(actor)
|
||||||
|
assert domain == 'element'
|
||||||
|
nickname = getNicknameFromActor(actor)
|
||||||
|
assert nickname == 'badger'
|
||||||
|
|
||||||
|
actor = 'egg@chicken.com'
|
||||||
|
domain, port = getDomainFromActor(actor)
|
||||||
|
assert domain == 'chicken.com'
|
||||||
|
nickname = getNicknameFromActor(actor)
|
||||||
|
assert nickname == 'egg'
|
||||||
|
|
||||||
|
actor = '@waffle@cardboard'
|
||||||
|
domain, port = getDomainFromActor(actor)
|
||||||
|
assert domain == 'cardboard'
|
||||||
|
nickname = getNicknameFromActor(actor)
|
||||||
|
assert nickname == 'waffle'
|
||||||
|
|
||||||
|
actor = 'https://astral/channel/sky'
|
||||||
|
domain, port = getDomainFromActor(actor)
|
||||||
|
assert domain == 'astral'
|
||||||
|
nickname = getNicknameFromActor(actor)
|
||||||
|
assert nickname == 'sky'
|
||||||
|
|
||||||
actor = 'https://randomain/users/rando'
|
actor = 'https://randomain/users/rando'
|
||||||
domain, port = getDomainFromActor(actor)
|
domain, port = getDomainFromActor(actor)
|
||||||
assert domain == 'randomain'
|
assert domain == 'randomain'
|
||||||
|
|
23
utils.py
23
utils.py
|
@ -215,6 +215,8 @@ def getDisplayName(baseDir: str, actor: str, personCache: {}) -> str:
|
||||||
def getNicknameFromActor(actor: str) -> str:
|
def getNicknameFromActor(actor: str) -> str:
|
||||||
"""Returns the nickname from an actor url
|
"""Returns the nickname from an actor url
|
||||||
"""
|
"""
|
||||||
|
if actor.startswith('@'):
|
||||||
|
actor = actor[1:]
|
||||||
if '/users/' not in actor:
|
if '/users/' not in actor:
|
||||||
if '/profile/' in actor:
|
if '/profile/' in actor:
|
||||||
nickStr = actor.split('/profile/')[1].replace('@', '')
|
nickStr = actor.split('/profile/')[1].replace('@', '')
|
||||||
|
@ -240,6 +242,9 @@ def getNicknameFromActor(actor: str) -> str:
|
||||||
if '/' in nickStr:
|
if '/' in nickStr:
|
||||||
nickStr = nickStr.split('/')[0]
|
nickStr = nickStr.split('/')[0]
|
||||||
return nickStr
|
return nickStr
|
||||||
|
elif '@' in actor:
|
||||||
|
nickStr = actor.split('@')[0]
|
||||||
|
return nickStr
|
||||||
return None
|
return None
|
||||||
nickStr = actor.split('/users/')[1].replace('@', '')
|
nickStr = actor.split('/users/')[1].replace('@', '')
|
||||||
if '/' not in nickStr:
|
if '/' not in nickStr:
|
||||||
|
@ -251,6 +256,8 @@ def getNicknameFromActor(actor: str) -> str:
|
||||||
def getDomainFromActor(actor: str) -> (str, int):
|
def getDomainFromActor(actor: str) -> (str, int):
|
||||||
"""Returns the domain name from an actor url
|
"""Returns the domain name from an actor url
|
||||||
"""
|
"""
|
||||||
|
if actor.startswith('@'):
|
||||||
|
actor = actor[1:]
|
||||||
port = None
|
port = None
|
||||||
prefixes = getProtocolPrefixes()
|
prefixes = getProtocolPrefixes()
|
||||||
if '/profile/' in actor:
|
if '/profile/' in actor:
|
||||||
|
@ -265,16 +272,22 @@ def getDomainFromActor(actor: str) -> (str, int):
|
||||||
domain = actor.split('/channel/')[0]
|
domain = actor.split('/channel/')[0]
|
||||||
for prefix in prefixes:
|
for prefix in prefixes:
|
||||||
domain = domain.replace(prefix, '')
|
domain = domain.replace(prefix, '')
|
||||||
elif '/users/' not in actor:
|
elif '/users/' in actor:
|
||||||
|
domain = actor.split('/users/')[0]
|
||||||
|
for prefix in prefixes:
|
||||||
|
domain = domain.replace(prefix, '')
|
||||||
|
elif '/@' in actor:
|
||||||
|
domain = actor.split('/@')[0]
|
||||||
|
for prefix in prefixes:
|
||||||
|
domain = domain.replace(prefix, '')
|
||||||
|
elif '@' in actor:
|
||||||
|
domain = actor.split('@')[1].strip()
|
||||||
|
else:
|
||||||
domain = actor
|
domain = actor
|
||||||
for prefix in prefixes:
|
for prefix in prefixes:
|
||||||
domain = domain.replace(prefix, '')
|
domain = domain.replace(prefix, '')
|
||||||
if '/' in actor:
|
if '/' in actor:
|
||||||
domain = domain.split('/')[0]
|
domain = domain.split('/')[0]
|
||||||
else:
|
|
||||||
domain = actor.split('/users/')[0]
|
|
||||||
for prefix in prefixes:
|
|
||||||
domain = domain.replace(prefix, '')
|
|
||||||
if ':' in domain:
|
if ':' in domain:
|
||||||
portStr = domain.split(':')[1]
|
portStr = domain.split(':')[1]
|
||||||
if not portStr.isdigit():
|
if not portStr.isdigit():
|
||||||
|
|
Loading…
Reference in New Issue