Try different users paths

main
Bob Mottram 2021-07-29 23:41:27 +01:00
parent 78d37b16ab
commit 09fcc163bb
1 changed files with 20 additions and 9 deletions

View File

@ -18,27 +18,38 @@ from utils import loadJsonOnionify
from utils import saveJson from utils import saveJson
from utils import getProtocolPrefixes from utils import getProtocolPrefixes
from utils import removeDomainPort from utils import removeDomainPort
from utils import getUserPaths
def _parseHandle(handle: str) -> (str, str): def _parseHandle(handle: str) -> (str, str):
"""Parses a handle and returns nickname and domain
"""
if '.' not in handle: if '.' not in handle:
return None, None return None, None
prefixes = getProtocolPrefixes() prefixes = getProtocolPrefixes()
handleStr = handle handleStr = handle
for prefix in prefixes: for prefix in prefixes:
handleStr = handleStr.replace(prefix, '') handleStr = handleStr.replace(prefix, '')
# try domain/@nick
if '/@' in handle: if '/@' in handle:
domain, nickname = handleStr.split('/@') domain, nickname = handleStr.split('/@')
else: return nickname, domain
if '/users/' in handle:
domain, nickname = handleStr.split('/users/') # try nick@domain
else:
if '@' in handle: if '@' in handle:
nickname, domain = handle.split('@') nickname, domain = handle.split('@')
else:
return None, None
return nickname, domain return nickname, domain
# try for different /users/ paths
usersPaths = getUserPaths()
for possibleUsersPath in usersPaths:
if possibleUsersPath in handle:
domain, nickname = handleStr.split(possibleUsersPath)
return nickname, domain
return None, None
def webfingerHandle(session, handle: str, httpPrefix: str, def webfingerHandle(session, handle: str, httpPrefix: str,
cachedWebfingers: {}, cachedWebfingers: {},